Skip to main content

Subsection 14.2.4 Part 4: Read "A Solar Tracker" in the Lab Handout

There are two feedback loops in the tracker (Figure 14.2.17 and Figure 14.2.19). The first loop is inside the servo, and it was described in the servo chapter (Subsection 13.1.2). The position we command enters on the left, the potentiometer on the output shaft measures the servo’s current position, and the servo’s own controller drives the motor until the error (the difference between the commanded and the actual position) is zero. That loop is built into the servo. The second loop is the tracking loop, the one that points the arm at the light, and it is what you implement in Lab 8. The two sensors are read by the two ADC channels, a controller computes a new PWM value, the PWM pulse moves the servo, and the angle of the arm sets how much light each sensor receives, which closes the loop. If we call the two sensors’ node voltages \(V_0\) and \(V_1\) (measured on A0 and A1), then the error is \(e = V_1 - V_0\text{,}\) and the controller updates the PWM value by \(K\,e\) every \(T\) milliseconds, where \(T\) is the sampling interval and \(K\) is the controller gain, the number that sets how large a step each error produces. The controller in this loop is a part of the program you write in Lab 8.
Figure 14.2.17. The loop inside the servo, from the servo chapter: the command position, the error, the controller, the motor, the gears, and the potentiometer that feeds the position back.
Figure 14.2.19. Lab 8’s Figure 6, the tracking loop: two sensors, whose node voltages are \(V_0\) and \(V_1\text{,}\) two ADC conversions, the controller we write, the PWM pulse, the servo, and the angle θ of the arm, which feeds back to the sensors through the light.

Activity 14.2.5. Read "A Solar Tracker" in the lab handout.

Read section 4 of Lab 8, Design Challenge – Solar Tracker, and discuss at your table how you might implement the feedback loop. Two questions to settle in the discussion:

(a)

Suppose \(V_1\) is larger than \(V_0\text{,}\) so that the error \(e = V_1 - V_0\) is positive. Which way should the arm turn, and should the PWM value increase or decrease to turn it that way? What do you need to know about your own build to answer that?

(b)

Predict what the arm does if \(K\) is much too large, and what it does if the sampling interval \(T\) is much too long.
In Lab 8 you are asked to impose upper and lower bounds on the PWM value before it is written to CCR1, TIM14’s compare register, so that the servo is not driven beyond ±60° of center; your servo program from Day 15 already applies a limit in updateServo() before every write, and Lab 8’s ±60° is narrower than the program’s SERVO_MIN and SERVO_MAX, so you need to work out the two numbers from Day 15’s pulse convention, a 1 ms pulse for −90° and a 2 ms pulse for +90° (Subsection 13.4.1). You are also asked to keep track of \(T\) with milliseconds(), the SysTick count from the motor chapter (Subsection 11.5.4).