We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello,
I am using ADUC842.
Continuous pulse is being fed at port P2.6
I need to calculate rising edges of the pulse for 10ms time interval..
how should i proceed?
pls help.
Regards Mayuri
counter in 8051 takes high to low transition... its not my choice sir...
it doesnt matter wht my signal is...0110011 or 1100110 or something else...
i just want to count high to low transitions....
But why are you then even talking about patterns?
Counting flanks will not see any difference between:
100000001100 000000101000 000000001001 001010000000 011111110100
All the above alternatives have two rising edges and two falling edges (but see note 1 below). So edge-counting is obviously not a working solution for pattern detection.
Not only that - if your signal could potentially be noisy, then you could manage to count two extremely short noise pulses (just long enough for the timer to detect them) even if your intended signal should never manage a pulse shorter than 1ms.
Maybe you should switch to a project where do you understand the exact needs - only then can you even start considering how to implement a solution.
If the word "pattern" is really important to this problem, then the traditional way is to either catch the flanks (both high and low) and pick up the exact time when the flanks was seen - or sample the signal at a frequency higher than the shortest high or low pulse allowed for the signal. Then the samples/times can be analyzed to decide if the detected data matches the pattern - obviously, a repeating pattern requires the analyzer to take care of the situation where you start listening at any time in the pattern, i.e. that the same repeating pattern 01011101001 could be seen as all of the following rotated variants (11 alternatives since 11 "bit slots" in pattern:
01011101001 10111010010 01110100101 11101001010 11010010101 10100101011 01001010111 10010101110 00101011101 01010111010 10101110100
Note 1: The first pattern could potentially have only one rising edge and two falling edges. The third pattern could potentially have two rising edges and one falling edge. A flank detector can only see flanks that happens while the flank detector is active - flanks that happens just before or just after can't be separated from a situation where the signal has been static high a long time before the flank detector is started - or the signal stays high a long time after the flank detector runs out of time.
counter in 8051 takes high to low transition...
...
So, the timer counts the falling edge, and you want to count the falling edge. But you do not think the timer is the way to go?
Whatever. You can use the INTx pin to count. Another solution would be pulling:
pulse_counter += ((port_prev ^ port_now) & port_prev)?1:0;
If any of the pins on the port has a falling edge, pulse_counter is incremented. You can mask it to just count certain pins (or a single pin).
pulse_counter += ((port_prev ^ port_now) & port_now)?1:0;
counts the rising edge, in case you want.