TeensyWolf
Well-known member
I have a project where I'm getting a square wave at ~48 Hz and I need to create a ~96Hz square wave with minimal jitter.
Last time I tested with the "machine", I was using a combination of interrupt and polling, the jitter on the falling edge was pretty bad, due to polling. It's feeding a PLL and takes too long to lock. But taking the trip to visit and test with the "machine" is a full day for me, and I'd like to reduce/eliminate the jitter so no more trips are necessary. There is also the possibility of having a variable delay in the future, tbd.
My working solution so far:
1. Setup OneShotTimer with TeensyTimerTool (great library!) to set my OUTPUT pin LOW
2. Use a GPIO interrupt, on signal CHANGE, interrupt priority set to 0 on INPUT pin.
3. In ISR, 1st thing I do is set the OUTPUT pin HIGH
4. Then I set the OneShotTimer trigger at half the period
This works great and I might leave it at that, my wave is fairly square, slightly delayed from the input, but I get about 25nS of jitter on my OUTPUT and I'm not sure if that is good enough.
I could use external hardware (flip flop) in combination with the OneShotTimer, but it would eliminate the ability to add a variable delay.
I'm thinking that I can get better using an input capture to trigger the OUTPUT pin and an interrupt at the same time. I would need to have the capture time to then set the OneShotTimer, so the square wave is near perfect.
I'm looking for an example of input capture that triggers a pin and lets me have access to the time of the trigger.
Thanks.
Last time I tested with the "machine", I was using a combination of interrupt and polling, the jitter on the falling edge was pretty bad, due to polling. It's feeding a PLL and takes too long to lock. But taking the trip to visit and test with the "machine" is a full day for me, and I'd like to reduce/eliminate the jitter so no more trips are necessary. There is also the possibility of having a variable delay in the future, tbd.
My working solution so far:
1. Setup OneShotTimer with TeensyTimerTool (great library!) to set my OUTPUT pin LOW
2. Use a GPIO interrupt, on signal CHANGE, interrupt priority set to 0 on INPUT pin.
3. In ISR, 1st thing I do is set the OUTPUT pin HIGH
4. Then I set the OneShotTimer trigger at half the period
This works great and I might leave it at that, my wave is fairly square, slightly delayed from the input, but I get about 25nS of jitter on my OUTPUT and I'm not sure if that is good enough.
I could use external hardware (flip flop) in combination with the OneShotTimer, but it would eliminate the ability to add a variable delay.
I'm thinking that I can get better using an input capture to trigger the OUTPUT pin and an interrupt at the same time. I would need to have the capture time to then set the OneShotTimer, so the square wave is near perfect.
I'm looking for an example of input capture that triggers a pin and lets me have access to the time of the trigger.
Thanks.