Announcement

Collapse
No announcement yet.

How to measure interval between 5 pulses - 16F1938 - 32mhz - PicbasicPro

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to measure interval between 5 pulses - 16F1938 - 32mhz - PicbasicPro

    Hi,
    I'm using a 16F1938 running at 32mhz and I want to measure the duration between the rise of pulse number 1, and the rise of pulse number 5. Each pulse occurs every 10 to 20 ms intervals.

    Any help would be greatly appreciated.

    Roy

  • #2
    is pulse 1 and/or pulse 5 different to the "other" pulses ?
    or is it just a continuous stream of similar pulses ?
    are the pulses a consistent width ? or mark/space ratio ?
    do you have a sketch/oscilloscope trace of the pulse train ? (pref showing max and min readings)
    is this really an xy problem ?
    http://xyproblem.info/

    Comment


    • #3
      re:How to measure interval between 5 pulses - 16F1938 - 32mhz - PicbasicPro

      Hi,
      The pulses vary in duration between 1 and 2 ms. They are sharp rectangular pulses going from 0 to 4.8 vdc. They are identical, but as the speed of the device changes, the intervals change. What I'm trying to do is:
      1. Average out the changes
      2. Use more than one pulse to improve resolution.

      Comment


      • #4
        I'm still unclear on what you are trying to achieve , it sounds like you are trying to measure the average pulse width of a pulse stream over a fixed interval of some sort .
        but is the pulse width proportional to the speed or is it the pulse frequency ?
        does the frequency vary ?

        Comment


        • #5
          RE: How to measure interval between 5 pulses - 16F1938 - 32mhz - PicbasicPro

          Ok, here's the lowdown. This is going to be both a speedometer and an odometer for my motorcycle. Hence, both the frequency and the pulse width will vary with speed.

          I'm not trying to measure pulse width. I'm trying to measure the interval between pulses. Because there is very little difference between the interval for, let's say, 55 mph and 60 mph, I want to measure the interval for one entire rotation of the wheel.

          There are 5 rotor bolts, so 5 pulses equal one rotation.

          I simply want to:
          1. start a timer
          2. allow 5 rising pulses to occur
          3. stop the timer

          I can do the rest. I have the math for it.

          Roy

          I'm still unclear on what you are trying to achieve , it sounds like you are trying to measure the average pulse width of a pulse stream over a fixed interval of some sort .
          but is the pulse width proportional to the speed or is it the pulse frequency ?
          does the frequency vary ?

          Comment


          • #6
            ok lets call it a tacho , next question. how are you going to display the data ?
            eg say a lcd updated once per second .

            the easiest thing then is to count the number of rising edges / second , average it over say 5 readings and update the display with that running average every sec
            (classic freq counter style)

            another method is to fire a fixed period pulse on every rising edge into a RC integrator and then to measure the voltage across the capacitor (classic freq to voltage converter)

            starting a 16 bit timer at a suitable rate , noting its value on an edge and then counting a fixed number of edges more then subtracting the present value from its initial value (16 bit unsigned style) may give you what you require but overflows will need to be allowed for (count timer int flags) . it can be difficult to find a suitable timer rate that has sufficient resolution over the range of integration time that possible

            Comment


            • #7
              the 5 pulses per rev rang a bell

              its not the same roy is it

              http://www.picbasic.co.uk/forum/show...ghlight=speedo

              Comment


              • #8
                RE: How to measure interval between 5 pulses - 16F1938 - 32mhz - PicbasicPro

                Yes, that's me.

                Comment


                • #9
                  ok roy , that fills in some details.
                  to get a good solution you need to consider hennrik's last and unanswered question
                  You can easily count pulses for a set period using one of the timers as a counter and another as a timebase. This would not lock up the processor. To determine the most suitable aproach (or possibly if two different aproaches is needed as outlines earlier) it would be nice to know the answers to the following:

                  1) What's your desired min/max velocity, and please don't say 0?
                  2) What kind of resolution do you need?
                  3) How often must the display update?
                  what makes you think measuring 5 sequential pulse lengths and averaging the result will be better than taking pulse width samples at a measured rate and performing a running average on those samples ?
                  what is the delta V likely to be over the display refresh period and is it that the display lags too much ?
                  does the result just jitter too much ?

                  Comment


                  • #10
                    Well Richard, I don't think measuring 1 of the pulses would be a very stable measurement technique. As he mentioned, there are 5 pulses for each revolution and more than likely he is using some kind of read switch and magnet or possibly a hall switch and a magnet to do the sensing. This would tell me that the modification is probably suspect of being somewhat nonlinear in nature, and probably installed be him after the fact. The fact that there are 5 pulses for each revolution would provide a more consistent wheel revolution period. Be sides if the tire is lets say 90 or so inches in circumference and you are sensing every 1/5 of it that's what? 18 or so inches. I think that is a bit overkill as far as how fast you need to do the sensing of the speed. Just my thoughts...
                    Dave Purola,
                    N8NTA
                    EN82fn

                    Comment


                    • #11
                      rjwheaton , Attached is something I wrote here at lunch. I hope it helps. I'ts for an 18F46K22.
                      Attached Files
                      Dave Purola,
                      N8NTA
                      EN82fn

                      Comment


                      • #12
                        Well Richard, I don't think measuring 1 of the pulses would be a very stable measurement technique
                        where did I say that

                        what i'm saying is , looking at my sketch. how can measuring p1-p5 duration and then p7-11 duration and deriving
                        the average waveform period give you any better result than measuring the period of every second cycle and then averaging
                        that result ?.
                        i say that it will give you the same result but is much more complicated (for what gain ? )



                        some calcs for a 78.4in wheel circumference


                        mph p/sec period mS
                        0, 0.0, #DIV/0!
                        5, 5.6, 178.2
                        10, 11.2 ,89.1
                        15, 16.8, 59.4
                        20, 22.5 ,44.5
                        25, 28.1, 35.6
                        30, 33.7, 29.7
                        35, 39.3, 25.5
                        40, 44.9, 22.3
                        45, 50.5, 19.8
                        50, 56.1, 17.8
                        55, 61.7, 16.2
                        60, 67.4, 14.8
                        65, 73.0, 13.7
                        70, 78.6, 12.7
                        75, 84.2, 11.9
                        80, 89.8, 11.1
                        85, 95.4, 10.5
                        90, 101.0, 9.9
                        95, 106.6, 9.4
                        100, 112.3, 8.9
                        Attached Files

                        Comment

                        Working...
                        X