Timer

Lamtron

Member
Ok gave it a try using the do: until loop and the program is working when I press the start switch the led comes on pauses and then shuts off. My other test did not work once I press the switch and the program started I waited a very short time and held the start switch down to simulate a patient holding down the start switch and the results were that the led stayed on. I have attached my code for your viewing and suggestions.

; Input 3 = Start switch
;Output 2 = LED
;What should happen is when input 3 switch is pressed program should goto flash and run the program
; what should happen while the program is running input 3 should be ingnored
;

Main:
If pin3=1 then flash
goto main
Do
flash:
High 2
pause 5000
low 2
loop until pin3=0
goto main
 

lbenson

Senior Member
Do you have a pull-down resistor (say, 10K to 0V) on pin3 to assure that it is not floating (and rapidly toggling between high and low) when not pressed?

Also, in the code you posted, "DO" needs to be after "flash:"--either with the "LOOP" line immediately following (if you want the led not to come on until the button is released), or immediately above "LOOP" (if you want the LED on as soon as the button is pressed, but not retriggered until released)--I'd recommend the latter.
Code:
; Input 3 = Start switch
 ;Output 2 = LED
 ;What should happen is when input 3 switch is pressed program should goto flash and run the program
 ; what should happen while the program is running input 3 should be ingnored
 ; 

 Main:
   If pin3=1 then flash
   goto main
 
 flash:
   High 2
   pause 5000
   low 2
   Do :  loop until pin3=0
   goto main
(Note the ":" in the "DO" line.)

You can run this in the simulator.
 
Last edited:

hippy

Technical Support
Staff member
My other test did not work once I press the switch and the program started I waited a very short time and held the start switch down to simulate a patient holding down the start switch and the results were that the led stayed on.
Your program is written to do exactly that. It keeps looping and keeping the LED on until pin3=0, the button is released, which it isn't.

We seem to have resolved what it does to start; waits until the buttons is pushed, sets the LED some time later, but what are the details of what is meant to happen then ?
 

Lamtron

Member
Yes I do have a pull down resistor to ground. What I am trying to do is program the pic to act like a monostable non retrriggerable one shot or in hardware terms a 555 timer.
This is going to be used by brain injury patients which have confusion of different levels. The sequence goes like this. The patient will press the start switch and the program should run in this case a timer.
But if before the timer has time to complete its time out the patient may press the switch again. I want to have the timer complete its timing and ignore other presses of the switch until it is done. Sorry for such a lengthy explanation but by me saying I have a better chance of not missing anything. Thanks for help. The program code as is runs find if I press the start switch and do nothing the sequence program turns the led on pause then turns off it is only when I press the switch the program is doing it thing.
 

hippy

Technical Support
Staff member
But what should happen - what do you want to happen - after the timeout completes, when the patient has -

1) Pressed but not released the button ?
2) Released it but has pressed it again and is still pressing it ?
 

Lamtron

Member
1) Pressed but not released the button ? Timer sequence would continue until done.
2) Released it but has pressed it again and is still pressing it ? Same thing If it was released and then pressed again program would ignore it finish the time sequence.
I am so sorry for the confusion plus my explanation was not clear my fault. The idea with brain injury patients young or old is that we try to bring back some sort of logical thinking. By pressing a switch to turn a led on for some time they kind of remember and if they do anything else like press the switch while it is timing the end result is the same or if they hold the switch down after pressing it once the results are the same the led stays on for the adjusted time . What I am asking for if after the switch has been press cut the switch wire going to the picaxe input and then after the timer has time out re connect it this is how I think about it. I know that the switch needs to go either high or low to activate but it should finish timing and at the end of the time shut the led off. As time goes by we will most likely change the way they need to activate the switch examples are voice control, sip& puff head movement eye gaze devices but we need to start off simple for them but not so easy for me.
 

lbenson

Senior Member
In what way does the code in post 2 (either in the simulator or programmed on a chip) not work as you intend?
 

Lamtron

Member
Sorry for the delay in my response it took me this long to setup the chip and test the code. It does work so thank you.
 
Top