hector1
Newbie level 1
Hi everybody this is my first post and I need help on a program that I´m working on. I'm using the ATMega328 and there will be 6 push buttons connected to it,with the buttons you will select the speed of a motor for PWM, the firts button will turn on a motor like a 17% for PWM, the second at 34% .....and you get the idea.
The problem is that i don't know how to change the duty cycle of the PWM:-|.
I'm doing the program step by step and I have accomplished to turn on the motor at 100% but i can´t vary the duty cycle of the PWM.
This is my program I hope you can help me ;-)
The problem is that i don't know how to change the duty cycle of the PWM:-|.
I'm doing the program step by step and I have accomplished to turn on the motor at 100% but i can´t vary the duty cycle of the PWM.
This is my program I hope you can help me ;-)
Code:
.include "m328pdef.inc"
.def stack=r16
.def temp=r17
.equ increase=5
; configure stack
ldi stack,low(ramend)
out spl,stack
ldi stack,high(ramend)
out sph,stack
;define I/O
ldi temp,0x00
out DDRC,temp
com temp
out PORTC,temp
out DDRB,temp
ldi temp,0x81
sts TCCR1A,temp
ldi temp,0x09
sts TCCR1B,temp
;begin the comparator with 00
ldi temp,0x00
sts OCR1Ah,temp
sts OCR1Al,temp
lds r20,OCR1Al
ldi r21,increase
continue_up: add r20,r21
cpi r20,0xff
breq wait
ldi temp,0x0
sts OCR1Ah,temp
sts OCR1Al,r20
jmp continue_up
wait: jmp wait
delay: ldi r23,0x5
another: dec r23
brne another
ret
Last edited by a moderator: