Why does my PICAXE 08m seem to be resetting itself half way through the program?

I am at the final stage of my automated chook door project, and have come across a problem which is proving a real headache.

To begin explaning the problem first of all I must explain a bit about how it works. First of all a PICAXE 08M is used to control a linear actuator attached to a vertical sliding door. The PICAXE is fed an LDR (light reading) and based on this 'light level' is programmed to either raise or lower the door. Two relays are employed to operate the actuator in one direction and then to reverse it (that is turning ouput 1 on lowers the door, turning both output 1 & 2 on raises the door). Unfortunately I don't have any position sensors built in (something which I now realise I should have done), which means that I have to operate the door for a set period of time (meaning that the program assumes where the door is at). Anyway when it is day I want the door to raise in order to let the chooks out. First it checks through regular intervals (and I will extend these intervals when I know its operating correctly) whether it is a certain light condition, then a pause occurs aswell as another light check to ensure that it is acutally the right light level, ready to open the door. The same also occurs when the door closes HOWEVER there is a safety system fitted to the bottom of the door (an aluminum bar which is spring loaded and hangs bolow the physical door. It is hooked up to two microswitches in series which provides input to the PICAXE). It is designed to provide feedback to the PICAXE in regards to detecting an obstruction. Because this model of PICAXE 08M does not support the SETINT command, I cannot detect a obstruction while the program is paused for the duration of the doors travel to the closed position. This lead me to try and develop some code to beat the situation.

( By the way, when an obstruction is encountered the unit is programmed to raise the door for the equivalent of 4 loops worth of door travel, and then return to the closing sub to continue closing the door. If 5 or more obstructions are encountered the program ends requiring the user to remove te obstruction and reset the unit.)

