How to switch off OC1A or OC1B pins independently (PWM)

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

Hi

I set up a Phase and Frequency Correct PWM Mode on my atmega 8 prototype and everything works fine but I wonder how could I switch off OCR1A or OCR1B independently. I want to obtain 0 logic level on one of these pins at any given moment.

One solution which comes to my mind is to unset DDRB to a desired pin but is it the best solution? How would you do it?

Code:

//Timer1 Phase & frequency correct 
	TCCR1A|= (1<<COM1A1)|(1<<COM1B1);
	TCCR1B|= (1<<WGM13);

target_timer_count=F_CPU/frequency + 1;

OCR1A= (target_timer_count * 9 / 10); 
OCR1B= (target_timer_count * 5 / 10);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The simplest is to unset DDRx of the desired pins.
You could also change the COM bits.

David.

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

Hmm...

That`s what I thought so basically I have two options:

- unsetting DDRx which will set my pins as input so I would have to pull them up or
- change COM bits which would leave my pins as output in low state which is more preferable in my case

Thank you David

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

Set COMxxx to "Clear on Compare Match" state, set WGM1x to a non-PWM mode, and set both FOCx bits in TCCR1A register to latch 0's to your outputs. You can do this in a single TCCR1A write operation - pins will be properly set even if the timer is stopped.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

Quote:

I want to obtain 0 logic level on one of these pins at any given moment.

Quote:

set my pins as input so I would have to pull them up

???

Quote:

so basically I have two options:

How about setting duty cycle to 0? That would work for Fast PWM (though you
might need to use inverted to avoid a 1-count-per-cycle high).

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.