tackling different timings for relay actuating

Status
Not open for further replies.

mgbglasgow

Junior Member level 1
Joined
Jun 15, 2011
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,508
hi all,

i would like to control three relays, i have built the circuit, its more a how-to on software structure i need. One relay is to be off for 120 seconds, on for 3, other relay is to be off for 122 seconds, on for one, last relay is off for a week, then on for 120 seconds,

i would like to be able to alter these timings without upsetting my code, i'm looking at isr routine to trigger every second. I also need to update my lcd to show run time in seconds, so code cant sit and do nothing while it waits every second.

Reading two books at once and on here/ stackoverflow (overabundance of arrogance of some on that site...)

any assistance greatly welcomed,,, SB
 

In the ISR routine, first you need to be able to keep track of time. You may want to declare a global variable (a 32Bit Integer) which increments each time ISR is called. This way, by looking at the 32Bit counter, you can see how much times has past (this will overflow after 136 years, so no worries there).

Then you need three more global variables, each also incremented by the ISR. Each holds the time for one of the relays. When the ISR is executed, increment all, and then check the three relay time counters. If their value indicates the amount of time it takes to switch a relay, do the switch on that relay and reset it's counter.

Also at each interrupt, you might want to update the LCD (since it has to show time in seconds, it won't miss anything is interrupt is also executed once every second).
 

many thanks, thats sounds good to me, will look into isr routine today, sb
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…