How do I configure GPIO pin (PE8 )as PWM output to control LED Brightness.
I am a newbie and trying to make my hands dirty in STM32l476 Discovery board.
I am trying to control the brightness of an LED which is connected onboard at GPIO PIN PE8.
The TIMER on this pin is TIM1 CH1N.
What I have tried is till now is below. I would request someone to please go through and correct where I am wrong.
STEP1: Setting the GPIO PIN PE8 to TIM1CH1N functionality.
STEP2: Clock Configuration is set to 40MHz.
STEP3: TIMER mode and configurations as below.
Clock Source - Internal Clock Source.
Channel 1 - PWM GENERATION CH1N
STEP4: Counter Settings as below.
Prescaler Value - 40000 (To make clock as 1000 Hz)
Counter Period (ARR) - 100 -1 (Max limit in one second)
Now in programming part.
I am starting the timer with the by calling below API.
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1);
Now in the while loop i wanted to change brightness of an LED.
while(1)
{
htim1.Instance-> CCR1 = 50; // For 50% brightness on PE8 LED//
HAL_Dealy(1000);
htim1.Instance->CCR1 = 100; // FOR 100% brightness on PE8 LED//
HAL_Dealy(1000);
}
I would once again request someone to guide me and let me understand this topic with detailed explanation.
Thanks in Advance! and Looking forward to hear from someone.