I am having a problem with phase corrrect PWM mode 5 Tiny45

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

The scope and debugger show The OC0A pin set high the first compare match TCNT0=OCR0B and then clears it at top=OCR0A and never sets it again although at OCR0A it reverses and goes back to Bottom so the phase correct going up and down is working.

OCR0B should be going high on compare match TCNT0=OCR0B when going up and clearing when going down.

My code, what am i doing wrong here?

Mode 1 with WGM02=0 works fine.

Tiny45, 10MHZ resonator 5V supply

	;COM0A0 = 1 Phase correct PWM mode set OC0B going up, clear going down
	;COM0A1 = 1

	;WGM00	= 1 Phase correct PWM mode 5 OCRA is top
	;WGM02  = 1 

	;CS00   = 1 No prescale

	ldi r16,0b000000011  ;data direction OC0B (and OC0A) 
	out	ddrb,r16

	ldi	r16,(1<<COM0A0)|(1<<COM0A1)|(0<<WGM01)|(1<<WGM00)
	out TCCR0A,r16
	ldi r16,10
	out	OCR0A,r16 ;top
	ldi r16,6
	out	OCR0B,r16
	ldi r16,(1<<WGM02)|(1<<CS00)
	out TCCR0B,r16

I tried a tiny2313 as well with PWM waveform mode 5 and I get the same result. I can set the frequency of the timer to bounce back and forth between Bottom and OCR0A but I can't get the pin to toggle.

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

If you want to toggle OCR0B you should be setting COM0B0 & COM0B1 instead of the 'A' bits.

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

Thanks. I guess they still have not corrected the datasheet. (Page 80 Table 13-7) COM0A1 and COM0A0 should be COM0B1 and COM0B0, and where it says Table 13-4 Shows COM0B1:0 should say "Table 13-7"

Attachment(s):