2
votes

I want to change my PWM duty cycle from 20% to say 70%. Although while I change my OCR1AL value. The duty cycle remains the same. Why is that? Should I change something else? As far as I understand while OCR1A shows the top value, it is the only parameter (register) that I can use in order to change the duty cycle.

.include "m16def.inc"
.cseg

PWM:
    ;input
    ldi r16, 0x00
    out DDRA, r16

    ;output
    ldi r16, 0xff
    out DDRD, r16
    out PORTD, r16

    ldi r20, 0xc1
    out TCCR1A, r20
    ldi r20, 0x01


    out TCCR1B, r20
    ldi r20, 0x00
    out OCR1AH, r20
    ldi r20, 0x33
    out OCR1AL , r20

    in r22, TIFR
    andi r22, 0b00000100
    out PORTD, r22

SW0:

in r23, PINA
cpi r23, 0b11111110
brne SW0

ldi r16, 0x82
in r17, OCR1AL
ADD r16,r17
out OCR1AL, r16
jmp SW0

ldi r16, 0x00
out PORTD, r16

I am using AVR ATmega16 at 4MHz

1
Did you already try the same program in C?Martin Rosenau
Please explain the algorithm how OCR1AL is changing when button is pressed? Also please add full initialization code and/or explain schematics how button is connected. Why PA0 should be 0 and why PA1-PA7 should be 1? In either case better add to your question full the information: how you got to conclusion it does not work: what you expected, what you got.AterLux

1 Answers

1
votes

Your problem is related to the timer setup. You should check it first. If you want to use a 16 bit timer you should set your timer settings with these config: Type: Fast PWM top 0xFFFF

You can find out how to configure your timer in your microcontroller datasheet.

After this configuration if you change the top 8 bits the duty cycle will change well.

I think your setup is for a 8 bit timer so you have to change OCR1AL from 0 to 255 to change duty cycle from 0 to 100 percent.