|
|
View previous topic :: View next topic |
Author |
Message |
705150
Joined: 25 Apr 2013 Posts: 14
|
12F1840 PWM fail |
Posted: Tue Aug 12, 2014 8:18 am |
|
|
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
|
|
Posted: Tue Aug 12, 2014 11:54 am |
|
|
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
|
|
Posted: Wed Aug 13, 2014 9:19 am |
|
|
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 |
|
|
|
|
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
|