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 CCS Technical Support

#pin_select PWM the problem

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



Joined: 23 Sep 2009
Posts: 55
Location: Ukraine

View user's profile Send private message Visit poster's website

#pin_select PWM the problem
PostPosted: Tue Dec 21, 2021 4:01 am     Reply with quote

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: 19495

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 4:25 am     Reply with quote

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: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 6:53 am     Reply with quote

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: 19495

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 7:41 am     Reply with quote

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: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 7:46 am     Reply with quote

yes, PPS is great for us old dinosaurs who still think pin 2 of an Rs232 connection is transmit..... Laughing
PPS allows for EASY 'board level' reconfiguration electronically...
Eddy71ua



Joined: 23 Sep 2009
Posts: 55
Location: Ukraine

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 21, 2021 9:20 am     Reply with quote

Thanks for your help - now the switching of the PWM pins works. Smile

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.
Rolling Eyes
temtronic



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

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 10:47 am     Reply with quote

why ?
simple answer, because not ALL PICs are created equal !!!
gaugeguy



Joined: 05 Apr 2011
Posts: 303

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 12:20 pm     Reply with quote

Read the data sheet and reference manuals for the processor you are using.
Ttelmah



Joined: 11 Mar 2010
Posts: 19495

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 12:47 pm     Reply with quote

#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: 8

View user's profile Send private message

PostPosted: Tue Dec 21, 2021 2:52 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Dec 22, 2021 1:58 am     Reply with quote

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: 19495

View user's profile Send private message

PostPosted: Wed Dec 22, 2021 3:02 am     Reply with quote

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