View previous topic :: View next topic |
Author |
Message |
RoGuE_StreaK
Joined: 02 Feb 2010 Posts: 73
|
Can pin select be changed during operation? |
Posted: Tue May 08, 2012 9:38 pm |
|
|
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
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue May 08, 2012 11:54 pm |
|
|
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
|
|
Posted: Wed May 09, 2012 12:28 am |
|
|
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
|
|
Posted: Wed May 09, 2012 2:17 am |
|
|
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. |
|
|
|