phase correct mode 5

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

Hi I`m confused with 328p datasheet for phase correct mode 5 in timer0.

 

if I want to set and clear OCR0B pin at some value and OCR0A is TOP value as per mode 5 do I need to enable TIMSK OCIE0A and OCIE0B bits?

 

Also in register TCCR0A is there need for enabling COM0A0 and COM0A1 bits?

 

DDRB|=_BV(DDB2); // OCR0B pin output


 TCCR0A = _BV(WGM00) | _BV(COM0B1) | _BV(COM0B0) ; enable mode 5

TCCR0B=_BV(CS02) | _BV(CS00); set prescaler

 

 

 

Last Edited: Tue. Mar 12, 2019 - 01:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

surepic wrote:
do I need to enable TIMSK OCIE0A and OCIE0B bits?
Well not OCIE0A. If OCR1A is being used for setting TOP (frequency) then it can't be used for anything else. As for OCIE0B - surely that depends whether you want interrupts at the compare point?

surepic wrote:
Also in register TCCR0A is there need for enabling COM0A0 and COM0A1 bits?
No, gain the OCR1A register has two possible uses when you do PWM. Either it is the compare register for channel A and can be used to set when the OC1A pin changes state during the cycle or it has the fixed use for setting the timer frequency. In Mode 5 it is the latter so you effectively cannot use hardware channel A on that time while it is tied up being used just to set the frequency. therefore COM0A0 COM0A1 are irrelevant in Mode 5.

 

if you do want to use both channels A and B in phase correct mode you would need to use Mode 1 but in this case TOP is fixed at 0xFF so you cannot change the frequency of the timer.

 

It's a trade off - only you can decide which is best for your application.

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

Excellent explanation. Thank you

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

surepic wrote:
Excellent explanation.

???  Now you all have me confused.  clawson mentions timer1 registers several times, yet isn't OP asking about timer0?

 

Without analyzing the particular mode, I believe the answer to OP's questions are "no" and "no". 

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

Actually i thought clawson meant 0 register and 1 was just “typo”. Teusch you are right i was about timer0 not timer1.