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

12F1840 PWM fail

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



Joined: 25 Apr 2013
Posts: 14

View user's profile Send private message

12F1840 PWM fail
PostPosted: Tue Aug 12, 2014 8:18 am     Reply with quote

i can not make the CCP1 function to work on A5, it works on A2
if anyone have any kind of solution.
compiler is 5.008

Code:
#include <12F1840.h>
//#device adc=10
#fuses INTRC_IO,noWDT,NOPUT,NOPROTECT,NOCPD,noMCLR, noBROWNOUT,nolvp, HS
#use delay(internal=32000000)
#byte APFCON = 0x01 //CCP on RA5
#int_timer2
void updateClock() { ctime++; }

void main(void) {
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_TIMER2);
                setup_timer_2(T2_DIV_BY_1,255,1);    
   //setup_ccp1(CCP_PWM);
   setup_ccp1(CCP1_A5);
   set_pwm1_duty(500);
   while(1)
   {
      count++;
      set_pwm1_duty(count*500);
      //if (count) output_high(pin_a5);
         //else output_low(pin_a5);
      delay_ms(1000);
   }
}

thank you in advance
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 12, 2014 11:54 am     Reply with quote

The code shown below will output a PWM signal (3.9 KHz squarewave)
on pin A5. I tested this with vs. 5.026. I don't know if it works with
your version.
Code:

#include <12F1840.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT
#use delay(clock=4M)

#bit CCP1SEL = getenv("BIT:CCP1SEL")

//======================================
void main()
{

/*
// This puts PWM on Pin A2.
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1); 
set_pwm1_duty(128);
*/

// This puts PWM on Pin A5.
setup_ccp1(CCP_PWM);
CCP1SEL = 1;       // Get PWM output on pin A5
output_drive(PIN_A5);
setup_timer_2(T2_DIV_BY_1, 255, 1); 
set_pwm1_duty(128);

while(1);
}
705150



Joined: 25 Apr 2013
Posts: 14

View user's profile Send private message

PostPosted: Wed Aug 13, 2014 9:19 am     Reply with quote

Thank you very much "PCM programmer" for your reply, it works, i can now continue from this sample program in what i need.

Have a pleasant day
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