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, 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.
You are using a very small part with no UDBs. For control register and AND gates you need parts with UDBs.
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.
- 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
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?
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, TCPWM0_P and TCPWM0_P 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.
Thanks graa :)