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.

[SOLVED] How to generate the PWM output for ATmega32 ?

Status
Not open for further replies.

anoop kr

Member level 4
Joined
Aug 6, 2010
Messages
69
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
kerala
Activity points
1,885
Hai
I want to about the PWM of ATmega32. I just look in the datasheet but i cant understand enough.can anybody help me.

I want to know that for generating the PWM output what should i have to do?.

And which are the pins of ATmega32 for this.Is it OC1A and OC1B.And what is
OC2.
If i want to connect a buzzer which is PWM controlled what i have to do? Please help me:?
 

Re: PWM for my ATmega32.

**broken link removed**

---------- Post added at 14:25 ---------- Previous post was at 14:23 ----------

you must first understand what is pwm: try to read here, it will give you some clues: Introduction to Pulse Width Modulation (PWM) | Netrino
 
Re: PWM for my ATmega32.

sample:

$regfile = "attiny2313.dat"
$crystal = 12000000

Config Portb = Output

Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 64

Pwm1a = 255

Do
Loop

End

For atmega32 :

$ regfile = "M32def.dat"

'Uncomment the following code to disable JTAG
Mcusr = &H80
'Mcusr = &H80

'tell the compiler which XTAL was used
$ crystal = 8000000


Startup:

Ddrb.3 = 1 'make pin4, portb.3 OC0 an output to drive LED


Tccr0 = &B01101001 'timer0 in fast pwm mode, prescale = 1
'Tccr0 = &B01101010 'timer0 in fast pwm mode, prescale = 8
'Tccr0 = &B01101011 'timer0 in fast pwm mode, prescale = 64
'Tccr0 = &B01101100 'timer0 in fast pwm mode, prescale = 256
'Tccr0 = &B01101101 'timer0 in fast pwm mode, prescale = 1024
'Tccr0 = &B01101101 'timer0 in fast pwm mode, external clock on t0 pin, falling edge
'Tccr0 = &B01101111 'timer0 in fast pwm mode, external clock on t0 pin, rising edge

Ocr0 = 0 'set the PWM value for timer0 to zero (0)

Do 'do this
Incr Ocr0 'add 1 to the PWM0 setting OCR0 means output compare register zero
Waitms 10 'stay on this ocr0 setting for 10 milliseconds
Loop

'end of PWM0 code
Compiler is BAscom AVR -free 2k of cobe
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top