PIC-18F4520 PWM 4 channel
Discussion in "Project Addition or Changes" started by Anonymous_Bill Dec 30, 2014.
Tue Dec 30 2014, 10:26 pm
Hi
Everyone i have a question .i think i have query as i did not get output since last 4 days..:(
The query is ........
PIC 18F4520 states that you can have 4 PWM output (i.e P1A P1B P1C and P1D)
but i am stucking in getting output on oscillscope...:(
I AM USING MPLAB V 8.40
i am attaching my code please help me and guide me
Everyone i have a question .i think i have query as i did not get output since last 4 days..:(
The query is ........
PIC 18F4520 states that you can have 4 PWM output (i.e P1A P1B P1C and P1D)
but i am stucking in getting output on oscillscope...:(
I AM USING MPLAB V 8.40
i am attaching my code please help me and guide me
Tue Dec 30 2014, 10:33 pm
void main()
{
TRISCbits.TRISC2=0; RC2/CCP1
TRISDbits.TRISD5=0; RD5/P1B
TRISDbits.TRISD6=0; RD6/P1C
TRISDbits.TRISD7=0; RD7/P1D
T2CONbits.T2OUTPS3=0;
T2CONbits.T2OUTPS2=0;
T2CONbits.T2OUTPS1=0;
T2CONbits.T2OUTPS0=0;
T2CONbits.T2CKPS1=1;
T2CONbits.T2CKPS0=1;
CCP1CON=0b11001100;
while(1)
{
PR2=15;
CCPR1L=9; /// 60% DUTY CYCLE
T2CONbits.TMR2ON=1;
while(PIR1bits.TMR2IF==0);
PIR1bits.TMR2IF=0;
}
{
TRISCbits.TRISC2=0; RC2/CCP1
TRISDbits.TRISD5=0; RD5/P1B
TRISDbits.TRISD6=0; RD6/P1C
TRISDbits.TRISD7=0; RD7/P1D
T2CONbits.T2OUTPS3=0;
T2CONbits.T2OUTPS2=0;
T2CONbits.T2OUTPS1=0;
T2CONbits.T2OUTPS0=0;
T2CONbits.T2CKPS1=1;
T2CONbits.T2CKPS0=1;
CCP1CON=0b11001100;
while(1)
{
PR2=15;
CCPR1L=9; /// 60% DUTY CYCLE
T2CONbits.TMR2ON=1;
while(PIR1bits.TMR2IF==0);
PIR1bits.TMR2IF=0;
}
Sun Jan 04 2015, 11:22 am
No one bothers to help ????Anonymous_Bill
It may be that no one knows what is wrong.
I doubt that your attitude will encourage anyone.
I don't use the same compiler, so can't test your code,
but it seems okay.
Are you testing in Proteus or real hardware ,
I don't think the ECCP module works in Proteus 8.
Many people say Proteus can't be trusted.
does the PWM work in compatible mode ?
i.e just one output.
try this simpler code
void main() { TRISCbits.TRISC2=0; RC2/CCP1 TRISDbits.TRISD5=0; RD5/P1B TRISDbits.TRISD6=0; RD6/P1C TRISDbits.TRISD7=0; RD7/P1D T2CONbits.T2OUTPS3=0; T2CONbits.T2OUTPS2=0; T2CONbits.T2OUTPS1=0; T2CONbits.T2OUTPS0=0; T2CONbits.T2CKPS1=1; T2CONbits.T2CKPS0=1; CCP1CON=0b00001100; PR2=128; //set freq CCPR1L=64; //pwm ratio T2CONbits.TMR2ON=1; // start timer while(1){} }
[ Edited Mon Jan 05 2015, 05:56 am ]
Powered by e107 Forum System