Solar tracking with Basic Stamp

Good morning!
I am a student and this my 1st post. I have built a pan-tilt device driven by Parallax Standard Servos and am using the BS2 on BOE rev d board. I am following the Student guide from Parallax by the name of this post.
The problem is that the student guide specifies a separate motor control and drives including a gear-head motor and pneumatic cylinder and I am using only parallax components.

The debug screen reads the RCTIME across the reverse-biased LEDs and does respond slightly to the light through the tilting action but is not consistent and is will tilt downward almost the whole way but when the light is moved up it will only move sightly. BUT, it will not respond at all in the horizontal axis even though the debug displays the decay in the RCTIME. I have built the circuitry to move both axis with pushbuttons and when that program is running the horizontal axis (Pan or Azimuth) moves perfectly and the the vertical axis (Tilt or Altitude) response is somewhat simular to the tracking program.

I have completed the BOE-Bot course and this is an extracurricular project that I have requested and am scheduled to demonstrate next Wednesday for the Advisory Board and am hoping to find a summer internship.
This project is beyond my current education but I find the study of Electronics fascinating. My studies in the fall will involve more advanced circuit logic and robotics.

If anyone can review the source code and see the error of my ways, I would be most appreciative.
I tried to create and attachment but this did not work so I have pasted the code below.

Best regards, Tru

'Indoor Light Tracker.BS2

[code]
’ {$STAMP BS2}
’ {$PBASIC 2.5}

'------*-----------------------------------------

AZIMUTH PIN 12 'Pan motor driving Azimuth axis
ALTITUDE PIN 13 'Tilt motor driving Altitude axis
'Parallax Standard Servo motors
LED_TOP CON 9 'Top LED sensor circuit
LED_WEST CON 8 'West LED sensor circuit
LED_BOTTOM CON 7 'Bottom LED sensor circuit
LED_EAST CON 6 'East LED sensor circuit

’ Note, LED’s are reversed biased for RCTIME.

'-----------------[Constants]-----------------------------------------

’ User defined constants
PULSE_CCW CON 870 'Counterclockwise motor speed
PULSE_CW CON 650 'Clockwise motor speed
PULSE_STOP CON 760
ALTITUDE_UP CON 960 '“too dark” threshold
ALTITUDE_DN CON 760 'Horizontal error threshold
MAX_ERROR_H CON 6 'Horizontal error threshold
MAX_ERROR_V CON 2 'Vertical error threshold
PULSE_DELAY CON 20 '20ms minimum between pulses
MAX_TIME CON 30000 '“too dark” threshold

’ Program constants

LIGHT_TOP CON 3 'Top light measurement index
LIGHT_WEST CON 2 'West light measurement index
LIGHT_BOTTOM CON 1 'Bottom light measurement
LIGHT_EAST CON 0 'East light measurement index

'--------- Variables ]---------------------------------------------

ewmotorPulse VAR Word 'Panning motor control pulse duration
udmotorPulse VAR Word 'Tilting motor control pulse duration
counter VAR Word 'Loop counter
average VAR Word 'Average measurement
error VAR Word 'Difference between measurements
time VAR Word(4) 'Light sensor array variable
index VAR Nib 'Indexing variable
pindex VAR index 'Pin index variable alias
x VAR Nib 'x cursor position for Debug
y VAR Nib 'y cursor position for Debug

'------- Intialization ]-------------------------------------------

GOSUB ST_Controller_Init 'Required, takes - 4 s.
DEBUG CLS, " Light Levels", 'Display legend for mesurements
CRSRXY, 8,3, “U”, CRSRXY, 8,5, “D”,
CRSRXY, 6,4, “W”, CRSRXY, 10,4, “E”

'------[Main ]------------------------------------------------------

DO 'Repeat indefinitly (DO…LOOP)

GOSUB Get_Decay_Times 'Get light measurements
GOSUB Display_Decay_Times 'Display measurements in DEBUG
GOSUB Tracker_Control 'Decide what action to do
GOSUB Azimuth_Altitude_Control 'Control pan and tilt motor

LOOP

'------[Subroutine Get_Decay_Times ]-------------------------------

Get_Decay_Times:
'Get light measurements
FOR pindex = LED_EAST TO LED_TOP 'Loop thru 4 sensors
HIGH pindex 'Charge diode junction
PAUSE 1 'wait 1 ms
RCTIME pindex, 1, time(pindex - LED_EAST) 'Time diode junction cap decay
NEXT 'Repeat FOR…NEXT loop

