jman
Member • Dec 9, 2008
Calcaulating the correct PWM values
Hi there
I need to know if I wrote the correct code for making a PWM signal of 50Hz and a duty cycle of rise time 1.7ms and down time of 18.3ms.
I am using a PIC18f4431 with a 40Mhz crystal
Here is my code:
#include
#include
void main(void)
{
PTCON0=0b00000100;//Choose a presacalar value of 1:4
PTCON1=0b10000000;//Set the PTEN bit to enable the PWM Time Base
PWMCON0=0b00111000;
PWMCON1=0b00000000;
PTPERH=0b00001100;//Set the PWM period to 20ms
PTPERL=0b00110100;
int Duty = 800;
int count=0;
while(1)
{
PDC0H=0b00000000;//Set the duty cycle to a specific value.
PDC0L=0b11001000;
TRISB = 0x00;
//PORTB = 0x00;
}
}
Thanks very much
I need to know if I wrote the correct code for making a PWM signal of 50Hz and a duty cycle of rise time 1.7ms and down time of 18.3ms.
I am using a PIC18f4431 with a 40Mhz crystal
Here is my code:
#include
#include
void main(void)
{
PTCON0=0b00000100;//Choose a presacalar value of 1:4
PTCON1=0b10000000;//Set the PTEN bit to enable the PWM Time Base
PWMCON0=0b00111000;
PWMCON1=0b00000000;
PTPERH=0b00001100;//Set the PWM period to 20ms
PTPERL=0b00110100;
int Duty = 800;
int count=0;
while(1)
{
PDC0H=0b00000000;//Set the duty cycle to a specific value.
PDC0L=0b11001000;
TRISB = 0x00;
//PORTB = 0x00;
}
}
Thanks very much