View previous topic :: View next topic |
Author |
Message |
Eddy71ua
Joined: 23 Sep 2009 Posts: 55 Location: Ukraine
|
#pin_select PWM the problem |
Posted: Tue Dec 21, 2021 4:01 am |
|
|
In a project with a PIC12F1822 I want to change the assignment of the default output CCP1 to pins RA4 and RA5.
I try to use the command #pin_select:
Code: |
#use fast_io(a)
#pin_select P1A=PIN_A5
#pin_select P1B=PIN_A4 |
And I get a message from the compiler:
Quote: |
Error 7 "Probe.c" Line 7(12,24): Invalid Pre-Processor directive Invalid Pin ID
Error 7 "Probe.c" Line 8(12,23): Invalid Pre-Processor directive Invalid Pin ID
|
What am I writing wrong?
(v5.101) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Dec 21, 2021 4:25 am |
|
|
What makes you think your chip supports PPS?.
IT DOESN'T.
What it does support is 'PWM steering', where one PWM signal, can be
routed in the peripheral setup to different pins. This is controlled in the
setup_pwm with CCP_PULSE_STEERING_x, to select the output. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 21, 2021 6:53 am |
|
|
As Mr. T points out, that PIC is not 'PPS', rather 'APF'.
Alternate Pin Functions, section 12 of the datasheet. Certain functions can be redirected to some pins.
PPS allows several peripherals to be remapped to several pins,similar to a Programable Logic Array. Once programmed though ,it cannot be changed(unless totally erased). This is similar to #FUSES.
APF though is a 'program level' remapping. If you change the APFCON register, then the peripherals will be redirected to the 'alternate' pins.
it'd be interesting to ask uchip why/how APF came about. It might have been a 'test' to see if they could merge or join PLA to PICs.
what I do know is things were a LOT simpler with the PIC16C84 ! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Dec 21, 2021 7:41 am |
|
|
Key difference is that the APFCON only ever allows two locations. PPS allows
things to map almost anywhere.
Code: |
#bit CCP1SEL=getenv("BIT:CCP1SEL")
#bit P1BSEL=getenv("BIT:P1BSEL")
//then in the code
CCP1SEL=TRUE; //sets P1A to it's alternate
P1BSEL=TRUE; //sets P1B to it's alternate
|
Historically they had alternate pin functions with fuses first. Then APCON.
Guess it was just a development to give software movability rather than
using fuses. Then once this was done they went for the greater flexibility
of PPS.
Last edited by Ttelmah on Tue Dec 21, 2021 7:46 am; edited 1 time in total |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 21, 2021 7:46 am |
|
|
yes, PPS is great for us old dinosaurs who still think pin 2 of an Rs232 connection is transmit.....
PPS allows for EASY 'board level' reconfiguration electronically... |
|
|
Eddy71ua
Joined: 23 Sep 2009 Posts: 55 Location: Ukraine
|
|
Posted: Tue Dec 21, 2021 9:20 am |
|
|
Thanks for your help - now the switching of the PWM pins works.
Although my brain still has a slight misunderstanding of why the command works on some chips, while others must be accessed through an application environment variable.
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Tue Dec 21, 2021 10:47 am |
|
|
why ?
simple answer, because not ALL PICs are created equal !!! |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 303
|
|
Posted: Tue Dec 21, 2021 12:20 pm |
|
|
Read the data sheet and reference manuals for the processor you are using. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Tue Dec 21, 2021 12:47 pm |
|
|
#PIN_SELECT is for chips with PPS.
Yours does not have PPS.
If when you search the data sheet you find 'PPS', then #PIN_SELECT applies.
Otherwise it doesn't. |
|
|
waffles
Joined: 21 Dec 2021 Posts: 10
|
|
Posted: Tue Dec 21, 2021 2:52 pm |
|
|
There's also an interface to configure APF + pulse steering provided via the setup_ccp() function/s i.e
Code: |
setup_ccp1(CCP_PWM | CCP_P1A_A5); // route pwm output to A5 (pin 2)
set_pwm1_duty(0L);
|
|
|
|
Eddy71ua
Joined: 23 Sep 2009 Posts: 55 Location: Ukraine
|
|
Posted: Wed Dec 22, 2021 1:58 am |
|
|
Thank you very much.
The final PWM configuration command in my case looks like this:
Code: |
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_P1A_A5|CCP_P1B_A4); // route pwm output to A5,A4
set_pwm1_duty(250L); |
Checked in the controller - everything works fine. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Dec 22, 2021 3:02 am |
|
|
Yes, I pointed out that setup_CCP could control this right at the start.
The key thing is to understand 'peripherals'.
Think about it. If you are using a PIC with only one UART, then 'of course'
commands to setup UART2 won't work. PPS, APFCON, and the alternate
pin fuses are each different peripherals. They each need different
commands to be used. In each case you can also 'go manual', but use
the right commands and CCS does it for you. |
|
|
|