I have almost got my project working but now struggling to get the last few
bugs out. When downloaded into an 08M the most of the programme works
OK but crashes when I use one of my functions.
I am sure the problem is to do with writing to NV memory as I still dont fully
understand how it works. In the simulator memory panel only one address
seems to be used (the one in the top left corner), also when I watch the b0
to b13 values in the main simulation panel they do not update straightaway
when the relevant line is executed but do update several lines later.
In the simulator I get a 'Write Error - Overwriting Programme' message when the line 'Write b6,125' is used.
Below is my code, it would be great if anyone could look through it and offer suggestions.
Ian
bugs out. When downloaded into an 08M the most of the programme works
OK but crashes when I use one of my functions.
I am sure the problem is to do with writing to NV memory as I still dont fully
understand how it works. In the simulator memory panel only one address
seems to be used (the one in the top left corner), also when I watch the b0
to b13 values in the main simulation panel they do not update straightaway
when the relevant line is executed but do update several lines later.
In the simulator I get a 'Write Error - Overwriting Programme' message when the line 'Write b6,125' is used.
Below is my code, it would be great if anyone could look through it and offer suggestions.
Ian
Code:
'For Picaxe 08M
'Controller for one axis of a 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. The servo stops moving when button released. At switch-on the servo is set to '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 (or min) 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 chips.
'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 switch on input 3 (IC pin 4)
'Reset memory switch on input 4 (IC pin 3)
PAUSE 2000' for simulator purposes
Symbol CW = b4 'Variable to decrement output pulse width
Symbol ACW = b5 'Variable to increment output pulse width
Symbol POSN = b6 'Current servo position
Symbol CWEOT = b0 'Clockwise End Of (useful) Travel
Symbol ACWEOT = b1 'Anticlockwise end of (useful) travel
Input 1 'Confirms i/o 1 into an input
Input 2 'Confirms i/o 2 into an input
Servo 0,125 'Only issued once, 2nd number appears irrelevant
If b0 = 0 then gosub NEWCHIP 'Recognises brand new IC and puts default values in memory
CW = 0
ACW = 0
CWEOT = 200 'Initial starting value
ACWEOT = 50 'Initial starting value
POSN = 140 'Start with servo in mid position
'Read b0,CWEOT
'Read b1,ACWEOT
'Programme starts here
Main:
If Pin3 = 1 Then Gosub CHOOSER 'SET switch
If Pin4 = 1 Then Gosub CLEARMEM 'Reset Switch
'Pause 200 'Artificially slows travel speed
Button 1, 1, 1, 1, CW, 0, NOTPRESSED1 'Clockwise travel button
POSN=POSN +1 Max CWEOT
NOTPRESSED1:
Button 2, 1, 1, 1, ACW, 0, NOTPRESSED2 'Anticlockwise travel button
POSN=POSN -1 Min ACWEOT
NOTPRESSED2:
Pause 2
Servopos 0,POSN 'Output the servo pulse on 0
Goto Main
'Various subroutines
NEWCHIP:
Write b0,200 'Default values just to make servo movable on first initialisation
Write b1,50 'values get overwritten later by 'Set' routines
Write b6,125
Return
SETCWEOT:
CWEOT = POSN
Write b0, POSN 'Puts current servo position into non volatile memory as new fixed constant
Return
SETACWEOT:
ACWEOT = POSN
Write b1, POSN 'Puts current servo position into non volatile memory
Return
SETMID:
POSN = POSN
Write b6,125
Return
CHOOSER: 'Decides where to put values
If POSN <100 then Gosub SETACWEOT 'Set Anticlockwise end of travel
If POSN >175 then Gosub SETCWEOT 'Set Clockwise end of travel
If POSN >=100 and POSN <=175 Then Gosub SETMID 'Set Midpoint of travel (Needed at power up)
Return
CLEARMEM: 'Cancels stored values so newchip routine will run next time powered up
eeprom 0,(0)
write 0,0
Return