CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC16F1517 and PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sven.petersen



Joined: 03 Apr 2013
Posts: 2
Location: Karlsfeld

View user's profile Send private message

PIC16F1517 and PWM
PostPosted: Wed Apr 03, 2013 3:06 am     Reply with quote

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: 19326

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 3:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Apr 03, 2013 4:11 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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