As seen in the code, I broke the time required to close the door into 250 ms intervals, and then created a for loop which performs each interval seperately. I did this so that within each loop (and therefore within each 250 ms interval) I could conduct a check to see if an obstruction had occurred before a certain loop number (NOTE I'm using Normally Closed microswitches: If input3 = 0 and Position < 83 then). The reason I have to test that the obstruction is within a certain loop number is so that the program will only accept an obstruction input while the safety bar has not reached the door frame - otherwise the PICAXE will think the bottom of the door frame is an obstruction and will continually raise and lower until the program ends after 5 obstructions - when in fact there were none! In theory and using the BASIC program simulator, my program works fine, however in reality it doesn't! The door raises fine and lowers to the closed position as desired (only when there were no obstructions! - in other words the safety microswitches were never activated). Unfortunately as soon as I introduce an obstrucion when the door is closing, it raises correctly and begins traveling to the closed position as I would hope. However when the door reaches the bottom it begins a continous cycle of raising and lowering (as would be valid if it were an actual obstruction). It has baffeled me for almost 2 days now, and the way that its behaving seems as if it reseting itself somehow. I am thinking this as I know that the program continues to raise and lower the door even after 5 obstructions (which would work if it was reseting as the obstruction variable would be reset to 0 everytime) have occured. If this part was at least working it would kill itself after 5 obstructions, however it just keeps going. To me it seems that when there is an obstruction and it reverses the door, a reset occurs, beginning the full door closing process. But because the door has already lowered a little the program then beleives that the bottom of the door frame is an obstruction and hence is in an evil loop of door raising and lowering. Can anybody please offer some adivce on my problem? I have tried replacing the PICAXE chip but the same problem occurs. The underlying issue I think sits at the level of trying to match the physical door location with the virtual location, based on time. HELP would be greatly appreciated!


'NOTE: Not all comments may be correct
symbol RELAY1 = 1     'Initialise Relay1 to output 1
symbol RELAY2 = 2     'Initialise Relay2 to output 2
symbol SETIME = 26500 'Initialise the SETIME variable to 26.5 seconds
symbol LIGHT = b0     'Initialise current LIGHT variable
symbol DAY = b1       'Initialise DAY light variable
symbol NIGHT = b2     'Initialise NIGHT light variable
symbol POSITION = b4   'Initialise counter variable
symbol STARTPOS = b3
symbol OBSCOUNTER = b5'

DAY = 100    ' Set Day threshold equal to 100
NIGHT = 30   ' Set NIGHT light threshold equal to 30

CheckLight: '**************Check Light****************
Readadc 4, LIGHT       'Read in input4 (LDR) and store in LIGHT variable
If LIGHT > DAY then    'Check if current light level is > than the day light threshold
  Goto CheckDayAgain   'If condition is true go to the CheckDayAgain sub
If LIGHT < NIGHT then  'Check if current LIGHT level is less than the NIGHT light threshold
  Goto CheckNightAgain 'If condition is true goto the CheckNightAgain sub
End if
'Pause 60000           'Pause 10 seconds
Goto CheckLight        'Recheck light level

CheckDayAgain:'*********Check Day Light Again*********
'Pause 10000
Readadc 4, LIGHT       'Read in input4 (LDR) and store in LIGHT variable
If LIGHT > DAY then    'Check again if current light level is > than the day light threshold
   If input3 = 0  then     'Check if switches are open indicating door is closed (as micro switches are normally closed)
      Goto OpenDoor    'If Light > day light threshold and door is closed, then go to OpenDoor sub
   End if
End if
Goto CheckLight        'If either of the above conditions are not true, then return to CheckLight sub

CheckNightAgain:'*******Check Night Light Again*******
Pause 1000
Readadc 4, LIGHT       'Read in input4 (LDR) and store in LIGHT variable
If LIGHT < NIGHT then  'Check if LIGHT is < than the night light threshold
  If input3 = 1  then  'Check if switches are closed indicating door is open (as micro switches are normally closed)
      Goto CloseDoor   'If Light < day light threshold and door is open, then go to CloseDoor sub
  End if
End if
Goto CheckLight        'If either of the above conditions are not true, then return to CheckLight sub

OpenDoor:'***************Open Door*******************
High RELAY1            'Switch on relay 1 or output 1
High RELAY2            'Switch on relay 2 or output 2
Pause SETIME           'Pause 26.5 seconds to allow door to rise
Low RELAY1            'Switch off relay 1 or output 1
Low RELAY2             'Switch off relay 2 or output 2
Goto CheckLight        'After opening door go back to CheckLight sub

CloseDoor:'**************Close Door******************
High RELAY1                 'Switch on RElAY1 to close door
For POSITION = STARTPOS to 93         'Enter a for loop representing the time needed to close the door
  PAUSE 250                'Pause 250 milliseconds for each loop
  If input3 = 0 and POSITION < 83 then'If switches are closed and safety bar has not reached the bottom then an obstruction has occured
    Pause 10                'Pause 10 milliseconds to allow for switch bounce
    If input3 = 0 then                'Check if switches are still closed
     Gosub Obstruction      'Go to obstruction sub when switches are closed and door is not fully closed
    End if
  End if

Low RELAY1                 'Switch off relay 1 or output 1
Goto CheckLight          'After closing door go back to CheckLight sub

OBSCOUNTER = OBSCOUNTER + 1 'Add 1 to the obstruction counter
High RELAY2                 'Activate second relay to reverse door
Pause 1130                  'Pause 1010 ms. The extra 10 ms is to account for the swith bounce delay
Low RELAY2                  'Deactivate seconds relay to allow door to continue travelling down
If OBSCOUNTER > 4 then      'if there are 5 or more obstructions then shutdown unit.
Goto Shutdown
End if
If POSITION > 4 then        'Prevents a negative POSITION
STARTPOS = POSITION - 5     'Minus 5 is to account for the fact that program returns to the next statement before executing another loop.
End if
Return                      'Return back to the loop to try finish closing the door

Shutdown:                   'This sub raises the door slighty before killing the program. The user is required to clear the obstruction and reset the unit.
Pause 1000

Bot13982 years ago
Have you used a pull up resistor for the serial in pin?
If it is kept floating then the 08M could reset it.

Get More Out of Instructables

Already have an Account?


PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!