Skip to main content
cl.1_99
Associate II
March 17, 2020
Question

I am wondering how to use PWM to adjust colours for an RGB LED if the LED is already set as a GPIO_Output? (so I cannot also set them as a timer(s)).

Hi all, I am currently writing a program that uses the STM32L432KC board (nucleol432kc) and a thermistor to obtain a temperature and then display that temperature on an LCD, a terminal screen, as well as turn an RGB LED on with different temperature ranges corresponding to different colours (ex. temp lower than 20 degrees C, blue led on...etc) Each component is currently working perfectly, the only extra thing I cannot figure out is how I can use PWM (and how to set up the configuration for it) to change the colours to different mixes of RGB. I have each leg of the RGB LED set as GPIO_Outputs, but I do not know what pin I should be setting as a timer if I want to use the PWM. I am using STM32CubeIde.

I have attached the current configuration for my board, which does work perfectly fine (so ideally I wouldn't want to make any huge changes, mostly because whenever I do it gets rid of all of my code and even when I copy and paste it back there's usually some errors). All I want to be able to do is adjust the colour mixing of the RGB LED in a way that looks like (255, 0, 0) for red, (0, 255, 0) for green... etc.

Note* the only configuration requirements are:

PA8 is red

PA9 is green

PA10 is blue

PA1 is for ADC of thermistor voltage

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
March 17, 2020

Use whatever timer channels that are on PA8 to PA10.

If there are none, you can still bit-bang the PWM e.g. in a timer interrupt if you don't mind the processor load this implies. A better solution is a timer-triggered DMA transferring the required pattern from memory to GPIOA_BSRR.

JW

cl.1_99
cl.1_99Author
Associate II
March 18, 2020

Thanks for the reply! I am not sure how to do the latter of your suggestions, but for using the timer channels on PA8-PA10, the only one that is available is for PA8 and it is PWM Generation CH1N (all other options have conflicts), PA9 and PA10 only have PWM Generation No Output. Do you have any suggestions as to what they should be set to and/or how to physically code or what functions to use to actually set the colour mixes?