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

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am