2025-10-30 6:27 PM
Hello guys,
I have a stm32G474RET board. I am using tim1 in PWM input mode and i want to update on the fly the hrtimA period and compare values using DMA.
This is the code i have written:
// Addresses for HRTIM registers (Timer A)
destPER = (uint16_t*)&HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].PERxR;
destCMP = (uint16_t*)&HRTIM1->sTimerxRegs[HRTIM_TIMERINDEX_TIMER_A].CMP1xR;
// Start DMA transfers in circular mode
HAL_TIM_IC_Start_DMA(&htim1, TIM_CHANNEL_1, destPER, 1);
HAL_TIM_IC_Start_DMA(&htim1, TIM_CHANNEL_2, destCMP, 1);
HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TA1);
HAL_HRTIM_WaveformCounterStart(&hhrtim1, HRTIM_TIMERID_TIMER_A);
HAL_TIM_IC_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_IC_Start(&htim1, TIM_CHANNEL_2);My problem is that the period of the hrtim is changing dynamically based on the input PWM signal, but the CMP1 doesn't. The only thing I could find is that when i tried to configure the channel 2 of timer 1 with DMA the CubeIDE didn't appear the TIM1_CH2 option, so it doen't "export" the value and thus this is the reason that it won't update the CMP1 of hrtimA.
I then tried by configuring the CH1 as direct input/rising edge and CH2 as indirect input/falling edge and while the TIM1_CH1/TIM_CH2 options appeared in the DMA configure tab, the CH2 after all reads the period of the 2 sequential falling edges.
My questions are:
1) Is there a way to manually add to channel2 the DMA configuration while in PWM Input mode?
2) If the (1) isn't possible, can you suggest any good way to sample a PWM signal without the PWM Input mode, but not either using the cpu(meaning to not need to subtract the CH2 - CH1 and then use DMA to update CMP1)?
Please, let me know if I can provide you with more information about my configuration.