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

16f1938 CCP4 setup

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



Joined: 26 Sep 2003
Posts: 194
Location: Northern Indiana

View user's profile Send private message

16f1938 CCP4 setup
PostPosted: Thu Jan 07, 2016 2:48 pm     Reply with quote

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>.
Code:

   set_pwm4_duty(73);

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?
temtronic



Joined: 01 Jul 2010
Posts: 6916
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 07, 2016 3:00 pm     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 20839

View user's profile Send private message

PostPosted: Thu Jan 07, 2016 5:18 pm     Reply with quote

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);   
}
pmuldoon



Joined: 26 Sep 2003
Posts: 194
Location: Northern Indiana

View user's profile Send private message

PostPosted: Fri Jan 08, 2016 6:51 am     Reply with quote

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.
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