Changing port pin assignment to internal peripheral at runtime

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

In my application, I want to use bicolor LED. Usually the Blue color is used for BLE state determination.

   

Can I change the port assigned to line output of the PWM mode in timer module i.e. if battery is below 30%, use red for BLE state notification and if battery is above 30%, use blue led for BLE state notification?

   

If answer is Yes, please explain the way to do it in main code.

   

 

   

***EDIT: since PWM has 2 outputs, line and line_n. I can use one output for one color and another for another color. So for this i have second question, can i disable one output and enable one i.e. if line is enabled, line_n is disabled and vice versa?

   

Thanks

   

Ashutosh

0 Likes
1 Solution
MR_41
Employee
Employee
First like received

A TCPWM output is mapped to multiple GPIO pins - usually three.  The details can be found in "Port Pin Connections" table in the device data sheet.

   

For example, TCPWM0 output is mapped to P4_0, P1_0 and P3_0.  These are shown as TCPWM0_P[0], TCPWM0_P[1] and TCPWM0_P[2] in the port pin connections table.  For example, if you have the blue LED on P4_0 and red LED on P1_0, you can connect and disconnect these using the HSIOM_PORT_SELx register.

   

In the HSIOM_PORT_SELx register, each port pin is controlled by 4 bits - bit#0 to bit#3 control pin#0, bit#4 to bit#7 control pin#1 etc. Details can be found in the device family register TRM.

   

With this information it is possible two switch between two pins for the PWM output.

   

1. Place the PWM in the design and connect it to a pin connected to one of the LEDs, say LED_BLUE.  For example, connect this to P4_0.
2. Place a pin in the design and configure this as general purpose GPIO with strong drive, and name this as the other LED, say LED_RED.  Connect this to another port bit that has the same PWM mapping as the blue LED.   If the blue LED is connected to P4_0, then connect the red LED to P1_0 (or P3_0)
3. In code, to disconnect P4_0 from PWM, write 0000 to bit#0 to bit#3 of HSIOM_PORT_SEL4 register. To connect P1_0 to the PWM, write 1000 to bit#0 to bit#3 of HSIOM_PORT_SEL1

   

Hope this helps.

   

Below are the links to the device data sheet and register TRM for the PRoC BLE.

   

PRoC Data Sheet

   

PRoC Register TRM

View solution in original post

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You can use a Control Register component and an AND gate to select wihch LED will light.

   

Alternatively you may use a multiplex component, the output enable of the pin component.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

@Bob, thanks. But, I could not find control register component/AND gate or multiplex anywhere in? I am using CYBL10461-56LQXI device. I did enable output enable but not sure how to use it. Please do explain this.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are using a very small part with no UDBs. For control register and AND gates you need parts with UDBs.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

So, is it possible to at least change port pin assignment at runtime, e.g. assign port pin x if battery is less than to 30% to TCPWM line output and assign port pin y if battery is greater than 30% to TCPWM line output?

0 Likes
Anonymous
Not applicable

You can change the compare values at runtime (I think PWM_WriteCompare()), so set the value to 0 means off. You could also set PWM_blue to CMP Type blue = "less" and CMP Type red = "greater or equal" with the same CMP values, than the LED switches between red and blue. So you could show battery state and bluetooth connection at the same time. Have a look at the diagram of the PWM configuration.

   

E.g.

   
        
  • no light = battery full, no connection
  •     
  • blue blinking = battery full, advertising
  •     
  • blue = battery full, connection established
  •     
  • red = battery low, no connection
  •     
  • red and blue blinking alternately with same period = battery low, advertising
  •     
  • red (short) and blue (long) blinking alternately = battery low, connection established
  •    
0 Likes
MR_41
Employee
Employee
First like received

A TCPWM output is mapped to multiple GPIO pins - usually three.  The details can be found in "Port Pin Connections" table in the device data sheet.

   

For example, TCPWM0 output is mapped to P4_0, P1_0 and P3_0.  These are shown as TCPWM0_P[0], TCPWM0_P[1] and TCPWM0_P[2] in the port pin connections table.  For example, if you have the blue LED on P4_0 and red LED on P1_0, you can connect and disconnect these using the HSIOM_PORT_SELx register.

   

In the HSIOM_PORT_SELx register, each port pin is controlled by 4 bits - bit#0 to bit#3 control pin#0, bit#4 to bit#7 control pin#1 etc. Details can be found in the device family register TRM.

   

With this information it is possible two switch between two pins for the PWM output.

   

1. Place the PWM in the design and connect it to a pin connected to one of the LEDs, say LED_BLUE.  For example, connect this to P4_0.
2. Place a pin in the design and configure this as general purpose GPIO with strong drive, and name this as the other LED, say LED_RED.  Connect this to another port bit that has the same PWM mapping as the blue LED.   If the blue LED is connected to P4_0, then connect the red LED to P1_0 (or P3_0)
3. In code, to disconnect P4_0 from PWM, write 0000 to bit#0 to bit#3 of HSIOM_PORT_SEL4 register. To connect P1_0 to the PWM, write 1000 to bit#0 to bit#3 of HSIOM_PORT_SEL1

   

Hope this helps.

   

Below are the links to the device data sheet and register TRM for the PRoC BLE.

   

PRoC Data Sheet

   

PRoC Register TRM

0 Likes
Anonymous
Not applicable

Thanks graa 🙂

0 Likes