' {$STAMP BS2p, run1.bsp, run2.bsp, run3.bsp, run4.bsp} ' {$PBASIC 2.5} ' {$PORT COM1} #DEFINE DebugMode ' NAME THIS FILE run0.bsp FIRST LINE MUST BE ~ ' {$STAMP BS2p... ' run0.bsp, run1.bsp, run2.bsp, run3.bsp ' Version 12/09/2010 ' Objective: To point solar dish approximately at sun for safety when sun is not visible, and exactly at sun when sun is visible. ' Run0 & Run1 & Run2 & Run3 were loaded into 4/6/2010 Fox Island solar dish AND operate with ' only two switches AND an optional notebook computer with BASIC Stamp Editor (free download). ' IF while power switch off both toggle switches are flipped towards the power switch ' then when power switched on motors remain off AND clock set enabled (IF DebugMode enabled). ' The only EXIT with DebugMode enabled (and without a notebook plugged in) is TO cycle the power with one or both switches NOT flipped towards the power switch. ' IF one OR the other switch flipped THEN the dish goes up OR goes down. If both switches flipped towards power switch then motors off. ' Otherwise when both switches flipped away from power switch the dish is fully automatic with program DATA optionally displayed ON a notebook screen. ' IF the dish stows FOR a fault THEN reset by turning power off AND ON. ' Always switch power off before disconnecting power. ' Depending ON the length of the serial cable, it may NOT be wise TO rely ON DebugMode enabled ' with a notebook NOT plugged in. RUN with #DEFINE DebugMode (above) commented out in all programs instead. ' Program flow: ' GET Sensor (XY,Z positions), GET Eyes, GET Time, GET Memory, GET Path (solar algorithm) ' Determine IF dark, twilight, cloudy, sunny, stow, OR focus. ' IF dark THEN orientate east AND go TO SLEEP. ' IF twilight THEN wakeup. Move TO safe position above sunrise. ' IF cloudy THEN track from memory OR from calculated sun path. ' IF sunny THEN track with eyes. ' IF sunny THEN check dish tracking credibility. ' IF any subsystem outside operational parameters THEN stow. ' Repeat ' Hardware: ' 24 VDC 36 inch TV dish actuary. ' 12 VDC Dayton 12 rpm gear motor 1/125 hp. ' Motor Mind C speed controller. ' BASIC Stamp Parallax micro BS2P. ' Solutions Cubed MMC BS2P carrier board. ' DS1307 clock chip. ' Variables - ' d FOR solar declination values, binary radians, 0 = Equinox. ' Dwell is used TO stall dish after sunny tracking before cloudy tracking via memory or path routines. ' Azimuth_Motor AND Altitude_Motor monitors motors time ON FOR movement fault testing. ' Azimuth_command AND Altitude_command sets motor direction. ' Azimuth_go AND Altitude_go sets motors ON OR off. ' Azimuth_spin AND Altitude_spin are actual motors spin direction. ' Azimuth_on AND Altitude_on are actual motors ON OR off condition. ' Constants - ' lat = binary latitude. 47 degrees Tacoma = 34 brads (binary radians 0-255 in circle) (round up or add 1) ' Additional logic statements will be required FOR sun path algorithms in equitorial and southern latitudes ' rampAZ AND rampAlt are values of motor speed increases per program cycle. ' startAz AND startAlt are motor start speeds. ' maxAz AND maxAlt are motor maximum speeds, NOT TO exceed 1023. ' drift is solar binary declination limit FOR memory tracking. ' Search is number of minutes past OR future FOR dead reckoning memory gaps. ' sun is eye signal strength needed FOR open LOOP tracking. ' sun_Gap is eye difference allowed FOR focus AND motors off. ' Azimuth_Gap AND Altitude_Gap are +/- position sensor error maximums. ' ON_SUN is solar intensity necessary FOR recording focus DATA into memory. ' Too_Bright is eye fault testing ~ stow. ' DISH SPECIFIC INPUTS ' lowZ ... Altitude sensor limits ' highZ ' lowXY ... Azimuth sensor limits ' highXY ' lowD ... Tilt angle in degrees ' highD ' safeZ dish altitude position safe from starting ground fires, maybe, check your location. ' Due_south for solar_noon when sun is due south. During installation set azimuth sensor to output 128 when due south. ' Code - run0.bsp (runs only at power startup) ' Store EEPROM sun position DATA in program slot 7. ' Initialize motor controller FOR slow braking AND fast PWM. ' High fidelity tracking will improve by skipping Initialize motor routines AND reducing NAP. ' I2CIN (time) sets flag to arctangent quadrant of solar azimuth to minimize startup Path error ' Run 2 skips run1 this cycle ' Safety more important than function. cport PIN 0 ' I2C - DS1307 clock cclock PIN 1 ' I2C North_eye PIN 2 ' RC Time South_eye PIN 3 ' RC Time East_eye PIN 5 ' RC Time West_eye PIN 4 ' RC Time 'water_off PIN 6 tm PIN 7 ' Motor Mind C serial comm. SERIN fm PIN 8 ' Motor Mind C serial comm. SEROUT Xin PIN 9 ' Rotate X Accelerometer MEMSIC 2125 Yin PIN 10 ' Rotate Y Accelerometer MEMSIC 2125 Zin PIN 11 ' Tilt Z Accelerometer MEMSIC 2125 Altitude_sensor 'temp_1 PIN 12 'temp_2 PIN 13 SW1 PIN 14 ' Pulled high SW2 PIN 15 ' Pulled high speed_azimuth VAR Word 'PWM storage register for motor 1 speed_altitude VAR Word 'PWM storage register for motor 2 time VAR Word work VAR Word work1 VAR Word work2 VAR Word work3 VAR Word work4 VAR Word work5 VAR Word Azimuth_sensor VAR Byte Altitude_sensor VAR Byte flags VAR Byte flag_north VAR flags.BIT0 flag_south VAR flags.BIT1 flag_run VAR flags.BIT2 flag_stow VAR flags.BIT3 d VAR Byte ' Declination Dwell VAR Nib Azimuth_Motor VAR Nib Altitude_Motor VAR Nib Smooth VAR Nib read_flag VAR Bit write_flag VAR Bit flag VAR Bit dark VAR Bit stow_write VAR Bit solar_noon VAR Bit sign VAR Smooth.BIT0 cloudy VAR Smooth.BIT1 Focus VAR Smooth.BIT2 Azimuth_Stow VAR Bit Altitude_Stow VAR Bit azimuth_command VAR Bit altitude_command VAR Bit azimuth_go VAR Bit altitude_go VAR Bit azimuth_spin VAR Bit altitude_spin VAR Bit azimuth_on VAR Bit altitude_on VAR Bit sec VAR work1.HIGHBYTE minute VAR work1.LOWBYTE hour VAR work2.HIGHBYTE day VAR work2.LOWBYTE date VAR work3.HIGHBYTE month VAR work3.LOWBYTE year VAR work.HIGHBYTE dat1 VAR work.HIGHBYTE alt VAR work2 az VAR work3 h VAR work4 Azimuth_Path VAR work1.BYTE0 Altitude_Path VAR work1.BYTE1 prior VAR work5.LOWBYTE lat CON 34 '47 degrees Tacoma = 33 brads ~round up~ 34 (binary radians 0-255 in circle) 'lat CON 20 ' 27.5 degrees Ft. Pierce = 20 brads BAUD CON 45 CKSUMq CON $D2+$01+$02+$09+$01 STORE 7 PAUSE 1500 #IF DebugMode #THEN DEBUG CLS,7 #ENDIF GOSUB initialize_motor IF sw1=0 AND sw2=0 THEN set_clock RUN 2 initialize_motor: 'RETURN SEROUT FM,BAUD,[$D2,$01,$02,$09,$01,CKSUMq] 'PWM STEP RAMP ~ slow breaking SERIN TM,BAUD,150,motor_error,[DAT1] IF DAT1 <> $6 THEN motor_error 'RETURN PAUSE 150 SEROUT FM,BAUD,[$D4,$01,$00,$D5] ' Change PWM frequency to 19.2 KHZ SERIN TM,BAUD,150,motor_error,[DAT1] ' Lowers tracking fidelity and reduces motor hum IF DAT1 <> $6 THEN motor_error RETURN motor_error: #IF DebugMode #THEN DEBUG CRSRXY,2,15," MOTOR ERROR",CR,HEX dat1," ",7,CR PAUSE 5000 #ENDIF RETURN set_clock: RUN 3