Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to vary the duty cycle of PWM with ATMega328

Status
Not open for further replies.

hector1

Newbie level 1
Joined
May 30, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,288
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 ;-)
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:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top