|
|
View previous topic :: View next topic |
Author |
Message |
kcj
Joined: 05 Oct 2011 Posts: 33
|
|
Posted: Fri May 11, 2012 3:46 am |
|
|
Hi mcr1981,
I had the same problem using pic18f13k22. The problem was that i had to setup CCP2 before setup timer 2 in the main code, CCP2 would not work without it, a bug with that pic.
You said in your original post you wanted a 1Khz frequency with 2 different duty cycles, will to do this you only need to set up timer 2 once for 1khz then setup two CCP modules and use the duty cycle to change the voltage output at the pin. The code you are using setups up two timers at 1Khz but is pointless because Timer 2 controls CCP1 and CCP2 i think.
Try the following code to see if it CCP2 works then you will know if its the same problem i had.
Code: | #include <18F45k22.h>
#fuses NOPLLEN, NOMCLR, INTRC_IO
#fuses CCP2C1
#use delay (clock=4M)
#byte T2CON = 0xFBA
#byte PR2 = 0xFBB
#define setup_timer_2(prescaler, PR2val, postscaler) \
if(prescaler) \
{ \
PR2 = PR2val; \
T2CON = prescaler | ((postscaler -1) << 3); \
} \
else \
T2CON = 0;
//======================================
void main(void)
{
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,249,1); //1000Hz
set_pwm2_duty(25);
setup_ccp1(CCP_PWM);
set_pwm1_duty(125);
while(1);
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Fri May 11, 2012 9:39 am |
|
|
I'd do two things at this point:
1) Assume that CCS is not setting up CCPTMRS0 properly.
2) Assume they may be getting the TRIS wrong for the output pin. This is fairly common on pins that are multiplexed, with the compiler 'forgetting' that the pin has been remapped, and setting the tris on the wrong bit....
So, try something like:
Code: |
#include <18F45k22.h>
#fuses NOPLLEN, NOMCLR, INTRC_IO, CCP2C1, NOXINST
#use delay (clock=4M)
#byte CCPTMRS0=getenv("SFR:CCPTMRS0")
void main()
{
setup_timer_2(T2_DIV_BY_1,249,1);
setup_timer_4(T4_DIV_BY_4,249,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty(500);
set_pwm2_duty(500);
CCPTMRS0=(CCPTMRS0 & 0B11000011)|0B00001000; //set CCP2 to use timer4
output_drive(PIN_C1); //turn on the output
do {
} while(TRUE);
}
|
and see what happens.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|