View previous topic :: View next topic |
Author |
Message |
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
16f1938 CCP4 setup |
Posted: Thu Jan 07, 2016 2:48 pm |
|
|
CCS PCM V5.053
I needed to setup CCP4 for a PWM output and could find nothing in the CCS commands that allow me to set the timer that the CCPx will use.
I ended up just defining a byte and writing directly to the reg:
Code: |
#byte CCPTMRS0_reg = getenv("SFR:CCPTMRS0")
//** assign TMR2 to CCP1; TMR4 to CCP4
CCPTMRS0_reg = 0b01000000;
|
Then I tried setting the PWM and found it would only use the upper 8 bits and not the extra 2 bits in register CCPxCON<5:4>.
Am I missing something or does the CCS compiler just not support the TMR selection of the PWM or the lower 2 bits of the Duty Cycle? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Thu Jan 07, 2016 3:00 pm |
|
|
I don't use that PIC but from previous posts....
what happens if you cast the '73' as a long ?
in this line.... set_pwm4_duty(73);
Jay |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 07, 2016 5:18 pm |
|
|
The following program produces PWM pulses on the CCP4 pin (PIN_D1).
The pulses occur at a rate of 3.9 KHz, and are about 73 usec long. This
was tested with compiler vs. 5.053.
Code: |
#include <16F1937.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
//==========================
void main()
{
setup_timer_4(T4_DIV_BY_1, 255, 1);
setup_ccp4(CCP_PWM | CCP_TIMER4);
set_pwm4_duty(73);
while(TRUE);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Fri Jan 08, 2016 6:51 am |
|
|
Thanks, guys.
I'm kicking myself for not seeing the CCP_TIMER4 in the .h file. I honestly searched the .h and help manual multiple times and never came across it.
It WAS tucked away after the ECCP ONLY options even though it is a CCP option.
As for the casting. I used a 16-bit var instead of a constant and it works fine. I re-read the Help for set_pwmx_duty() and it makes complete sense.
I should've thought to try that. |
|
![](templates/subSilver/images/spacer.gif) |
|