stm32g474 hrtim-half模式下 始终只能输出一个1脚,2脚没有输出 stm32f334 就没有这个问题static void MX_HRTIM1_Init(void) { /* USER CODE BEGIN HRTIM1_Init 0 */ /* USER CODE END HRTIM1_Init 0 */ HRTIM_TimeBaseCfgTypeDef pTimeBaseCfg = {0}; HRTIM_TimerCfgTypeDef pTimerCfg = {0}; HRTIM_CompareCfgTypeDef pCompareCfg = {0}; HRTIM_TimerCtlTypeDef pTimerCtl = {0}; HRTIM_DeadTimeCfgTypeDef pDeadTimeCfg = {0}; HRTIM_OutputCfgTypeDef pOutputCfg = {0}; /* USER CODE BEGIN HRTIM1_Init 1 */ /* USER CODE END HRTIM1_Init 1 */ hhrtim1.Instance = HRTIM1; hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE; hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE; if (HAL_HRTIM_Init(&hhrtim1) != HAL_OK) { Error_Handler(); } if (HAL_HRTIM_DLLCalibrationStart(&hhrtim1, HRTIM_CALIBRATIONRATE_3) != HAL_OK) { Error_Handler(); } if (HAL_HRTIM_PollForDLLCalibration(&hhrtim1, 10) != HAL_OK) { Error_Handler(); } pTimeBaseCfg.Period = 0xFFDF; pTimeBaseCfg.RepetitionCounter = 0x00; pTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL32; pTimeBaseCfg.Mode = HRTIM_MODE_CONTINUOUS; 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_DISABLED; pTimerCfg.ResetOnSync = HRTIM_SYNCRESET_DISABLED; 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(); } pCompareCfg.CompareValue = 0xFFDF/4; if (HAL_HRTIM_WaveformCompareConfig(&hhrtim1, HRTIM_TIMERINDEX_MASTER, HRTIM_COMPAREUNIT_1, &pCompareCfg) != HAL_OK) { Error_Handler(); } pTimeBaseCfg.Period = 0xFFDF-2; if (HAL_HRTIM_TimeBaseConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, &pTimeBaseCfg) != HAL_OK) { Error_Handler(); } pTimerCtl.UpDownMode = HRTIM_TIMERUPDOWNMODE_UP; pTimerCtl.TrigHalf = HRTIM_TIMERTRIGHALF_DISABLED; pTimerCtl.GreaterCMP1 = HRTIM_TIMERGTCMP1_EQUAL; pTimerCtl.DualChannelDacEnable = HRTIM_TIMER_DCDE_DISABLED; if (HAL_HRTIM_WaveformTimerControl(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, &pTimerCtl) != HAL_OK) { Error_Handler(); } pTimerCfg.InterruptRequests = HRTIM_TIM_IT_NONE; pTimerCfg.DMARequests = HRTIM_TIM_DMA_NONE; pTimerCfg.DMASrcAddress = 0x0000; pTimerCfg.DMADstAddress = 0x0000; pTimerCfg.DMASize = 0x1; pTimerCfg.InterleavedMode = HRTIM_INTERLEAVED_MODE_DUAL; pTimerCfg.PreloadEnable = HRTIM_PRELOAD_DISABLED; pTimerCfg.RepetitionUpdate = HRTIM_UPDATEONREPETITION_DISABLED; pTimerCfg.PushPull = HRTIM_TIMPUSHPULLMODE_DISABLED; pTimerCfg.FaultEnable = HRTIM_TIMFAULTENABLE_NONE; pTimerCfg.FaultLock = HRTIM_TIMFAULTLOCK_READWRITE; pTimerCfg.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED; pTimerCfg.DelayedProtectionMode = HRTIM_TIMER_A_B_C_DELAYEDPROTECTION_DISABLED; pTimerCfg.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_NONE; pTimerCfg.ResetTrigger = HRTIM_TIMRESETTRIGGER_MASTER_PER; pTimerCfg.ResetUpdate = HRTIM_TIMUPDATEONRESET_DISABLED; if (HAL_HRTIM_WaveformTimerConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, &pTimerCfg) != HAL_OK) { Error_Handler(); } pTimerCfg.DMASrcAddress = 0x0000; pTimerCfg.DMADstAddress = 0x0000; pTimerCfg.DMASize = 0x1; pTimerCfg.PreloadEnable = HRTIM_PRELOAD_ENABLED; pTimerCfg.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED; pTimerCfg.ResetTrigger = HRTIM_TIMRESETTRIGGER_MASTER_CMP1; pTimerCfg.ResetUpdate = HRTIM_TIMUPDATEONRESET_ENABLED; if (HAL_HRTIM_WaveformTimerConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_B, &pTimerCfg) != HAL_OK) { Error_Handler(); } pCompareCfg.CompareValue = 0xFFDF; pCompareCfg.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; pCompareCfg.AutoDelayedTimeout = 0x0000; if (HAL_HRTIM_WaveformCompareConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_2, &pCompareCfg) != HAL_OK) { Error_Handler(); } pDeadTimeCfg.Prescaler = HRTIM_TIMDEADTIME_PRESCALERRATIO_DIV1; pDeadTimeCfg.RisingValue = 0x090; pDeadTimeCfg.RisingSign = HRTIM_TIMDEADTIME_RISINGSIGN_NEGATIVE; pDeadTimeCfg.RisingLock = HRTIM_TIMDEADTIME_RISINGLOCK_WRITE; pDeadTimeCfg.RisingSignLock = HRTIM_TIMDEADTIME_RISINGSIGNLOCK_WRITE; pDeadTimeCfg.FallingValue = 0x090; pDeadTimeCfg.FallingSign = HRTIM_TIMDEADTIME_FALLINGSIGN_NEGATIVE; pDeadTimeCfg.FallingLock = HRTIM_TIMDEADTIME_FALLINGLOCK_WRITE; pDeadTimeCfg.FallingSignLock = HRTIM_TIMDEADTIME_FALLINGSIGNLOCK_WRITE; if (HAL_HRTIM_DeadTimeConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, &pDeadTimeCfg) != HAL_OK) { Error_Handler(); } pOutputCfg.Polarity = HRTIM_OUTPUTPOLARITY_HIGH; pOutputCfg.SetSource = HRTIM_OUTPUTSET_TIMCMP1; pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_MASTERPER; 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(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &pOutputCfg) != HAL_OK) { Error_Handler(); } pOutputCfg.SetSource = HRTIM_OUTPUTSET_TIMPER; pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1; if (HAL_HRTIM_WaveformOutputConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB1, &pOutputCfg) != HAL_OK) { Error_Handler(); } pOutputCfg.SetSource = HRTIM_OUTPUTSET_NONE; pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_NONE; if (HAL_HRTIM_WaveformOutputConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA2, &pOutputCfg) != HAL_OK) { Error_Handler(); } if (HAL_HRTIM_WaveformOutputConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB2, &pOutputCfg) != HAL_OK) { Error_Handler(); } if (HAL_HRTIM_TimeBaseConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_B, &pTimeBaseCfg) != HAL_OK) { Error_Handler(); } if (HAL_HRTIM_WaveformTimerControl(&hhrtim1, HRTIM_TIMERINDEX_TIMER_B, &pTimerCtl) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN HRTIM1_Init 2 */ /* USER CODE END HRTIM1_Init 2 */ HAL_HRTIM_MspPostInit(&hhrtim1); } |
foc电流环无法正确维持Iq在自己设定的数值。
ADC各个通道转换
STM32G431 用MCSDK5.4.8 进行PMSM永磁同步电机FOC控制,转速上升到某一值(3500rpm)无法继续上升,上不去
STM32G431KBU3 只要开中断HAL_xxxx_Start_IT()就死机一动不动
STM32G474HRTIM中断跳到硬件错误中断问题
F302R8电机驱动三角函数为什么用定点查表方式
免费试用|领取你的STM32G491,完成你的开发计划
stm32G431 用DWT外设用来计时,DWT->CYCCNT的值一直固定不变,程序里面都使能了。还有别的寄存器要打开吗?
基于GCC编译器的initcall在STM32如何实现?
想找一款pin to pin的MCU(参考STM32F105RC),支持CAN FD的,64PIN封装,各位小伙伴们有推荐吗
刚开始怀疑是库驱动方面的问题搞错方向而 耽误了点时间,后来发现 还是我用户代码方面有些问题。
我这里使用的TIMA的两路输出。用户代码如下:
HAL_HRTIM_WaveformCountStart(&hhrtim1, HRTIM_TIMERID_TIMER_A);
HAL_HRTIM_WaveformOutputStart(&hhrtim1 , HRTIM_OUTPUT_TA1);
HAL_HRTIM_WaveformOutputStart(&hhrtim1 , HRTIM_OUTPUT_TA2);
最终结构就是两路50%占空比的pwm输出,至于同相还是反相我们可以自住设定。
有关CubeMx的配置我会单独附件出来供参考。