Dual channel timer

misellers

New Member
I need to measure the time a button is pressed and store this to non volatile memory in a PIC 08

I'm trying to drive two relays with different time intervals programmed from a single push button. A single LED to provide feedback.

The programming sequence would be: 1st press Enter programming mode; 2nd press duration = Relay1 On time; 3rd press duration = Relay2 On time; 4th press duration = interval between Relay1 & Relay2. These durations need to survive power interruptions.

Any thoughts, ideas or experience gratefully received.

Matthew
 

hippy

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

Your program will do a number of things so tackle each as a seperate task ...

How to break out of a loop when a button pushed.

How to measure the length of time a button is pushed.

How to store and retrieve data that is non-volatile ( survives power down ); see EEPROM, READ and WRITE.

How to control relays.

How to control relays with specific time periods.

How to control a LED.

Once you have those mastered, you can draw a flowchart of what your program needs to do or describe it in a sequence of written steps and then it should be a case of putting it all together.
 

BeanieBots

Moderator
Welcome to the forum.

One criticism if I may.
Whenever designing a user programming method, it is always best to get the user to enter the required parameters in the EXACT same sequence that the events occur. Hence, I would suggest swapping over the functions of the 3rd and 4th press.

What range of duration do you require and what sort of accuracy?
A single LED could be tricky for feedback. Is there no chance of a second one?

What happens if the user gets lost and isn't sure where he is in the sequence? Does the LED indicate the sequence being programmed or the length of time the button has been held? (maybe both).

Have a look at the "button" command.
It can be placed within a timed loop. It includes a repeat feature which you could count and thus determine how long the button has been pressed.

Alternatively, you could create a loop and test for high/low on the input pin and do the counting/timing that way.

Rember, buttons are NOT perfect.
They suffer a problem called 'contact bounce'. It's all over in a few milli seconds but a fast micro can easily 'see' those bounces as very fast pushes if you are not careful.
 

misellers

New Member
Thanks for the replies

Thanks for the replies.

I should have been more specific, I've actually done a fair bit of programming before (including about 3 years of University MANY years ago), I've also done a bit of prototyping work with the Parallax Stamp and their SX chip. As such I'm pretty comfortable with program structures and driving relays, LED's, Etc.

I am trying to replicate a commercially available unit at a lower price. Hence the desire to move to a cheaper chip/platform.

The unit only needs to be accurate to about 1/2 a second with a max duration of 20 seconds.

Specifically, issues I can see arising are:

Measuring time from a pushed button including issues with bounce, instruction count in the replay routine, excessive commands, Etc.

I need to keep the cost down, so using the cheapest chip capable of programming its own non volatile memory and the best way to do this.

The unit I'm copying has a single LED but pin count permitting I do think 2 LED's would be more intuitive.

Cheers

Matthew
 

boriz

Senior Member
Or better still 3 LEDs. Each to indicate the stage of programming you are at. Maybe even a fourth to indicate a ‘running’ state. EG:

Code:
‘pseudo code

Start:

LED 4 on to indicate running
Do
   Read from eeprom /  perform relay sequence
Until button pressed
LED 4 off

LED 1 on to indicate first delay programming
Capture first delay info
LED 1 off

LED 2 on to indicate second delay programming
Capture second delay info
LED 2 off

LED 3 on to indicate third delay programming
Capture third delay info
LED 3 off

Store delay info in eeprom

GOTO start
 

BeanieBots

Moderator
As you have a fair amount of experience, there's no need to spoon feed you then. It's a relatively simple task to do what you want but there are a few things to look out for.

20 seconds to within 1/2 can easily be achieved but you might need to experiment a little. This is because there is no accurate way to determine the execution time of a given command. To make things worse, the time is also dependant on where within the program that command is situated.

The pause command has a resolution of 1mS so it is well suited for your requirements. I'd suggest using a value of around 100 to give 0.1S increments on your counter. Even using a single byte for the counter will give you 0 to 25.5S with a calibrated accuracy of 0.1S.

Try an initial pause value of 99 or 98 to take into account the time taken for other commands to execute. You can fine trim the loop by using the pulsout command which has a resolution of 10uS. Experiment.

Most commands (when clocked at 4Mhz) take around 250uS to execute.
So don't forget a 10uS pulsout will take around 250+10uS to execute.
 
Top