|
|
View previous topic :: View next topic |
Author |
Message |
sven.petersen
Joined: 03 Apr 2013 Posts: 2 Location: Karlsfeld
|
PIC16F1517 and PWM |
Posted: Wed Apr 03, 2013 3:06 am |
|
|
Hi there,
I am having a problem to get the pwm running on a PIC16F1517. I actually didn't have problem setting up PWM on other PICs like the 16F690, though.
Here is what I have done:
Code: | setup_adc_ports(sAN1|sAN2|sAN3|sAN5|sAN6|sAN7|sAN8|sAN9|sAN10|sAN12|sAN20|sAN21|sAN22|sAN23|sAN24|sAN25|sAN26);
setup_adc(ADC_CLOCK_DIV_2);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //14.2 ms overflow
set_tris_a( 0b11101111 ); // RA4 is output
set_tris_b( 0b11111111 ); // all inputs
set_tris_c( 0b10000000 ); // RC0-6 is output
set_tris_d( 0b11111111 ); // all inputs
set_tris_e( 0b11111111 ); // all inputs
// PWM for fan
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
setup_timer_2(T2_DIV_BY_16,200,1);
set_pwm1_duty((int16)100);
set_pwm2_duty((int16)100);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL); |
I can get CCP1 (RC2) and CCP2 (RC1) moving by using output_high() or output_low(), so they work as an output. I have also considred clearing the CCP2SEL flag (for CCP2), but I had no change. Same with ANSELC.
Now, I am running out of ideas. Any input? _________________ -cu
Sven |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed Apr 03, 2013 3:39 am |
|
|
OK.
Does this apply to both CCP1, and CCP2?.
The latter has re-mappable pins, are you sure you are looking at the default location?.
You do realise that 100 as a duty cycle will only give about 12.5% cycle?.
You show an interrupt call but no handler. Chip will crash if this is done in the real code.
Again are you sure you want 200 as your timer2 PR2 value. It counts from 0 to PR2, so for a 200 count, you need 199.
So with:
Code: |
void main()
{
setup_timer_2(T2_DIV_BY_1,199,1);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
set_pwm1_duty((int16)400);
set_pwm2_duty((int16)400);
while(TRUE)
{
}
}
|
and a suitable set of fuses, I merrily see C1, and C2, toggling every 200 processor cycles.
Best Wishes |
|
|
sven.petersen
Joined: 03 Apr 2013 Posts: 2 Location: Karlsfeld
|
|
Posted: Wed Apr 03, 2013 4:11 am |
|
|
Now I have found the bug. The initialisation was skipped. Now, it works exactly like listed. Sorry.... but things pretty often have stupid reasons. _________________ -cu
Sven |
|
|
|
|
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
|