project1
Junior Member level 1
hi
i'm using pic 18f4550 to generate pwm. i'm using the ccp2 module as ccp1 is already being used to generate pwm and that is working fine. i'm using RB3 pin for the ccp2 module output. i have 4 pushbuttons for inputs at RD2,RD3,RD4 and RD5, each for 0V,10%,50%,100%. the problem is for both 50% and 100%, the output of pwm module is showing 5V only and for 10% it is showing 2.25V. can someone pls help me with this.
i'm using 7 bits for pwm as i dont want the pwm frequency to exceed 5kHz.
here's my code:
i'm using pic 18f4550 to generate pwm. i'm using the ccp2 module as ccp1 is already being used to generate pwm and that is working fine. i'm using RB3 pin for the ccp2 module output. i have 4 pushbuttons for inputs at RD2,RD3,RD4 and RD5, each for 0V,10%,50%,100%. the problem is for both 50% and 100%, the output of pwm module is showing 5V only and for 10% it is showing 2.25V. can someone pls help me with this.
i'm using 7 bits for pwm as i dont want the pwm frequency to exceed 5kHz.
here's my code:
Code:
#include<p18f4550.h>
#include<delays.h>
#include<pwm.h>
#pragma config FOSC = INTOSCIO_EC
#pragma config WDT = OFF
#pragma config PWRT = OFF
#pragma config CP0 = OFF
#pragma config PBADEN = ON
#pragma config LVP = OFF
#pragma config CCP2MX = OFF
void main()
{
INTCON2bits.NOT_RBPU = 0;
PORTEbits.RDPU = 1;
TRISA = 0b001111;
TRISB = 0b01110111;
TRISC = 0b00000000;
TRISD = 0b00111100;
TRISE = 0b000;
ADCON1 = 0b00001011;
ADCON2 = 0b10001001;
T2CON = 0b00000101 ;
CCP1CON = 0b00001100 ;
CCP2CON = 0b00001100 ;
OpenPWM2(0x0C);
while(1)
{
if(PORTDbits.RD2 == 0)
{
SetDCPWM2(0x0C);
}
else if(PORTDbits.RD3 == 0)
{
SetDCPWM2(0x3F);
}
else if(PORTDbits.RD4 == 0)
{
SetDCPWM2(0x7F);
}
else if(PORTDbits.RD5 == 0)
{
SetDCPWM2(0x0);
}
}
}
Last edited: