|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
I need to know why the CCP1 PWM line is high on startup |
Posted: Fri Jan 06, 2006 5:13 pm |
|
|
Hi all,
I have started a project that needs the PWM capability of the PIC16F73 on pin RC2.
I have the code running no problem, and the duty cycle varies as designed. However, when I power-up the chip for the 1st time, the pin C2 is high for a short period, then stops. The PWM then kicks in.
ATM it causes a mosfet to short into Avalanche and burn out.
Does anyone know what might be the cause of the brief "on" pulse?
DO I have to set the value of Timer 2 before it is used?
The clock is a 20Mhz resonator.
Code: |
#include <SMPSU.h>
void InitMCU()
{
output_low(PIN_C2);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,40,1); // 23 gives ~208Khhz
setup_ccp1(CCP_PWM); // 50 gives ~100Khz
// 60 gives 82Khz
// 75 gives 65.8Khz
// 90 gives 54.3Khz
// 100 gives ~50Khz
// 150 gives 33.33Khz
// 200 gives 25Khz
}
void main()
{
int8 duty=20; // should be half of the number above
int8 i=0;
//12=50% 24=100% when "23"
// 25=50% when "50"
InitMCU();
output_high(PIN_C1);
delay_ms(100);
output_low(PIN_C1);
delay_ms(100);
output_high(PIN_C5);
delay_ms(100);
output_low(PIN_C5);
delay_ms(100);
for (i=0; i<duty+1; i++)
{
set_pwm1_duty(i);
delay_ms(400);
}
// set_pwm1_duty(duty);
do{
output_high(PIN_C1);
delay_ms(1000);
output_low(PIN_C1);
delay_ms(100);
output_high(PIN_C5);
delay_ms(1000);
output_low(PIN_C5);
delay_ms(100);
}while(1);
// Sets a 416Khz square wave.
// while(1)
// {
// output_high(PIN_C2);
// delay_cycles(2);
// output_low(PIN_C2);
// }
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 06, 2006 5:47 pm |
|
|
Quote: | When I power-up the chip for the 1st time, the pin C2 is high for a
short period, then stops. The PWM then kicks in. |
The 16F73 data sheet says, in Section 8.5:
Quote: |
Note: Clearing the CCP1CON register will force
the CCP1 PWM output latch to the default low level.
This is not the Port C i/o data latch. |
You could try doing that and see if it helps. Add the lines
shown in bold below:
Quote: |
#include <16F73.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT
#use delay(clock = 4000000)
#byte CCP1CON = 0x17
//=====================================
void main()
{
output_low(PIN_C2);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,40,1); // 23 gives ~208Khhz
CCP1CON = 0x00; // Reset CCP1 PWM output latch
setup_ccp1(CCP_PWM); // 50 gives ~100Khz
while(1);
} |
|
|
|
Guest
|
|
Posted: Sat Jan 07, 2006 7:00 am |
|
|
Cheers,
I'll give it a try. I should pay more attention to the datasheet.
Regards |
|
|
Guest
|
|
Posted: Sat Jan 07, 2006 5:00 pm |
|
|
Hi PCM P,
Tried it and I still have the same problem.
Could be anything to do with what may be in the Timer2 reg, perhaps it sets the pwm to maxing out on the first cycle?
I'm going to check the PWM registers to see what's going on.
Regards. |
|
|
Guest
|
|
Posted: Sat Jan 07, 2006 5:29 pm |
|
|
Hi,
I've found the fault.
I set Pin_c1 before I set the duty cycle on Pin_c2. If I set the duty cycle first, I can toggle C1 as often as I like without causing problems for the PWM.
I don't understand why this is happening though, I suppose it is back to the datasheet.
cheers. |
|
|
[terminate]
Joined: 08 Jan 2006 Posts: 26
|
|
Posted: Tue Jan 10, 2006 12:09 am |
|
|
i had this problem, and you should set the pwm duty first to low and then toggle as you were saying |
|
|
|
|
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
|