About Fast PWM

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

In fast pwm when timer reaches TOP then resets and starting from zero also the TOV1 flag in TIFR is set on the TOP value (overflow interrupt also).What i am doing wrong in the code and when timer reaches top then starts countdown,overflow interrupt is set on bottom and the hole period is the double than i expected.Here is the code:

.include "m8def.inc"

.org 0
rjmp init
.org $06
rjmp compareA
.org $08
rjmp tim1ovf

init:
ldi r16,low(ramend)
out spl,r16
ldi r16,high(ramend)
out sph,r16
ldi r16,(1<<COM1A1)|(1<<COM1A0)|(1<<WGM11)|(1<<WGM10)
out tccr1a,r16
ldi r16,(1<<WGM12)|(1<<CS10)
out tccr1b,r16
ldi r16,$80
out ocr1al,r16
ldi r16,$00
out ocr1ah,r16
ldi r16,(1<<1)
out ddrb,r16
ldi r16,(1<<OCIE1A)|(1<<TOIE1)
out timsk,r16
sei

main:
rjmp main

compareA:
in r16,sreg

out sreg,r16
reti

tim1ovf:
in r16,sreg

out sreg,r16
reti

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

What frequency do you expect and what frequency are you running the AVR at?

ldi r16,$80
out ocr1al,r16
ldi r16,$00
out ocr1ah,r16

For the 16 bit timer registers (from the datasheet):

Quote:
To do a 16-bit write, the High byte must be written before the Low byte.

Regards,
Steve A.

The Board helps those that help themselves.