A couple of years ago I used an 08M (actually 2 of them) to control servos on a pan and tilt on a underwater ROV. I now need to write another vaguely similar programme and thought I would convert what I already had to familiarise myself with the 18M2. I have no skills as a programmer but apart from getting help from this wonderful forum I use trial and error until I succeed.
The first major difference I found was now having to define in some way the inputs so the picaxe knows where the switches and servos are connected.
I have tried searching the archives but might have used the wrong search terms as so far have not found any easy explanation.
I'm sorry if I have missed the obvious but any pointers would be appreciated.
I have attached my 08M code in case it is of any interest to anyone.
Ian
The first major difference I found was now having to define in some way the inputs so the picaxe knows where the switches and servos are connected.
I have tried searching the archives but might have used the wrong search terms as so far have not found any easy explanation.
I'm sorry if I have missed the obvious but any pointers would be appreciated.
I have attached my 08M code in case it is of any interest to anyone.
Ian
Code:
'For Picaxe 08M
'Modification Dates
'28-4-2010 Programmed to chip
'29-4-2010 Default values changed & delay set to give about a 10 second camera transit time
'10-9-2010 Servo now driven by pulsout command which appears to solve glitch problem. Values 'have 'now been adjusted and servo pulse width (measured using BS2 with serial LCD) is in the 'range 500 'to 1000 mS although this does not give full mechanical travel of servo.
'This controller is for one axis of a (for 'Driving' not filming) small underwater video camera pan and tilt head, (so two of these are required). Servo position adjusted by using momentary up/down buttons that move the servo at a slowish speed. Servo stops moving when button released. At switch-on the servo is set to nominal mid position. The end positions of the servo can be set by the user so that when installed in its housing the servo travel only covers the range that the camera lens can see through the housing window.
'Setting end stop positions is done by a 'Set' switch which reads the current servo position 'and 'saves it as a max, min or mid value. Depending on the where the current position is the 'programme decides where to put the new value. Another switch 'Reset' clears all the stored 'values and allows the programme to cater for brand new blank chip.
'In use the supply to both ICs is interupted in order reset the pan/tilt head to mid position (not enough pins on an 08M really)
'Hardware description
'Servo on output 0 (IC pin 7)
'Increment sw on Input 1 (IC pin 6)
'Decrement sw on input 2 (IC pin 5)
'Position SET sw on input 3 (IC pin 4)
'Reset memory sw on input 4 (IC pin 3)
Symbol POSN = b6 'Current servo position
Symbol CW = b4 'Variable to decrement output pulse width
Symbol ACW = b5 'Variable to increment output pulse width
Symbol CWEOT = b0 'Clockwise end of user set travel
Symbol ACWEOT = b1 'Anticlockwise end of user set travel
Output 0 'Confirms i/o 0 as an output pin
Input 1 'Confirms i/o 1 as an input pin
Input 2 'Confirms i/o 2 as an input pin
Read 0,b0 'Read saved values from NV memory into the variables
Read 1,b1 'If its a brand new chip the values will all be blank
Read 2,b6 'so reset button inserts some sensible numbers
'Programme starts here
Main:
If Pin3 = 0 Then Gosub CHOOSER 'SET switch has been pressed
If Pin4 = 0 Then Gosub RST 'Reset Switch pressed
Button 1, 1, 1, 1, CW, 0, NOTPRESSED1 'Anticlockwise travel button
POSN=POSN +1 Max CWEOT
NOTPRESSED1:
Button 2, 1, 1, 1, ACW, 0, NOTPRESSED2 'Clockwise travel button
POSN=POSN -1 Min ACWEOT
NOTPRESSED2:
pause 20 'Slows travel speed (5=3, 20=6, 40=8 seconds)
Pulsout 0,POSN 'Output the servo pulse on 0
Goto Main
'Subroutines
CHOOSER: 'Decides where to put values
If POSN <135 then Gosub SETACWEOT 'Set Clockwise end of travel
If POSN >165 then Gosub SETCWEOT 'Set Anticlockwise end of travel
If POSN >=135 and POSN <=165 Then Gosub SETMID 'Set Midpoint of travel (Needed at power up)
Return
SETCWEOT:
Write 0,POSN 'Puts current servo position into NV memory
Return
SETACWEOT:
Write 1,POSN 'Puts current servo position into NV memory
Return
SETMID:
Write 2,POSN 'Defines mid position for startup
Return
RST: 'Resets memory to default values
write 0,200 'These values suit Futaba servo
write 2,150
write 1,100
read 0,b0 'Copies value to variables so can be used
read 1,b1
read 2,b6
Return