Jump to content
43oh

Timer B one-shot pulse?


Recommended Posts

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

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...