2025-12-01 6:43 AM - last edited on 2025-12-02 10:08 AM by Imen.D
Hi everyone,
I am working on an STM32G4 project using the HRTIM1 peripheral.
My goal is to generate a burst of exactly 3 PWM pulses on Timer A and Timer B simultaneously, triggered by an External Event (Sync Input / EEV).
The Goal:
System waits for an external trigger (e.g., from TIM3 via TRGO or physical pin).
Upon trigger, HRTIM Timer A and Timer B start.
They output exactly 3 PWM cycles.
They stop and wait for the next trigger (Single-Shot Retriggerable).
The Configuration:
I am using STM32CubeIDE and HAL, but I also tried direct register access.
Master Timer: Acts as a dummy/pass-through for synchronization.
Timer A & B:
Mode: Single-Shot Retriggerable.
Prescaler: Div1.
Period: 1000 ticks.
Repetition Counter: 2 (Targeting $N+1 = 3$ pulses).
Start on Sync: Enabled.
Reset on Sync: Enabled.
Preload Enable: Disabled (To force immediate register update).
The Problem:
Despite setting REPxR = 2, I consistently see only 1 pulse on the scope when the trigger arrives. It seems the timer resets and starts, but the Repetition Counter value is ignored or treated as 0 for the first run.
Any help will be appreciated
Thank you
2025-12-02 10:06 AM - edited 2025-12-02 10:06 AM
Hello @GiovanniL
Did you set the repetition counter before enabling the timer?
After configuring the HRTIM and before enabling it or waiting for the external trigger, generate an update event to ensure the repetition counter is loaded.
Check the repetition counter value during operation through the HRTIM debug registers.
STM32G4-WDG_TIMERS-High_Resolution_Timer_HRTIM.pdf
AN4539 HRTIM cookbook - Application note
2025-12-04 5:22 AM
Hi, i managed to achieve 2 pulses!
Now i set TIMA and TIMB as continuos with long period, and i'm trying to reset them with the master at each master period.
The problem is that my master resets TIMER A and TIMER B just after the first period. It looks like it does not take the update of the preload at each sync (i receive it from a pulse by TIM3). Should i force the preload by software each time? it seems crazy to me.
Here you can find my master configuration and my scope results where you can see the two pulses and the third due to the period repetition. That third pulse is not wanted but not a problem, i just want 5 pulses like the first two.
pTimeBaseCfg.Period = 2000;
pTimeBaseCfg.RepetitionCounter = 0x04;
pTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV1;
pTimeBaseCfg.Mode = HRTIM_MODE_SINGLESHOT;
if (HAL_HRTIM_TimeBaseConfig(&hhrtim1, HRTIM_TIMERINDEX_MASTER, &pTimeBaseCfg) != HAL_OK)
{
Error_Handler();
}
pTimerCfg.InterruptRequests = HRTIM_MASTER_IT_NONE;
pTimerCfg.DMARequests = HRTIM_MASTER_DMA_NONE;
pTimerCfg.DMASrcAddress = 0x0000;
pTimerCfg.DMADstAddress = 0x0000;
pTimerCfg.DMASize = 0x1;
pTimerCfg.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
pTimerCfg.InterleavedMode = HRTIM_INTERLEAVED_MODE_DISABLED;
pTimerCfg.StartOnSync = HRTIM_SYNCSTART_ENABLED;
pTimerCfg.ResetOnSync = HRTIM_SYNCRESET_ENABLED;
pTimerCfg.DACSynchro = HRTIM_DACSYNC_NONE;
pTimerCfg.PreloadEnable = HRTIM_PRELOAD_ENABLED;
pTimerCfg.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
pTimerCfg.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
pTimerCfg.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
pTimerCfg.ReSyncUpdate = HRTIM_TIMERESYNC_UPDATE_UNCONDITIONAL;
if (HAL_HRTIM_WaveformTimerConfig(&hhrtim1, HRTIM_TIMERINDEX_MASTER, &pTimerCfg) != HAL_OK)
{
Error_Handler();
}