View previous topic :: View next topic |
Author |
Message |
ufarooq
Joined: 24 Jul 2014 Posts: 7
|
PIC16F1705: CCP Function not working [SOLVED] |
Posted: Thu Jul 24, 2014 3:08 am |
|
|
Morning,
I’m trying to make a simple PWM program (to be expanded later), I’m using MPLAB X IDE v2.15 while my CCS C compiler version is 1.57. When compiling the following program I get the following error. All the functions used here are available in the header file. I think it’s most probably a bug.
Code: |
#include <16f1705.h>
#device adc=10
#FUSES NOWDT,NOPUT,NOPROTECT,NOLVP,NOMCLR
#USE delay(clock=4000000)
//#USE PWM(CCP1, FREQUENCY=10000)
//#PIN_SELECT P1A=PIN_C5
void main()
{
input_a();
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL); // Using internal clock frequency
set_adc_channel(0);
delay_us(20);
//setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_pwm3_duty(128);
while(1);
}
|
setup_ccp1 is available in the header file of the complier but for reason it’s not read giving the following error.
C:\Users\umer farooq\MPLABXProjects\pic16f1705_test.X\main.c:23:66: Error#99 Option invalid :: P1A not assigned, use #PIN_SELECT
1 Errors, 0 Warnings.
Whilst using #PIN_SELECT at PIN_C5, the following error is received.
"C:\Program Files (x86)\PICC\CCSCON.exe" out="build/default/production" main.c +FM +DF +CC +Y=9 +EA +DF +LN +T +A +M +J +EA +Z -P #__16F1705=1
C:\Users\umer farooq\MPLABXProjects\pic16f1705_test.X\main.c:9:144: Error#7 Invalid Pre-Processor directive Invalid Pin ID
1 Errors, 0 Warnings.
Kindly, advise as to what can be done in this regard.
Thanks in advance.
Umer _________________ Umer
Last edited by ufarooq on Thu Sep 25, 2014 9:53 am; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 24, 2014 11:08 am |
|
|
Quote: | my CCS C compiler version is 1.57 |
That's not a version number. What is your real version ? It's a number
in this format: x.xxxx
Examples of version numbers (these are the more recent versions):
http://www.ccsinfo.com/devices.php?page=versioninfo
Here is a list of ways to find the CCS compiler version:
1. Compile a test file, and look at the top of the .LST file, which will
be in your project folder. It will show the version. However, to get
the .LST file to be generated, the source file must compile with no errors.
2. Click on the Start button in Windows, then go to Programs, and then
find the entry for CCS, which will be called "PIC-C". Then click on the icon
for "Compiler Version". It will display a box which shows the compiler
version.
3. Open a Command Prompt window and go to c:\Program Files\Picc
and run this command line: CCSC.exe +v
This method should always work. |
|
|
ufarooq
Joined: 24 Jul 2014 Posts: 7
|
|
Posted: Thu Jul 24, 2014 2:57 pm |
|
|
Yes, you are right. Sorry about that. The one I wrote in my post is the plug in version. My complier version is
Code: |
CCS PCM C Compiler, Version 5.025d, 1 23-Jul-14 04:50
Compiler operating in Evaluation Mode
|
The same code works just fine with PIC16F616 and PIC16F1938. _________________ Umer |
|
|
ufarooq
Joined: 24 Jul 2014 Posts: 7
|
|
Posted: Thu Jul 24, 2014 3:14 pm |
|
|
Quote: |
setup_ccp1(CCP_PWM);
|
And this line is not commented out in the build that shows the error. Thanks in advance. _________________ Umer |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 24, 2014 3:27 pm |
|
|
I don't have that version at my current location. If no one fixes it before
then, I will find the answer this evening. |
|
|
ufarooq
Joined: 24 Jul 2014 Posts: 7
|
|
Posted: Thu Jul 24, 2014 3:42 pm |
|
|
Thanks. _________________ Umer |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 24, 2014 11:42 pm |
|
|
Try doing it like this. This method compiles OK. I don't have this PIC
so I can't test it in hardware. But it may work.
Code: |
#include <16F1705.h>
#fuses INTRC_IO, NOWDT,PUT,NOMCLR
#USE delay(clock=4M)
#pin_select PWM3OUT=PIN_C5
//=====================================
void main()
{
setup_timer_2(T2_DIV_BY_1, 249, 1); // 4 KHz PWM frequency
set_pwm3_duty(500L); // 50% duty cycle in 10-bit PWM mode
setup_pwm3(PWM_ENABLED | PWM_ACTIVE_HIGH);
while(1);
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Fri Jul 25, 2014 2:29 am |
|
|
Aargh!...
Contact CCS. :(
They appear to have really made an error with the data setup for this chip.
Now, first there is an error with your code. PxA pin names only apply to ECCP modules. As PCM_Programmer shows, the output pin name for a standard CCP module is PWMxOUT.
However the compiler then complains about P0A not being assigned.
However the chip database, then shows they have configured four PWM modules (the chip only has two), but CCP3 is set on address 619, so the setup code PCM_programmer posts, will talk to the wrong addresses.. :(
There is then a typing error in their 'CCP pins' entry used for the settings they apply, with 'PR' used in one entry, instead of 'RP' (for relocatable pin), so I doubt if this is going to work.
It is a 'mess'. |
|
|
ufarooq
Joined: 24 Jul 2014 Posts: 7
|
|
Posted: Fri Jul 25, 2014 3:36 am |
|
|
@PCM Programmer Thanks your code works just fine!
@Ttelmah Yes, it does seem like a mess.
Regards, _________________ Umer |
|
|
FrankM
Joined: 16 Sep 2014 Posts: 1
|
|
Posted: Tue Sep 16, 2014 8:57 am |
|
|
I have the same problem with 16F1704. But you can write the configuration to the register without the CCS function.
Code: |
#BYTE CCP1CON = 0x293
CCP1CON = 0x0C;
|
No PIN_SELECT an no use of setup_ccp1(). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 16, 2014 9:35 am |
|
|
If you have a problem,
1. Post your test program that shows the failure. It must compile with
no errors so we can test it.
2. Post your CCS compiler version. |
|
|
ufarooq
Joined: 24 Jul 2014 Posts: 7
|
|
Posted: Tue Sep 23, 2014 4:09 am |
|
|
@FrankM @PCM programmer
The CCS header file for this family doesn't have the peripheral select option. So the way to go would be to pass on bits to the xxxPPS module; refer to page 137 of the datasheet. You can follow the code I wrote in xc8, this might be helpful.
Code: |
void Initialize_TMR2()
{
T2CONbits.T2CKPS = 0b00; //Pre-scalar set to 1
T2CONbits.T2OUTPS = 0b0000; //Post-scalar set to 1
PR2 = 64; //Set at 8-bit
TMR2 = 0x00;
PIR1bits.TMR2IF = 0;
T2CONbits.TMR2ON = 1; //Start Timer2
}
void Initialize_PWM1()
{
RC5PPSbits.RC5PPS = 0b01100; //Output pin -> RC5 for CCP1
TRISCbits.TRISC5 = 1; //Clear pin RC5
CCP1CON = 0x1C;
CCPR1L = 0x3F;
CCPR1H = 0x00;
CCPTMRSbits.C1TSEL = 0x0; //Lock Timer2 for CCP1
TRISCbits.TRISC5 = 0;
}
void Set_Duty1(unsigned int DutyCycle1) //Write calculated duty-cycle value to CCP1
{
CCPR1L = ((DutyCycle1 & 0x03FC)>>2);
CCP1CON = (CCP1CON & 0xCF) | ((DutyCycle1 & 0x0003)<<4);
}
|
_________________ Umer |
|
|
|