JamesWhite
New Member
A new bot, hot off my workbench:
Info:
http://geppettosworkbench.blogspot.com/2013/10/beampicaxe-20x2-turbot.html
Here's the code.
Info:
http://geppettosworkbench.blogspot.com/2013/10/beampicaxe-20x2-turbot.html
Here's the code.
Code:
' ====== Constants ======
symbol TestEyes = c.0 ' set pin low to read
symbol Panels = c.1 ' adc9
symbol Eyes = c.7 ' adc3
' ====== Variables ======
symbol TriggerLevel = b0
symbol TestResults = b1
symbol PreviousTest = b2
symbol TestFreq = b3
symbol MaxOnTime = b4
symbol Motors = b5
symbol MotorCom = b6
' ====== Directives ======
#picaxe 20x2
#no_table
#no_end
' ======================================= Begin Program =======================================
high TestEyes ' disable photobridge until it's time to look around
disablebod ' disable brown out detection to save power
pullup %00000010 ' enable pullup on unused input only pin c.6
let dirsB = %11111111 ' set motor connections %xxxxyyyy as outputs ONLY in this format!!! %10101010 or anything
' else other than the %xxxxyyyy format will kill your picaxe. You have been warned!!!
let dirsC = %00111101 ' set motor common connection and TestEyes as outputs, ADC's and unused pin are inputs
let adcsetup = %0000001000001000' setup adc 3 & 9
let TriggerLevel = 80 ' 87 = 3v 90 = 2.9v etc... Figure like this: 255/Desired Voltage * 1.024 = TriggerLevel
let PreviousTest = 255 ' start with a zero volt reading
let TestFreq = 1 ' this number decides how long to wait between power storage capacitor samples
let MaxOnTime = 2 ' maximum amount of time to run a motor
test:
setfreq k31
sleep TestFreq ' store some electrons
setfreq m8
calibadc TestResults ' read ADC value of 1.024v internal voltage reference
if TestResults >= TriggerLevel then goto test ' has the voltage of the storage capacitor reached our minimum? if not go store more electrons
if TestResults < PreviousTest then goto save ' we are past trigger level, if our test was a lower value then voltage is still rising. save results
goto enable ' if we are here then we are over the trigger voltage and the voltage has stopped rising. time to m
save:
let PreviousTest = TestResults ' save the test results
goto test ' go store more electrons
enable:
readadc Panels, TestResults ' test the solar panels to see which side is pointing up
if TestResults >= 127 then let MotorCom = %00111101 ' if high set portC motor common connection high
else let MotorCom = %00000001 ' or if low set portC motor common connection low
endif
low TestEyes ' enable the photobridge
pause 1 ' let the photobridge settle for 1ms
readadc c.7, TestResults ' reuse our TestResults variable to save the results
high TestEyes ' disable photobridge
if TestResults >= 127 then let Motors = %11110000 ' if high set portB motor connections !Warning %xxxxyyyy format ONLY!
else let Motors = %00001111 ' if low set portB motor connections !Warning %xxxxyyyy format ONLY!
endif
if MotorCom = %00111101 then let dirsC = %00000001 ' if PortC is high we need to set portB high first. so make change portC into inputs temporarily
endif
if MotorCom = %00111101 then let pinsB = %11111111 ' if PortC is high we need to set portB high first. so set portB high
else let pinsB = %00000000 ' or low (it should be already though through its default state)
endif
let dirsB = %00000000 ' make portB into inputs temporarily
let dirsC = %00111101 ' portC is ready to go, change into outputs
let pinsC = MotorCom ' and set the final signal to the motor common connection
let dirsB = %11111111 ' set portB to output. at this point the polarity will match the common connection
enablebod ' turn on brown out protection, because we are to about to brownout the picaxe
setfreq k31
let pinsB = Motors ' set the final signal to the individual motors
sleep MaxOnTime ' one of the motors is moving, for a max amount of time (if the power is there for it)
reset ' it might drain the capacitor and brownout the picaxe, but maybe not. reset just in case
Last edited: