Is it Possible?: Pausing and resuming a time delay?

louie55

New Member
Hello,

I am new to microcontrollers and have never used one. I do not currently own a Picaxe but I might buy one if it can do what I want it to do.

Here is how I want the Picaxe to function:

Note: My input signal can be high or low. I have either option, but for this example let's just assume it will be high.

  • When the input signal goes high, a first time delay starts of around 2.25 to 2.75 seconds (The timing of which can be adjustable with a Potentiometer). Output pin stays low during this time
  • After the first time delay, Output pin goes high and a second time delay of around 3.75 to 4.75 seconds starts (This timing also adjustable with a second Potentiometer).
  • After the second time delay, Output pin goes low.
  • Then Resets for another loop waiting for the input signal again.


Also, the input signal will be provided through relay contacts, so switch bounce may need to be taken into account?

Sounds pretty simple right? It would be except I need both time delays to be "pauseable". If the input signal goes low during either time delay, I need the chip to stop counting and wait for the input to go high again and then resume the delay where it left off. It doesn't need to be extremely precise. It's ok if I lose 200 milliseconds or so, but it can't be say a half-second off. Is this something that can be done with a picaxe? Maybe it's simple? I do have some programming experience so code doesn't scare me. Maybe it can save the time passed in a variable every 100 milliseconds or something like that so that it knows where it was?

Also, if it is possible to use a Picaxe for this, how many pins will I need on my chip? Will 8 pins be enough?

Lastly, I read that the Picaxe uses it's clock frequency for time delays or "pause" commands. Is this clock generated internally to the chip or do I need an outside clock source? (Again, I'm new to this)

Any help would be appreciated.

Thanks!
 

nick12ab

Senior Member
All modern PICAXEs have built in timers - one fixed-interval time variable on the M2 parts and two more versatile timers on the X2 (and X1) parts - see settimer and tmr3setup in PICAXE Manual 2 (and also available - calculators for these commands). In addition to that, PICAXEs also have interrupts - see hintsetup and setint commands in PICAXE Manual 2 - but you can use IF statements in a loop instead if you choose to. ADDED: There's also pause commands which you can use instead of timers if you don't want to multitask - with pauses you have to use interrupts.


Also, the input signal will be provided through relay contacts, so switch bounce may need to be taken into account?
That can be taken into account by using a small capacitor. It could also be possible to replace the relay with a opto-isolator or just use direct connection through a resistor.


Sounds pretty simple right? It would be except I need both time delays to be "pauseable". If the input signal goes low during either time delay, I need the chip to stop counting and wait for the input to go high again and then resume the delay where it left off. It doesn't need to be extremely precise. It's ok if I lose 200 milliseconds or so, but it can't be say a half-second off. Is this something that can be done with a picaxe? Maybe it's simple? I do have some programming experience so code doesn't scare me. Maybe it can save the time passed in a variable every 100 milliseconds or something like that so that it knows where it was?
The timers on the X2/X1 parts allow very small intervals to be set. Therefore, you can stop and restart the timer and still retain good accuracy (much less than 200ms loss).


Lastly, I read that the Picaxe uses it's clock frequency for time delays or "pause" commands. Is this clock generated internally to the chip or do I need an outside clock source?
It depends. All modern PICAXEs can use an internal clock source and all modern PICAXEs with 28 or 40 pins can use an external clock source. See the SETFREQ command in PICAXE Manual 2 for details.
 
Last edited:

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

Everything you want should be achievable with a PICAXE and things will be easier to do once you have got to grips with some simpler code to start with. For example just initially respond to the trigger with fixed 2.5 and 4 second delays, then adding variable delays, then add the clever stuff.

In choosing a PICAXE you have a digital input, two analogue inputs and a digital output so an 08M2 should be suitable there.

The timing for delays is all internal to the M2 chips and should be entirely satisfactory for what you want to do.
 

louie55

New Member
That can be taken into account by using a small capacitor. It could also be possible to replace the relay with a opto-isolator or just use direct connection through a resistor.
My input signal is 32VAC so I almost have to use a relay to switch a smaller DC signal to the chip.

The timers on the X2/X1 parts allow very small intervals to be set. Therefore, you can stop and restart the timer and still retain good accuracy (much less than 200ms loss).
Yes, I never thought of using a bunch of small time delays in a row instead of one large one. Can that be adjustable with a potentiometer? Also, what would be an example of the code for this? Would you just run the time delay code with each line pausing say 20ms and then set an interrupt which would stop the count? Then how would you get it to start where it left off? (I know, I should read through the code manual, just thought I would ask though :) )

Thanks.
 

SAborn

Senior Member
To weigh this up, you need 1 pin for a input (digital), 1 pin for a output, and 2 ADC inputs, to me that fits the 08m2 chip about perfect with a spare pin or 2.

Yes you can do the task at hand fairly easy with a picaxe, If every 0.5 second time period is enough then running the chip at 8meg would give the time function 0.5 second increasements.

Effect of increased clock speed:
The time function will work correctly at 4MHz or 16 MHz. At other clock speeds
it will function at the speed multiple (ie at 8MHz it will increment every 0.5s).
Which would imply as 32 meg it would increase in 0.25 second intervals, which would suit your needs.

All i would do is store the time to a variable when the pause was activated and when the pause was deactivated put the variable value back into the timer

Eg...
w1 = time
*pause loop here*
time = w1

Then the timer will start counting for the period it left to pause.

Gee i need to type faster.
 

nick12ab

Senior Member
My input signal is 32VAC so I almost have to use a relay to switch a smaller DC signal to the chip.
You can use a rectifier, capacitor and potential divider - that would be quite cheap as only a small capacitor is needed since you're not drawing significant current through the ADC input but you'd need a bleeder resistor to discharge the capacitor when the 32VAC input turns off.



Yes, I never thought of using a bunch of small time delays in a row instead of one large one. Can that be adjustable with a potentiometer? Also, what would be an example of the code for this? Would you just run the time delay code with each line pausing say 20ms and then set an interrupt which would stop the count? Then how would you get it to start where it left off? (I know, I should read through the code manual, just thought I would ask though :) )
You use the readadc command to read from an analogue input. I don't mean using a bunch of small delays - I mean just waiting until the timer gets to a certain number and then doing what needs to be done - the readadc value can influence either that certain number or the timer interval.

Also, don't dismiss using pauses and interrupts on an 8-pin PICAXE.
 
Top