BEAM/Picaxe 20x2 - Tiny Solar Turbot

JamesWhite

New Member
A new bot, hot off my workbench:

bptb.JPG

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:

erco

Senior Member
VERY cool bot, James. Love your website and other great projects, too. I'm inspired to build!
 

MPep

Senior Member
Hi James,

I LIKE IT!!!!
Indeed it reminded me of Crab Claws too.
Paralleling outputs is, after some thought, a simple and obvious choice. Well done.

MPep
 

hippy

Technical Support
Staff member
Paralleling outputs is, after some thought, a simple and obvious choice.
It's a neat trick but some care and risk may have to be taken as PICAXE ports may spread over a variety of underlying PICmicro ports.

A "Let pinsX=" command may not set all outputs simultaneously as the firmware can only update one PICmicro port at a time. For example, for a 20X2 and "Let pinsB=$FF", there may be a few microseconds between PICAXE Pin C.4 (leg 14, RC2) and PICAXE Pin C.5 (leg 13, RB4) changing state.

During that time one pin may be high and another low so effectively a short between pins with potentially high current flow. The times are quite short and the PICmicro / PICAXE is fairly robust so it may well be that no observable or real damage is being caused and it may be less detrimental than it could be but would not be a recommended practice.

The time can be reduced by running the PICAXE at higher speeds, but lower speeds ( particularly 32kHz ) will extend the time the adverse condition exists for.
 

chipwich

Member
During that time one pin may be high and another low so effectively a short between pins with potentially high current flow. The times are quite short and the PICmicro / PICAXE is fairly robust so it may well be that no observable or real damage is being caused and it may be less detrimental than it could be but would not be a recommended practice.
.
WARNING - POOR ENGINEERING PRACTICES FOLLOW:

I have yet to burn out a PICAXE (or blow an LED) despite an absence of current limiting resistors on LEDs, experimenting with ganged outputs, etc. The 20mA output limit seems high enough to drive real-world devices, but low enough to avoid permanent damage to the output stages or connected device (eg, LED) when shorted. I haven't done any intentional destructive testing, but these devices seem remarkably robust.

I'm sure that overvoltages could quickly destroy the chip. But barring that, how easy/hard is it to cause a failure in the output pins? How long can a PICAXE sustain a shorted output before permanent failure? Does it make any difference whether it is shorted high or shorted low?
 

srnet

Senior Member
The 20mA output limit seems high enough to drive real-world devices, but low enough to avoid permanent damage to the output stages or connected device (eg, LED) when shorted
Remember that 20ma is the maximum that you should, as a result of your design, allow to flow through the output pin.

The pins are not current limited to ensure that under fault conditions no more than 20ma will flow through the pin.
 

G-Man

New Member
I'm confused. I thought BEAM robots were made using simple analog components (comparators and such) and not with microcontrollers.
 

MPep

Senior Member
G-Man,

I suppose you're right. BUT, if a micro-controller will do the job, then why not.
Then main thing is that they are SOLAR powered, so to provide bursts of power/activity.

MPep
 

JamesWhite

New Member
Thanks Chipwich & Mpep!
This little guy is still going strong, I just had him out in the sun yesterday.

Hippy, these kinds of caveats are frustrating. If I was able to understand the book of a datasheet from pic, I probably would not be using a picaxe.
I took the rev-ed manual at it's word when it says "when working with multiple outputs it is often convenient to change all outputs simultaneously..." to mean simultaneously. Oh well. It worked for me this time and the picaxe is easily accessible/replaceable if I do fry it. I will have to try switching at a higher speed tough and see if I can coax some more power saving.

G-Man, Yes typically BEAM robots do not utilize a uC, but it's hardly the first BEAM bot to have one. The fact that this guy lives on the sun alone as his power supply, and is modeled after many BEAM turbots that came before him makes him an BEAM bot in my opinion. If I scratch off the pic logo, no one could tell the difference ;)

Gotta love picaxe!
Thanks guys!
 
Top