I'm using timer B to generate a fixed width, variable frequency pulse train (timer up mode, timer1 in set/reset, ccr1 fixed to 10 cycles and ccr0 adjusted between 500 and 65535 counts).
I need to generate a software triggered, single pulse on timer 2 that is in phase with this pulse train. So basically some event happens and the next time the timer rolls over it generates a single pulse on the timer 2 pin.
The "obvious" thing I tried was to:
1. Enable interrupt on ccr2
2. Use the software trigger to change timer 2 from outmod_0 to outmod_7.
3. Let the timer generate the pulse and interrupt on the falling edge
4. In the isr, switch timer 2 back to outmod_0.
The problem is it doesn't work. I believe the issue is that I start this process at some timer value > 0, which results in the ccr2 isr firing and disabling the timer before it can roll back and generate the pulse.
I did try using the ccr0 isr to switch timer 2 into outmod_7 to stop this, but I believe the isr processing time is producing the same result.
I suppose I could add a flag to make the timer 2 isr fire twice or add a test to make sure the pin is high before killing the timer, but that seems sort of like a kludge.
So.... Is there a graceful way to handle this using some timer voodoo
I need to generate a software triggered, single pulse on timer 2 that is in phase with this pulse train. So basically some event happens and the next time the timer rolls over it generates a single pulse on the timer 2 pin.
The "obvious" thing I tried was to:
1. Enable interrupt on ccr2
2. Use the software trigger to change timer 2 from outmod_0 to outmod_7.
3. Let the timer generate the pulse and interrupt on the falling edge
4. In the isr, switch timer 2 back to outmod_0.
The problem is it doesn't work. I believe the issue is that I start this process at some timer value > 0, which results in the ccr2 isr firing and disabling the timer before it can roll back and generate the pulse.
I did try using the ccr0 isr to switch timer 2 into outmod_7 to stop this, but I believe the isr processing time is producing the same result.
I suppose I could add a flag to make the timer 2 isr fire twice or add a test to make sure the pin is high before killing the timer, but that seems sort of like a kludge.
So.... Is there a graceful way to handle this using some timer voodoo