View previous topic :: View next topic |
Author |
Message |
nfs
Joined: 28 Apr 2004 Posts: 18
|
two timers in the same time? how may i do this |
Posted: Mon May 03, 2004 5:24 am |
|
|
i want to trig two timers in the same time, what's the solution.
timer_1 to count 2 second and test therefore the input voltage if it changes or no. the second timer is the timer_2 who will sample the same voltage input in every 100µs.
this two timers must be one time which a led will be high.
if anyone help me, i give him an additionnal information _________________ nfs |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon May 03, 2004 5:34 am |
|
|
If I understand correctly, you want both timers to have the same source. Configure Timer1 or Timer2 module of the PIC to overflow every 100us. Enable the timer interrupt. In the ISR, increment a long counter and set a flag. In your main(), in a loop check if the flag is set. If it is do whatever you want your timer_2 to do and reset the flag. Also in the same loop check the value of the counter, when it reaches 2000000 it means 2 seconds have passed. Do your timer_1 action there and clear the counter. |
|
|
nfs
Joined: 28 Apr 2004 Posts: 18
|
re |
Posted: Mon May 03, 2004 6:33 am |
|
|
the source is the same but the problem is: how can i program the two timers to start on the same time? _________________ nfs |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon May 03, 2004 7:42 am |
|
|
So you want ot take 20K samples and then do a compare? Load a counter with 20000 and decrement in the timer interupt every 100uS. When it gets to zero do the compare and load the counter again. You don't need to use two timers. |
|
|
nfs
Joined: 28 Apr 2004 Posts: 18
|
re |
Posted: Mon May 03, 2004 8:04 am |
|
|
in this case i will use the timer_1 as a counter!!!! _________________ nfs |
|
|
|