And voila! As I said in one of the last two posts (Initial post: https://hsel.co.uk/2014/08/14/stm32f0-discovery-board-and-the-hd44780-lcd/ and integrating a charge pump for backlight control: https://hsel.co.uk/2014/08/14/stm32f0-discovery-board-with-hd44780-and-integrated-charge-pump/), I’ve now included a generic LED backlight PWM controller using one of the standard GPIO pins. I’m using GPIOA Pin 6 to drive the LED backlight and I’ve integrated a 4bit (16 step) backlight control within software operating at a PWM frequency of 62.5hz. The PWM counter is implemented within the Systick timer loop, reducing the need for a seperate timer to be enabled, or any specific CC channels used. Theoretically, all the unused pins could be used as PWM outputs, though why you would want to do that, I don’t know! I’d say you could increase the speed at which the PWM runs but this would modify the rate at which the delay function works and that would be undesirable!
Its only a small addition to the code so I’ll merely include pictures. The LED backlight anode is connected to GPIOA pin 6.
As per, my code can be found in my github repository! If you want one of the previous versions that don’t incorporate the charge pump or LED PWM controller, just use a previous commit!
Charge pump revision without LED PWM: 378109c14b9a259af7ceaef686fd9a1379c8e9bb
Initial revision without chargepump or PWM: b2fe4fa1b742f77ba139043f5f21ac2fcf3b5eac