Count Pulses and duration
Greetings,
I have a project where i need to check 2 inputs but i have no clue how to do it... i will try to explain.
--What i have--
Both signals start and end at the same time
One changes to high and stays high until the end
The second has pulses
--what i need--
I need to count the number of pulses of the second input while the first input is on.
The pulses ( high state ) are 35ms long but the low state may vary
I also need to count how long is the first at the high state
--math after input receive--
I then need to compare the lenght of the first input and the number of pulses detected so i can check if there are any missed pulses.
The math i can handle...what i cant figure out is how can i measure the time of a pin being high and at the same time count the pulses of the second pin.
I thank in advance the help.
Regards
Rui
Re: Count Pulses and duration
Hi,
Depends.....on what resolution you need, what else the PIC needs to do WHILE it times and counts pulses, if the PIC needs to other things while WAITING for that first signal to go high or if it can just sit there twiddling its thumbs, waiting, if you're "locked" to a specific chip, if the pulses are occuring even when the "solid" signal is NOT on etc etc etc etc.
I'd look at a chip that incorporates the TMR1 Gate feature or wire up a bit of external logic that gates the pulses so that they are presented to the PIC only when the "solid" signal is HIGH (a simple AND gate). Set a Timer up as a counter, connect the pulsed signal to its input. Connect the "solid" signal to another input. Clear the counter. Do a PULSIN measurement on the "solid" signal, grab the counter value. Something like that perhaps.
/Henrik.
Re: Count Pulses and duration
if the two inputs start and stop together ... the length of ch1 is the sum of all pulses @ ch2 ... ( M. de La Pallice )
so, no need to care of ch1 ...
aaaaa.......
just need to log pulses @ ch 2 ...
one "pulsin" followed by enough "RC Time"s will do it ...
Alain
Re: Count Pulses and duration
Hi there,
@Henrik
I was thinking of using a 12F615. The MCu will only have a tight loop where it's just waiting for the inputs to start.
After stopping it will analise the results and can go back to wait for signals again or move forward.
@Alain
Yes... both start and stop together...the problem is that the pulses ( 35ms ) may vary in quantity in the same period of time.
Regards
Rui
Re: Count Pulses and duration
Hi,
OK, so the 12F615 has the TMR1 Gate feature, I'd say you're good to go for an all hardware solution - and since there's no pulses on second line when the first line isn't high then it gets even easier.
Set up TMR1 as a timer with the gate control enabled, clear it and feed the "long" pulse to the gate control pin, this will measure the duration of the long pulse. Set TMR0 up as a counter, clear it and feed the pulses to the counter input, this will count the number of pulses.
If you use the comparator as the gate control for TMR1 you might be able to set an interrupt up to trip when the duration of the long pulse ends.
/Henrik.
Re: Count Pulses and duration
Quote:
Originally Posted by
ruijc
@Alain
Yes... both start and stop together...the problem is that the pulses ( 35ms ) may vary in quantity in the same period of time.
Regards
Rui
and ... Where's the problem ???
the RCTime timeout feature will take care of that for you ... :D
Alain
Re: Count Pulses and duration
Thanks guys,
I still have some doubts on how to code this but i will use your tips, study them a bit and try some lines of code. ;)
Regards
Rui