2023-07-12 06:31 AM
Hi, I am trying to generate a PWM signal using HRTIM and DMA in the STM32H745 Nucleo board. However, I am not getting any output. I have verified that the source and destination addresses for the DMA are correct. I think the issue may be with the configuration of the HRTIM or DMA.
I have attached the code and screenshots of configuration that I am using. I would appreciate any help that you can provide.
//==========code ====================//
//====This is the function I am using to generate PWM signal===========//
if(HAL_HRTIM_SimplePWMStart_DMA(&hhrtim, (uint32_t)HRTIM_TIMERINDEX_TIMER_A,(uint32_t)HRTIM_OUTPUT_TA1,(uint32_t)signalValues_src_addr, (uint32_t)signalValues_dst_addr, (uint32_t)NUM_OF_SAMPLES ) == HAL_OK){
}
//============= MX_HRTIM_Init function ======================//
/**
* @brief HRTIM Initialization Function
* @PAram None
* @retval None
*/
static void MX_HRTIM_Init(void)
{
/* USER CODE BEGIN HRTIM_Init 0 */
/* USER CODE END HRTIM_Init 0 */
HRTIM_TimeBaseCfgTypeDef pTimeBaseCfg = {0};
HRTIM_TimerCfgTypeDef pTimerCfg = {0};
HRTIM_DeadTimeCfgTypeDef pDeadTimeCfg = {0};
HRTIM_OutputCfgTypeDef pOutputCfg = {0};
/* USER CODE BEGIN HRTIM_Init 1 */
/* USER CODE END HRTIM_Init 1 */
//======================================================================//
hhrtim.Instance = HRTIM1;
hhrtim.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
hhrtim.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
if (HAL_HRTIM_Init(&hhrtim) != HAL_OK)
{
Error_Handler();
}
//======================================================================//
pTimeBaseCfg.Period = 1600;
pTimeBaseCfg.RepetitionCounter = 0x00;
pTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_DIV1;
pTimeBaseCfg.Mode = HRTIM_MODE_CONTINUOUS;
if (HAL_HRTIM_TimeBaseConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &pTimeBaseCfg) != HAL_OK)
{
Error_Handler();
}
//======================================================================//
pTimerCfg.InterruptRequests = HRTIM_TIM_IT_NONE;
pTimerCfg.DMARequests = HRTIM_TIM_DMA_REP;
pTimerCfg.DMASrcAddress = 0X10000518;
pTimerCfg.DMADstAddress = 0x10005338;
pTimerCfg.DMASize = 5000;
pTimerCfg.HalfModeEnable = HRTIM_HALFMODE_DISABLED;
pTimerCfg.StartOnSync = HRTIM_SYNCSTART_DISABLED;
pTimerCfg.ResetOnSync = HRTIM_SYNCRESET_DISABLED;
pTimerCfg.DACSynchro = HRTIM_DACSYNC_NONE;
pTimerCfg.PreloadEnable = HRTIM_PRELOAD_DISABLED;
pTimerCfg.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT;
pTimerCfg.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK;
pTimerCfg.RepetitionUpdate = HRTIM_UPDATEONREPETITION_DISABLED;
pTimerCfg.PushPull = HRTIM_TIMPUSHPULLMODE_DISABLED;
pTimerCfg.FaultEnable = HRTIM_TIMFAULTENABLE_NONE;
pTimerCfg.FaultLock = HRTIM_TIMFAULTLOCK_READWRITE;
pTimerCfg.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_ENABLED;
pTimerCfg.DelayedProtectionMode = HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_DISABLED;
pTimerCfg.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_NONE;
pTimerCfg.ResetTrigger = HRTIM_TIMRESETTRIGGER_NONE;
pTimerCfg.ResetUpdate = HRTIM_TIMUPDATEONRESET_DISABLED;
if (HAL_HRTIM_WaveformTimerConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &pTimerCfg) != HAL_OK)
{
Error_Handler();
}
//======================================================================//
pDeadTimeCfg.Prescaler = HRTIM_TIMDEADTIME_PRESCALERRATIO_DIV1;
pDeadTimeCfg.RisingValue = 300;
pDeadTimeCfg.RisingSign = HRTIM_TIMDEADTIME_RISINGSIGN_POSITIVE;
pDeadTimeCfg.RisingLock = HRTIM_TIMDEADTIME_RISINGLOCK_WRITE;
pDeadTimeCfg.RisingSignLock = HRTIM_TIMDEADTIME_RISINGSIGNLOCK_WRITE;
pDeadTimeCfg.FallingValue = 300;
pDeadTimeCfg.FallingSign = HRTIM_TIMDEADTIME_FALLINGSIGN_POSITIVE;
pDeadTimeCfg.FallingLock = HRTIM_TIMDEADTIME_FALLINGLOCK_WRITE;
pDeadTimeCfg.FallingSignLock = HRTIM_TIMDEADTIME_FALLINGSIGNLOCK_WRITE;
if (HAL_HRTIM_DeadTimeConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, &pDeadTimeCfg) != HAL_OK)
{
Error_Handler();
}
//======================================================================//
pOutputCfg.Polarity = HRTIM_OUTPUTPOLARITY_HIGH;
pOutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
pOutputCfg.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE;
pOutputCfg.IdleLevel = HRTIM_OUTPUTIDLELEVEL_INACTIVE;
pOutputCfg.FaultLevel = HRTIM_OUTPUTFAULTLEVEL_NONE;
pOutputCfg.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED;
pOutputCfg.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;
if (HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &pOutputCfg) != HAL_OK)
{
Error_Handler();
}
if (HAL_HRTIM_WaveformOutputConfig(&hhrtim, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA2, &pOutputCfg) != HAL_OK)
{
Error_Handler();
}
//======================================================================//
/* USER CODE BEGIN HRTIM_Init 2 */
/* USER CODE END HRTIM_Init 2 */
HAL_HRTIM_MspPostInit(&hhrtim);
}
//======================================//
2023-07-14 06:24 AM
Hello @Pradeep Rajkumar, welcome to ST Community,
Try configuring the SetSource and ResetSource, to determine which event will set or reset your output!
>>pOutputCfg.SetSource = HRTIM_OUTPUTSET_NONE;
pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE;
You can set SetSource to HRTIM_OUTPUT_SET_TIMCMP1 and the ResetSource to HRTIM_OUTPUT_RESET_TIMCMP2 for example, which means, the output will be set when the counter reaches the compare register1, and resets when it reaches the compare register2
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-07-14 10:32 PM - edited 2023-07-14 10:33 PM
Thank you for your reply. Sure I will try your suggestion. In addition to this I think one more mistake is I need to use
if(HAL_HRTIM_WaveformOutputStart(&hhrtim, HRTIM_OUTPUT_TA1)==HAL_OK){
if(HAL_HRTIM_WaveformCountStart_DMA(&hhrtim, HRTIM_TIMERINDEX_TIMER_A) == HAL_OK){
}
}
instead of HAL_HRTIM_SimplePWMStart_DMA() since have configured as Advanced (using HAL_Waveform methods) using function HAL_HRTIM_WaveformOutputConfig().