Pommie said:
I read it as 12 inputs drive 12 outputs. When one input goes high the coresponding relay should switch on for a set time irrespective of how the input is.
That's also how I understood it.
µC input x1 high = output µC x1 high after 15 to 30 sec (set by user) output µC x1 low and that 12 times (x1 to x12)
The optocoupler is only for isolation between µC and relays.
Pommie said:
As you state, if he told us a bit more then there will be a better way.
Mike.
Absolutely better way is no external HW at all; all code in the µC
@chandu13
Flow in main routine
1) Set timer 0 for a 10ms interrupt
2) Declare twelve 16bit counters in RAM (2 bytes per counter)
3) Declare twelve bits in bit addressable RAM
4) Initialize all counters to specific value (20sec = 2000; 15sec = 1500)
5) Input x1 high? Yes: set output x1, set bit x1
6) Input x2 high? Yes: set output x2, set bit x2
... and so on for all twelve inputs
7) go back to step 5
Flow in ISR T0
0) reload T0
1) bit X1 high?
1a) Yes: decrement counter x1
1b) Is counter x1 = 0? Yes: reset output x1, reset bit x1 and reload counter x1
2) bit X2 high?
2a) Yes: decrement counter x2
2b) Is counter x2 = 0? Yes: reset output x2, reset bit x2 and reload counter x2
...and so on for all twelve counters
If time presets for relays are always the same (but different over all relays), use hard coded values for preset counters x1 to x12
If they always change, use PC to edit them and serial E²PROM to store them.
Understood?
Yes: go on with it
No: ask