Activity How The Sun Tracker Works

Servo waitCount

WaitVal

PIN VAR CON

12 Nib 1

Finally, if the left panel's voltage is greater than the right panel, the program branches to Exp_3_Move_Right. Following these basic branch instructions, the remaining part of the code does the actual tracking work.

Exp_3_Stop:

PULSOUT Servo, 75 0

GOTO Exp_3_Set_Wait_Count

At Exp_3_stop the program executes a pulsout command to the servo for 750 two-microsecond units, or 1.5 milliseconds. This value should stop the servo. If it doesn't and the servo still "creeps" a bit to the left or right, you can point the solar panels directly at your light source, then adjust the servo by inserting your Parallax screwdriver into the adjustment port and very gently twisting it until the servo is still when both LEDs are illuminated.

Exp_3_Move_Left:

waitCount = waitCount - 1 IF (waitCount <> 0) THEN

GOTO Exp_3_End ELSE

PULSOUT Servo, 75 5 GOTO Exp_3_Set_Wait_Count ENDIF

Exp_3_Move_Right:

waitCount = waitCount - 1 IF (waitCount <> 0) THEN

GOTO Exp_3_End ELSE

PULSOUT Servo, 74 5 GOTO Exp_3_Set_Wait_Count ENDIF

Continuing, the next instruction branches to Exp_3_Set_Wait_Count where the waitCount variable is set to the waitval that has already been declared. We'll get to what waitCount and waitval are all about in a moment.

The Exp_3_Move_Left and Exp_3_Move_Right subroutines are basically the same except for the value of the pulsout command. To move the servo slightly left the program adds 5 to the neutral 750 "stop" value, while the program subtracts 5 to 750 to make the servo move right. These 745 and 755 values do not represent anything like moving the servo one degree at a time (which is what it may look like). Instead, they were chosen to move the servo with enough precision so that the voltages from the left and right panels would converge without overshooting one another. Later on you will be asked to experiment with these values to fine-tune your sun tracker to your particular liking.

Another thing that both subroutines do is decrement waitCount with the command waitcount = waitCount - 1. After decrementing, if waitCount is 0, the servo is moved in the indicated direction. However if waitCount is not zero, the subroutine simply exits and does not move the servo.

Since our program declared that waitval is equal to 1, waitCount will always be decremented to 0 and the servo will always be moved left or right a bit. This, then, causes the "hunting" that we referred to earlier. That is, the servo moves left or right every time the solar panel voltages are not equal. To mitigate the hunting action we incorporated the waitCount and waitval into the program so that the program could "dampen" the servo hunting. In other words, if waitval is set to 3 instead of 1 in the declaration section, the program will ignore any voltage imbalance for three consecutive passes before moving the servo. Let's try it:

Your Turn - Adjusting the waitVal Variable

V First, disable StampPlot by deselecting the Connect icon and return to the BASIC Stamp Editor.

V Locate the waitval constant in the Experiment 3 declarations and change it from 1 to 3 so it now reads:

' ----- For Experiment 3: Solar Cell Sun Tracker --------------------------

Servo PIN 12 ' Sun tracker servo on P12

waitCount VAR Nib ' Dampens servo's "hunting"

WaitVal CON 1 ' initial value of waitCount

V Next, save the modified code and reload it into the BS2 by clicking on the Run icon in the BASIC Stamp Editor or type Ctrl-R.

You should now see the "dampening" effects of the new waitval constant on the servo's actions.

V Watch the left and right LEDs and notice that when both are not illuminated, the servo does not move every time.

Instead, the subroutines are decrementing waitCount. Another thing happens to waitCount when both LEDs become illuminated, even briefly. Notice that the second instruction after the label Exp_3_Stop causes the program to branch to Exp_3_Set_Wait_Count. Here the waitCount variable is re-initialized to 3, the new waitVal constant. So even after the Exp_3_Move_Left or Exp_3_Move_Right subroutines decrement waitCount, if the two solar panels suddenly become equal in voltage WITHOUT moving the solar panels, the waitCount value is re-initialized.

The effect of all of this is to not overreact to slight, random imbalances in the solar panel voltage outputs. And this is what's called "damping" because these random imbalances are taken out of the servo action thus making the servo tracking much smoother. If the solar panels do, in fact, remain at different voltage values after waitCount is decremented to 0, the servo will step in and move the panel in the correct direction.

A Typical Problem

In your experimental trials with the sun tracker you may notice that while it follows the sun or a bright light source, it may not point directly at the light. This goes back to Experiment 2 when you calibrated both panels using the offSet value. Perhaps this value is not correct for the light source that you're trying to track in this experiment, or maybe you rushed through this part before. Nevertheless, in order to recalibrate offSet value:

Solar Power

Solar Power

Start Saving On Your Electricity Bills Using The Power of the Sun And Other Natural Resources!

Get My Free Ebook


Post a comment