Mega64 PWM shutdown.

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am running timer/counter 2 on a Mega64 (16 MHz) in phase correct pwm mode with:

  TCCR2 = BIT(WGM20) | BIT(COM21) | BIT(CS22);

This is non-inverted output on the OC2 pin at 122 Hz. In an ISR that is triggered by an overcurrent condition synchronous with the pwm, I would like to turn off the pin as quickly as possible. I have tried:
1. Disabling pwm mode and clearing the pin.
2. Setting OCR2 to 0.
3. Disabling pwm mode and using FOC2.
in various combinations and I cannot get the pin to go low. In fact the pulse seems to be extended rather than shortened.
Naturally there are no clues in the datasheet, and a search here reveals nothing. Has anyone solved this problem?
Dave Raymond

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You need to disconnect the pin from the timer, COMxx = 0. Then set it to the desired state. At that point, you can stop the timer if you desire or let it and the PWM run.

When the timer "has" the pin there isn't much you can do with it.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Lee. You put me on the right track. I had been disconnecting the pin with:

TCCR2 = 0; 

My mistake was to immediately reconnect the pin after attempting to set it low. Apparently internally the timer will still force the pin high when reconnected. Since I am detecting a catastrophic error condition, there is no need to reconnect.
Dave Raymond