2021-01-20 11:58 PM
Hello,
I am working on a STM32F723E-Disco,
I am learning the use of timers and their functionalities.
In particular, I try to use the output compare.
What I'm trying to do is to use the output compare to turn on a LED when the output compare is triggered.
I don't know where to start, I don't see any examples of what I want to do on the internet.
Do you have any examples, help please?
Thanks
2021-01-21 12:40 AM
There are samples included in the firmware. windoes location: %USERPROFILE%\STM32Cube\Repository\STM32Cube_FW_F7_V1.16.0\Projects\STM32F746ZG-Nucleo\Examples\TIM, alsoavail. online. Not precisely for your board, bt close.
hth
KnarfB
2021-01-21 01:51 AM
Be sure to compare the LED current requirement with the limits of the GPIO pin you intend use for driving it.
2021-01-21 11:45 PM
Thanks for your answers.
I looked at the samples provided by STM32, having also STM32F429, I used it for my tests. It helped me a lot, I think I succeeded.
However, I have a second question,
is it possible that when the output compare is triggered, the PIN of the timer of my channel goes directly to the LED?
Because for the moment, I have configured the TIMER channels directly on the LED PIN.
On my STM429, I can't select any timer going to my LED pin (attached image), how can I make the channel timer corresponding to my output compare to be linked to this pin ?
I don't know if you see what I want to do, I hope so.
Thanks you,
2021-01-22 12:20 AM
If you leave the LED pins (PG13 PG14) in the Reset_State (no Output) you may safely connect a wire from the timer channel output pin to the LED pin to make the LED blinking.
If you don't like wires and timing is not very critical, you can enable a timer OC interrupt and toggle the LED from the interrupt handler in software.
Note that OC is only a short pulse (unless you use Toggle on Match mode). You may also look into PWM mode for dimming a LED.
2021-01-22 12:41 AM
To be honest, I don't really like wires.
So if I want to turn on the LED by the software, I put my LED in GPIO_OUTPUT.
Then in my output compare callback function : "HAL_TIM_OC_DelayElapsedCallback", I check if the channel of my timer is equal to HAL_TIM_ACTIVE_CHANNEL_X, if it returns true, it enters my condition and turns on my LED.
That's how I see the program, but this one doesn't work, is there something I didn't understand?
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim){
if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1){
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
}
}
Yes I use the toggle on match mode.
Yes I have already succeeded for dimming a led with the PWM mode.