• AVR Freaks

PPS multiple peripherals one pin?

Page: 12 > Showing page 1 of 2
Author
machetebath
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2013/08/21 17:15:21
  • Location: 0
  • Status: offline
2013/08/26 20:17:28 (permalink)
0

PPS multiple peripherals one pin?

Just to get it straight, can I map multiple peripherals to a single pin with PPS?
Also, does Mplab X have a built in visual device initializer?
MB
post edited by machetebath - 2013/08/26 20:25:11
#1

27 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 17341
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/26 21:19:38 (permalink)
    0
    Just to get it straight, can I map multiple peripherals to a single pin with PPS?
    I connected a PWM output to two different pins. It works.

    Also, does Mplab X have a built in visual device initializer?
    No
    #2
    BobAGI
    Super Member
    • Total Posts : 1708
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/26 22:30:12 (permalink)
    5 (2)
    machetebath
    Just to get it straight, can I map multiple peripherals to a single pin with PPS?

    You can map multiple peripheral INPUTs to a single pin, they will all use the same input data.
    But only a single peripheral can drive an OUTPUT pin so it is only possible to have one output connected to that pin.
    It is also possible to send one peripheral's output to multiple pins as mentioned by the other reply.

    --
    Bo B
    Sweden & Texas
     
    #3
    maxruben
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 00:12:02 (permalink)
    5 (1)
    BobAGI
    You can map multiple peripheral INPUTs to a single pin, they will all use the same input data.
    But only a single peripheral can drive an OUTPUT pin so it is only possible to have one output connected to that pin.
    It is also possible to send one peripheral's output to multiple pins as mentioned by the other reply.

    Yes, for inputs, each input function is associated to a specific pin (or VSS if not used) which means that an input pin can be configured to one or more input functions but one input function can only be cofigured to one specific pin.
    For outputs, each pin is associated to an output function (or no function) which means that only one output function can drive a specific pin but several pins can be driven by the same output function.
    In other words: An output function can drive one or more output pins. An input pin can drive one or more input functions. Which makes sense.
     
    You can always reprogram an output pin for different output functions but only one output function can be associated to a specific pin at any time.
     
    Just out of curiosity - What is it that you want to do?
     
    /Ruben
     
    #4
    machetebath
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2013/08/21 17:15:21
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 08:57:57 (permalink)
    0
    I will be using a  PIC24fj32. PPS is new to me so I'm generally just gathering an understanding of its limits and abilities. As I was reading up on it It seemed that I could use multiple peripherals on a single pin and wanted confirmation.
    I'm still a bit unsure about how exactly to use it. If anyone has an good examples I'd love to see them. 
    Because of the reset condition, does PPS have to be performed at config time, or can I do it anytime?
    Is the lock and unlock sequence always the same?
    MB
    #5
    BobAGI
    Super Member
    • Total Posts : 1708
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 09:15:53 (permalink)
    5 (1)
    There is a config flag you have to set right if you want to run PPS mapping more than once. Normally it is only allowed a single time after reset.
    Since the connections to the PIC pins cannot really change on the PCB there are not many reasons to do it differently that what is present on the board...
    But I had to do this when I integrated the boot load functionality in my recent project and failed until DarioG pointed out that the config bit controlling the PPS protection had to be modified.
    The sequence specified in the data sheet for PPS handling must be observed every time you want to change anything.
     

    --
    Bo B
    Sweden & Texas
     
    #6
    maxruben
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 13:33:26 (permalink)
    4 (1)
    Here is a small example for UART1:
     

           // Unlock peripheral pin selection
     asm volatile ( "MOV #OSCCON,w1 \n"
         "MOV #0x46,w2 \n"
         "MOV #0x57,w3 \n"
         "MOV.b w2,[w1]  \n"
         "MOV.b w3,[w1]  \n"
         "BCLR OSCCON,#6");
     RPINR18bits.U1RXR=6;  // Map U1RX to RP6 (pin 15)
     RPOR2bits.RP4R=3;   // Map U1TX to RP4 (pin 11)
          // Lock peripheral pin selection again
     asm volatile ( "MOV #OSCCON,w1 \n"
         "MOV #0x46,w2 \n"
         "MOV #0x57,w3 \n"
         "MOV.b w2,[w1]  \n"
         "MOV.b w3,[w1]  \n"
         "BSET OSCCON,#6");

     
    As you can see, RPINR18bits.U1RXR=6 configures UART1 RX input to pin RP6 (which is pin 15 on this processor). Since bits U1RXR selects which pin should drive input UART1 RX, only one pin can be selected for this input at any one time. Other input functions could also be set to RP6 though.
     
    RPOR2bits.RP4R=3 selects output function UART1 TX to drive pin RP4 (pin 11 on this processor). 3 means UART1 TX. Only one output function can be set to drive pin RP4 at any one time but UART1 TX could also be selected for other RP pins.
     
    Instead of inline assembly there are some plib macros/function that can be used. I also really should use defined names for at least the output function instead of a hardcoded number.
     
    Any other peripheral pin select configuration should be done right after the ones for UART1 RX and TX but before IOLOCK (OSCCON bit 6) is set to 1.
     
    /Ruben
     
    #7
    machetebath
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2013/08/21 17:15:21
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 17:21:52 (permalink)
    0
    Thanks for the example, can I do it in C or is assembly required for time sensitive reasons?
    I will be using it for SPI. where would I set the PPS?
     
    post edited by machetebath - 2013/08/27 17:27:32
    #8
    NKurzman
    A Guy on the Net
    • Total Posts : 17341
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 18:03:29 (permalink)
    5 (1)
    Note there is a #include "pps.h"    header with macros
       PPSUnLock();  
       PPSOutput(PPS_SDO1,   PPS_RP9);  
       PPSInput(PPS_SDI1, PPS_RP8);   
       PPSLock();  
    #9
    machetebath
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2013/08/21 17:15:21
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 18:50:37 (permalink)
    0
    That's awesome and I really appreciate the help, unfortunately I can't get it to compile, it keeps telling me things are undeclared. I have included the header and  I changed to the correct macros for the uC i'm using but still having a lot of trouble. Can I perform this anywhere?
    I'm not sure why the headers not helping me. 
    I'll do it the old fashioned way i guess. lol
    MB
    post edited by machetebath - 2013/08/28 06:01:10
    #10
    NKurzman
    A Guy on the Net
    • Total Posts : 17341
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 21:07:09 (permalink)
    0
    "me thing are undeclared"
    Always include the exact error
     
     Try:
    PPSUnLock;
    PPSLock;
    If that is the issue
    #11
    flubydust
    Super Member
    • Total Posts : 1286
    • Reward points : 0
    • Joined: 2005/05/19 13:44:42
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 21:29:14 (permalink)
    0
    NKurzman
    Try:
    PPSUnLock;
    PPSLock;

    One of the stupidities in Microchip's PPS.H which is fixed by including this header instead...
    // Improvements to Microchip PPS.H which allow #defined parameters
    // in PPSOutput and PPSInput macros.

    #include <PPS.H>

    #undef PPSUnLock
    #undef PPSLock
    #define  PPSUnLock()    __builtin_write_OSCCONL(OSCCON & 0xbf)
    #define  PPSLock()      __builtin_write_OSCCONL(OSCCON | 0x40)

    #undef PPSOutput
    #define _PPSOutput(pin,fn)          iPPSOutput(OUT_PIN_##pin, OUT_FN_##fn)
    #define PPSOutput(pin,fn)           _PPSOutput(pin, fn)

    #undef PPSInput
    #define _PPSInput(fn, pin)          iPPSInput(IN_FN_##fn,IN_PIN_##pin)
    #define PPSInput(fn, pin)           _PPSInput(fn, pin)

    #12
    NKurzman
    A Guy on the Net
    • Total Posts : 17341
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 21:31:07 (permalink)
    5 (1)
    I complained.  They said thy would fix it, And the errors in the HJ Version of the Header file.
    #13
    maxruben
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/27 23:23:26 (permalink)
    5 (1)
    machetebath
    Thanks for the example, can I do it in C or is assembly required for time sensitive reasons?
    I will be using it for SPI. where would I set the PPS?

     
    As others have already said, you can use the PPS functions (if they work as intended!) in C but I just want to clarify that the unlocking and locking sequence must be done with exactly the sequence I showed, wither using inline assembly or the PPS macros. If not, the unlocking won't work. It is more a security feature than a timing issue. This exact sequence is the key to unlock access to pps configuration.
     
    /Ruben


    #14
    BobAGI
    Super Member
    • Total Posts : 1708
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/28 00:02:26 (permalink)
    5 (1)
    I looked up the crucial config bit to allow multiple time PPS mappings:
    IOL1WAY_OFF
    If you do not use this then you can only do PPS mapping once after the PIC starts from reset.
    I think that the default is
    IOL1WAY_ON
    and this will disallow multiple PPS mapping sequences.
     
    IOL1WAY_OFF is working for me on a PIC24FJ256GB206 part, could not get it to work before using this to set the config bit.

    --
    Bo B
    Sweden & Texas
     
    #15
    machetebath
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2013/08/21 17:15:21
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/28 18:22:27 (permalink)
    0
    So if I were to use this:
     

            //Peripherial pin selects// Unlock peripheral pin selection asm volatile ( "MOV #OSCCON,w1 \n"     "MOV #0x46,w2 \n"     "MOV #0x57,w3 \n"     "MOV.b w2,[w1]  \n"     "MOV.b w3,[w1]  \n"     "BCLR OSCCON,#6"); RPINR20bits.SDI1R=13;  // Map SDI1 to RP13 (pin 24) RPOR2bits.RP4R=7;   // Map SDO1 to RP4 (pin 11) RPOR0bits.RP0R = 8; // MAP SCLK1 to RP0 ( pin 4)       // Lock peripheral pin selection again asm volatile ( "MOV #OSCCON,w1 \n"     "MOV #0x46,w2 \n"     "MOV #0x57,w3 \n"     "MOV.b w2,[w1]  \n"     "MOV.b w3,[w1]  \n"     "BSET OSCCON,#6");

     
    would I put it first thing in my (int main) or at the top of my main.c before or after the configuration settings or does it matter?? sorry for the ignorance I'm learning.
    I can compile it there, but should it be somewhere specific?
    also how do I insert code in a thread so it doesn't look like this?
     
    mb
    #16
    NKurzman
    A Guy on the Net
    • Total Posts : 17341
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/28 18:33:24 (permalink)
    5 (1)
    No this is running code it can not be put at th Top out of a Function like CONFIG. CONFIG is directions to the compiler.
     
    Put it with all the other port configurations.
    I would sugest after you configure the port pins them selves so you know the pins are not in a funny state.
    But Before the Peripherial is set up.
     
    Others: feel free to correct me here as needed.
     
    in the tool bar there is a white box next to the smily and ABC, it is the insert source code Button.
    #17
    maxruben
    Super Member
    • Total Posts : 3301
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/08/28 23:17:00 (permalink)
    5 (1)
    Just to clarify: Configuration settings are just a couple of words at specific locations in the flash memory that are programmed when you program the chip. It is no setting that the running program does, it does not result in any code. The location of the configuration settings in your source file doesn't matter. They are placed in the hex file at the proper addresses by the linker.
     
    /Ruben
     
    #18
    machetebath
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2013/08/21 17:15:21
    • Location: 0
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/09/05 15:33:03 (permalink)
    0
    So...
    I'm not sure if I have assigned PPS pins correct for SPI as I'm not seeing any wiggle on the pins I have selected. This is the PPS code I'm using.
    // Unlock peripheral pin selection asm volatile ( "MOV #OSCCON,w1 \n"     "MOV #0x46,w2 \n"     "MOV #0x57,w3 \n"     "MOV.b w2,[w1]  \n"     "MOV.b w3,[w1]  \n"     "BCLR OSCCON,#6");   ///MAP PINS HERE:  RPOR0bits.RP0R=8;      //SET SCLK1OUT TO RP0 PIN 4 --OUTPUT RPOR2bits.RP4R=7;      //SET SDO1 TO RP4 PIN 11    --OUTPUT RPINR20bits.SDI1R=13;  //SET SDI1 TO RP13 PIN 24   --INPUT         // Lock peripheral pin selection again asm volatile ( "MOV #OSCCON,w1 \n"     "MOV #0x46,w2 \n"     "MOV #0x57,w3 \n"     "MOV.b w2,[w1]  \n"     "MOV.b w3,[w1]  \n"     "BSET OSCCON,#6"); 

     
    I'm also not sure why the code always posts this way when I copy.
    MB
    #19
    Aussie Susan
    Super Member
    • Total Posts : 3559
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re:PPS multiple peripherals one pin? 2013/09/10 21:16:26 (permalink)
    5 (1)
    To get things started, you can start by optionally clearing the IOL1WAY configuration bit but use the fact that the IOLOCK bit resets to 0. This means that you don't need to initially unlock the PPS registers - only if you set the IOLOCK bit will they be locked.
    This means that you should be able to just set the PPS registers as you need them during the initialisation phase and then carry on with the testing.
    later on, once you know that everything is working OK, you can then look to lock the PPS registers against later accidental changes during the remaining development work.
    Also, I'm not sure the device you are using (all I can see is a reference to PIC24FJ32 which is not really that specific) but you may also be selecting a pin that has analog functionality associated with it and you will need to code for that as well.
    Susan
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5