| Author |
Message |
randell_xtian
Joined: 25 Mar 2008 Posts: 150 Helped: 8 Location: Philippines
|
04 Aug 2008 11:18 codes for PWM |
|
|
|
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  
|
|
| Back to top |
|
 |
SWETA
Joined: 17 Apr 2008 Posts: 11
|
07 Aug 2008 14:09 Re: codes for PWM |
|
|
|
hey..u can refer this link...u will get the code for generating modulated sine signal...would be a great help..
http://www.scienceprog.com/generate-sine-wave-modulated-pwm-with-avr-microcontroller/
bye..
|
|
| Back to top |
|
 |
yeechyan
Joined: 14 Jun 2004 Posts: 111 Helped: 1
|
11 Aug 2008 1:53 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.
|
|
| Back to top |
|
 |
craftor
Joined: 18 Aug 2008 Posts: 23 Helped: 2 Location: China
|
19 Aug 2008 2:25 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
|
|
| Back to top |
|
 |