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

Can pin select be changed during operation?

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



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

Can pin select be changed during operation?
PostPosted: Tue May 08, 2012 9:38 pm     Reply with quote

Not sure of the correct terminology here, so forgive me if it's been answered before, my searches didn't find a relevant result.

I have a PIC24FJ64GA004, which has lots of remappable peripheral pins. I believe you use #pin_select in the defines to set these, before the main begins operation?
But let's say I have two RGB LEDs, only three PWM channels available, and six RPn pins available; is there a way to re-define the PWM pins during operation, so I can use one RGB LED and then remap to use the other RGB LED? This wouldn't be a "mid flight" requirement, I could stop everything before changing from one to the other if required/possible.

It's just a passing thought that popped into my head when I realised that my changing another part of the project had freed up a few more remappable pins.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 08, 2012 10:54 pm     Reply with quote

Previous thread on dynamic PPS for the PIC24:
http://www.ccsinfo.com/forum/viewtopic.php?t=44325
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue May 08, 2012 11:54 pm     Reply with quote

Changing peripheral pin select at run time requires direct writes to special function registers, because #pin_select only works for the initial setting. You have to figure out the right PPS registers and codes from the datasheet. As mentioned in the linked thread, the compiler startup code fails to lock PPS registers (up to recent versions), so you can simply write it without previous unlock.

Code:
#byte RPINR19L = 0x6A6
#byte RPOR13H = 0x6DB

// IOUNLOCK sequence, shown for completeness
// not required with PCD versions up to V4.132
#asm
   mov #0x742,w1
   mov #0x46,w2
   mov #0x57,w3
   mov.b w2,[w1]
   mov.b w3,[w1]
   bset 0x742,#6
#endasm
RPINR19L = 28; // UART2 Receive = RP28
RPOR13H = 5;   // RP27 = UART2 Transmit
RoGuE_StreaK



Joined: 02 Feb 2010
Posts: 73

View user's profile Send private message

PostPosted: Wed May 09, 2012 12:28 am     Reply with quote

Thanks guys, will see if I can re-wire my PDB design and see how it goes. No big deal if the second LED doesn't work out, I'll just dump it.

Is it OK to leave the PPS registers unlocked (as they are now anyway), or are there reasons why I should lock them again after the change?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed May 09, 2012 2:17 am     Reply with quote

The locking feature is intended to prevent from unintentional configuration changes, which can be a safety requirement. There's even an IOL1WAY fuse to block further unlock operations. But I don't think either of these options will be necessary in normal applications.
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