This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

how to count rising edges of a pulse in ADUC842

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

Parents Reply Children
  • Most probably not. Two pulses a pause and two pulses within a 14ms window? Most probably not.

    But more importantly - you still haven't described the difference between the two states you want to detect.
    1) what the signal looks like when the module is active
    2) what the signal looks like when the module is not active
    3) how short time the module may be active as shortest
    4) how short time the module may be inactive as shortest
    5) how fast you need to be able to detect when it gets activated
    6) how fast you need to be able to detect when it gets deactivated
    7) if there can be glitches in the signal, requiring any form of filtering of the signal (sw/hw)
    8) if there is a silent phase where it matters if the signal stays high or low

    In short - you have given us zero information about exactly what a program should look for. Zero as in: no information anyone who reads this thread can use. Because the facts you have given are mismatching.

    You sometimes talks about a measurement window of 10 ms. Then you suddenly talk about 14 ms.
    You sometimes talks about pulses being 14ms long. Then suddenly about having multiple pulses within 14 ms.
    You sometimes talks about _needing_ rising edges to be processed. Then suddenly claims a scenario where it doesn't matter if you look for rising or falling edges.
    You sometimes talks about a continuous pulse train and then suddenly claims you see a specific pattern.

    Do walk through the 8 bullets above, and give specific and carefully worded answers to each and every one of them. If not for us, but at least for yourself. It's impossible to implement a program without a specification. If you don't know what problem to solve, you can't develop an algorithm that solves the problem. And you can't do any testing of the written code since you have no metric to measure if the code is correct or not.

  • ______ _______ | | | | | | | |
    __| ________| |

    0110011 is the pattern i am getting which is having total duration of 14 ms..
    The above mentioned pattern is repeating again and again..

    Hardware working:

    If the module is able to sense above signal then module has detected the probe from where above signal comes.

    If module is able to sense some other pattern then module has not detected the probe...

    So for module to sense this signal,i am counting number of pulses using timer as counter.

  • I am srry...
    i cudnt draw the waveform properly..
    pls pardon

  • And you didn't notice the different color around my waveform, and then suspected that maybe I had used some special tags? So no reason to look at the posting instructions directly above the message input box to see what tags they mention there?

    By the way - counting edges only tells us how many edges you will see. It doesn't tell you what pattern. And since you still haven't told us the answer to my questions, we still don't know if there could be other patterns with similar number of pulses.

    Another thing - when using a 14ms measurement window, that window may not be perfectly aligned with the pattern. So sometimes you may start the window at a zero. Sometimes at a one. Sometimes just at a flank. If the pattern is "exactly" 14ms and your timer code takes "exactly" 14ms, then you can get the wrong count because the 14ms are never really _exactly_ 14ms. The side generating the pulses have a limited precision to the time-generating hardware. So have your processor. And there are latencies and jitter in the code execution.

    How that affects your code is still unknown - without full answers to all questions, there are no proper specification available to know exactly what the full requirements are. All we know is that counting flanks does not detect a specific pattern. It can be enough to decide that the correct pattern is there if it is known that there can't be any other pattern that gives similar edge counts. But that is not covered by your descriptions of your problem.

    How fast do you think this project will progress, if you can't manage to give a proper - and complete enough - description of the problem? Did you find my itemized questions unreasonable? Can you then explain why you think they are unreasonable?

  • i cudnt draw the waveform properly..

    That really is not your issue. Your problem is your not understanding what you want to achieve. From what you had just described, it sounded like you wanted to recognize some certain patterns (but then it is not certain what you meant exactly by that).

    If that is true, counting the rising edges does not help you, as Per indicated. Again, if you just want to detect pattern (a 10000000001 is the same as 101 for example), you will need to detect both rising edge (indicating 1) and falling edge (indicating 0).

    An external interrupt will do it. But a simple solution will go like this:

      set up the timer for desired duration;
      while (time is not up yet) {
        if (rising edge) {set bit 0, and shift left}
        if (falling edge) {clear bit 0, and shift left}
      }
    

    Something like that will count the last n pulses within a given period of time, n=8 if you used "char", or n=16 if you used "short", ... So a pulse train of 0110110101 within 14 ms will be read as 10110101 for a "char" type.

    The advantage of this approach is that you can easily compare the "pattern" afterwards. Its disadvantage is obvious, however. But without knowing your application, it is hard to tell if it will not work for you.

  • 0110011 is the pattern i m getting ...
    i just want to count number of highs...

    I have fed this signal to timer0 pin of micro controller

    I want to use timer as a counter..

    only high to low transitions are taken as 1 by timer..

    in my case ,my counter should count 2...

  • 0110011 is the pattern i m getting ...
    i just want to count number of highs...

    That statement directly contradicts what you wrote earlier.

    Before you move forward, you will have to make up your mind as to what you are trying to do.

    Is this logic fine?

    Without knowing what you are trying to do with that piece of code, there is no way to know if the logic is fine.

    Per is absolutely correct about this: you need to read and comprehend what others are telling you.

  • i need to count high to low transitions from my signal...

    in my case it is two.....

    
    #include <stdio.h>
    #include <math.h>
    #include <aduc842.h>
    
    sbit Tone = P3^5;
    
    
    void sendmoduleinit(void);
    
    
    void main()
    
    {
    
            PLLCON = 0x00;
            EA = 1;
            ES = 1;
    
            T3CON = 0x86;
            T3FD = 0x2D;
            SCON = 0x50;
    
    
    Tone = 1;
    
    TMOD = 0x50;
    
    TH1 = 0;
    TL1 = 0;
    
    while(1)
    {
       do
    {
       TR1 = 1;
       sendmoduleinit();
    }
    
    
    while(TF1 == 0);
    TR1 = 0;
    TF1 = 0;
    
    }
    
    
    }
    
    
    void sendmoduleinit(void)
    {
    
    SBUF = TL1;
    
    while (TI == 0)
     {
    
     }
     TI = 0;
    
    
    }
    
    
    

  • i need to count high to low transitions from my signal...

    Then why do you count rising edges?

  • 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...

    ...

    i just want to count high to low transitions....

    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.