RETURN 'Return from Subroutine

'-------[Subroutine Display_Decay_Times ]-------------------------

Display_Decay_Times: 'Light sensor display subroutine

FOR index = LIGHT_EAST TO LIGHT_TOP 'Loop thru 4 measurements
LOOKUP index, [12,6,0,6], x 'Set cursor - x position
LOOKUP index, [4,6,4,2], y 'Set cursor - y position
DEBUG CRSRXY, x,y, DEC5 time (index), CR 'Display indexed measurements
NEXT 'Repeat the loop

RETURN 'Return from subroutine

'-------- Subroutine Tracker_Control]-------------------------------

'Set control variables based on sensor measurements.

Tracker_Control:

’ East/West rotation
’ If it’s light enough, divide difference between axis light measurements
’ into average light for the axis. IF the result is less than MAX_ERROR_H,
’ tracker rotates platform to catch up with light source provided the limit
’ switch for that direction is not pressed.

IF time (LIGHT_WEST) < MAX_TIME AND time (LIGHT_EAST) < MAX_TIME THEN
error = time (LIGHT_WEST) - time (LIGHT_EAST)
average = time (LIGHT_EAST) + time (LIGHT_WEST) / 2
IF average / ABS (error) < MAX_ERROR_H THEN
IF time (LIGHT_WEST) > time (LIGHT_EAST) THEN

ENDIF
 ENDIF
  ENDIF

’ Up/Down adjustment
’ If it’s light enough, divide difference between axis light measurements
'into average light for the axis. If the result is less than MAX_ERROR_V,
'tracker tilts platform to face the light source.

IF time (LIGHT_TOP) < MAX_TIME AND time (LIGHT_BOTTOM) < MAX_TIME THEN
error = time (LIGHT_TOP) - time (LIGHT_BOTTOM)
average = time (LIGHT_TOP) + time (LIGHT_BOTTOM) / 2
IF average / ABS(error) < MAX_ERROR_V THEN
IF time ( LIGHT_BOTTOM) > time (LIGHT_TOP) THEN
udmotorPulse =ALTITUDE_UP
ELSE
udmotorPulse = ALTITUDE_DN
ENDIF
ENDIF
ENDIF

RETURN

'------[Subroutine Azimuth_Altitude_Control]-----------------

'Send pulses simular to standard hobby servo control signals to control
'the Solar Tracker’s Azimuth and Altitude motors.
'must call at least every 500ms.

Azimuth_Altitude_Control:
PULSOUT AZIMUTH, ewmotorPulse 'Send pan motor control pulse
PULSOUT ALTITUDE, udmotorPulse 'Send tilt motor control pulse
PAUSE PULSE_DELAY 'Delay for at least PAUSE_DELAY

RETURN

'----[Subroutine ST_Controller_Init]------------------------------

'*********************************************************************
'*********************************************************************
'THE ORIGINAL STUDENT GUIDE; SOLAR TRACKING W/ BASIC STAMP USED A SECOND CONTROLLER
'TO COMMUNICATE WITH NON-PARALLAX MOTOR AND PNEUMATIC PISTON.
'I NEED TO REPLACE THIS SUB-ROUTINE TO CONTROL 2 PARALLAX STANDARD SERVOS
’ **************************************************************************
'***************************************************************************

ST_Controller_Init:

ewmotorPulse = 760
udmotorPulse = 760

'Pause 1/10 s, 100 neutral pulses for ~2 s to indicate activity on
'channels, pause another 1/10 s, then neutral pulses for ~ 2 s so
'that Azimuth (panning) and Altitude (tilting) controller gives BS2 control.

FOR counter = 0 TO 199
IF counter//100 = 0 THEN PAUSE 100
GOSUB Azimuth_Altitude_Control
IF counter//50 = 0 THEN DEBUG “initializing…”, CR
NEXT

RETURN
[/code]*

Hi all,
Here are a few pics, perhaps this may give you a better idea as to what I am up to

When I switched the servo ports the horizontal axis worked and the vertical axis did not but under push button control both axis work perfectly. The thing that puzzles me the most is how to modify the code because I am not using the IDS controller that was specified in the student guide and yet I have that subroutine still enabled.

Thanks!!

Unfortunately, we cannot help you debug your code, however, perhaps a user with experience with this issues can answer your question or provide some insight.