[SOLVED] How to generate a PWM signal out from ATmega644 microcontroller?

Status
Not open for further replies.

randell_xtian

Full Member level 4
Joined
Mar 25, 2008
Messages
199
Helped
28
Reputation
56
Reaction score
14
Trophy points
1,298
Location
Philippines
Activity points
2,667
hi!^^ can you help me guyz!^^

how can i generate a PWM signal out form may microcontroller? i'm using a atmega644 or atmel microcontroller and may language is a C language for make it easy to program... can you give me example on how i can program may microcontroller to output the PWM to drive the 4 stepper motors...

sample codes will do...

best regards,
randell_xtian
 

codes for PWM

You can play around with the compare/capture register to generate PWM. Let's say if you set a value for the compare/capture register and let the timer counter runs, when the timer counter value matches with the compare/capture register, it'll trigger an interrupt. That's basically how to generate the PWM.
 

codes for PWM

Here is the C code about PWM using AT89X51, I think it will be a little useful for you .

#include <AT89X51.h>
sbit LED = P0^0;
void delay (unsigned int d)
{
unsigned char i;
while( d-- != 0)
{
for(i = 0; i < 8; i++);
}
}

void main (void)
{
unsigned char a, b;
while (1)
{
LED = 1;
a = 0x00;
for (b=255; b>0; b--)
{
a++;
delay (a);
LED = 0;
a = ~a;
delay (a);
LED = 1;
a = ~a;
}
LED = 0;
a = 0x00;
for (b=255; b>0; b--)
{
a++;
delay (a);
LED = 0xff;
a = ~a;
delay (a);
LED = 0;
a = ~a;
}
}
}

GL
Craftor
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…