2022-04-14 03:28 AM
In my application I want to use timer to turn on LED for around 300ms and simultaneously generate PWM signal of freq 2.7kHz (for buzzer) on PA10 pin. Is there any way I can achieve this?
(NOTE: I have already used TIM2 and TIM21 timers. TIM21 is also running at the same time as I trun on LED and buzzer)
No matter what configurations I set on channel 1, I always get around 400us wave as shown in screenshot below.
Solved! Go to Solution.
2022-04-14 04:19 AM
You don't need hardware timer for LED blinking - control the LED in software using any timer interrupt routine. SysTick, with default 1 ms period should be a good candidate for this.
2022-04-14 04:19 AM
You don't need hardware timer for LED blinking - control the LED in software using any timer interrupt routine. SysTick, with default 1 ms period should be a good candidate for this.
2022-04-14 05:12 AM
I dont want it running continuously. I'll turn on LED and Buzzer on only when I receive valid data from UART. WIll it be possible to do so using SysTick? If so then can you recommend me some resources for reference?
Thanks & Regards,
SBhon.1
2022-04-14 05:13 AM
I dont want it running continuously. I'll turn on LED and Buzzer on only when I receive valid data from UART. WIll it be possible to do so using SysTick? If so then can you recommend me some resources for reference?
Thanks & Regards,
SBhon.1
2022-04-14 05:59 AM
Like gbm writes. Use timer to generate 2.7kHz for buzzer. And use Systick (like "millis") to turn on and off LED or buzzer (timer).
Of course it is possible to generate periodic 2.7kHz signal by one timer and 300ms pulses by another timer. But you waste timer for simple LED control. Of courste there are ways how to manage both tasks by one timer (enable interrupt from overflow, count interrupts until about 300ms) but they are more complicated then first mentioned way...
2022-04-14 06:13 AM
Thanks for the reply. But I dont want 300ms pulses. My application is access control system. So, only when someone does access, I have to turn on LED and Buzzer for around 300ms indicating access granted. And after 300ms, I have to trun it off and go in low power mode until next access happens. And SysTick gives periodic interrupts. So I wanted to know if I can start SysTick timer when access is done, and after 300ms stop it.
2022-04-14 06:27 AM
You can use another timer in one-shot mode to output a 300ms pulse.
Using SysTick should be straightforward as well. Set the pin high and start a counter. Increment counter in SysTick. When counter reaches 300, set pin low.
2022-04-14 09:46 AM
You can start and stop systick if you need (and systick is disabled in most sleep modes). If you are using CubeMX and HAL, you have probably systick enabled and running with 1ms periodic interrupt...
2022-04-15 02:22 AM
Yes I'm using CubeMX and HAL(I'm using STM32CubeIDE v1.9.0). But I'm not getting any interrupts. HAL_InitTick() returns HAL_OK. I set breakpoint in HAL_SYSTICK_IRQHandler() but I never hit it. Can you tell me if I'm doing something wrong? Is there anything I need to set up? (I'm using the default code generated by CubeMX).
2022-04-16 07:14 AM
Probably systick runs and generate 1ms interrupts and HAL_SYSTICK_IRQHandler() is not placed into systic IRQ routine. Look into SysTick_Handler().