Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Pulse multiplication

  1. #1

    Pulse multiplication

    Hi guys,

    I have an pulse coming in on a digital pin on Teensy 3.2 and what I want to do is have the ability to have multiples of this pulse. I'm trying to think of how I should even comprehend writing the code for it but I'm having a tough time and wondering if someone could point me in the right direction.

    I thought about storing the initial time the pulse comes in, then storing the time the next pulse comes in and working out the difference in time pulses and then reducing the time difference so that it would be faster than the incoming pulse however that didn't work.

    Any ideas? Simply can't think even though it seems so simple.

    Thanks in advance
    M

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,057
    Often this sort of thing is done with an analog circuit. The terms to search are "phase locked loop" and "one shot".

    Both can be emulated with software, as long as the pulses are not too rapid relative to the processor speed.

    The one shot approach is simplest, but only useful if the relative timing of the pulses doesn't matter, only the total number. The idea is to simply generate a 2nd pulse a short delay after every pulse you receive.

    The phase locked loop approach involves learning how rapidly the pulses arrive. This usually only works if the pulse rate is consistent and if it varies at all, the changes are gradual. Then you generate a new pulse stream with the time divided in half. Getting the details right can be tricky.

  3. #3
    Thanks paul.

    Yes the incoming pulse would be at a constant interval, however can increase or decrease in regularity. Its coming from a timer that is user controllerable. I"m simply trying to measure the pulses then multiply accordingly. Sounds like i would need a Phase Locked loop approach then. I'll be sure to search around and come back if i've had no luck.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,057
    Probably the simplest approach, at least to get started, would involve attachInterrupt() and a function which records the micros() time and sets a flag (both variables volatile). Then in the main program, compute the different from the previous time whenever the flag gets set. For initial testing, just print the info to the Arduino Serial Monitor to confirm you're getting correct measurements.

    Then you can start the work of generating a new pulse stream using that info. Perhaps use IntervalTimer. Maybe use the update() function to change the interval. But first things first, get the measurements of incoming pulses working and verified before you add this extra complexity.

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,586
    How fast/slow are the incomming pulses?
    Perhpas an easy approach is to measure the incomming frequency (freqmeasure(), perhaps), multiply it, and just use tone() to output it to an other pin..?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •