Pulse multiplication

Status
Not open for further replies.

mtiger

Well-known member
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
 
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.
 
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.
 
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.
 
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..?
 
Status
Not open for further replies.
Back
Top