Discussion in "Project Addition or Changes" started by    Anonymous_Bill    Dec 30, 2014.
Tue Dec 30 2014, 10:26 pm
#1
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
Tue Dec 30 2014, 10:33 pm
#2
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;
}
Thu Jan 01 2015, 10:18 pm
#3
No one bothers to help ????
Sun Jan 04 2015, 11:22 am
#4


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 ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am