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

Replies

You are reading an archived discussion.

Related Posts

Does anybody use netbeans for C/C++.......i just want to know how and from where did u download the compiler.....i tried it a lot by reading the instructions on the sun...
😕 Hye there, I’m currently trying to design and develop an interactive telephone based remote control and security but I’m having some problems regarding the whole project. I have some...
Hey guys, I read a rumour in the news paper today morning that Arun Sarin (yes 'our own' Arun Sarin who headed Vodafone before retiring this July) has emerged the...
hi, I need to know that how can we measure snr(signal to noise ratio) value with out the help of hardware.i am using ns-2 simulator and i need to measure...
pls help for my project topic in school my discipline is mechanical engineering. thanks