STM32F334,用的cubeMX设置,如图:使用timer E, PC8,PC9输出,使用外部时钟,HRTIM 144M, |
F302R8电机驱动三角函数为什么用定点查表方式
基于GCC编译器的initcall在STM32如何实现?
想找一款pin to pin的MCU(参考STM32F105RC),支持CAN FD的,64PIN封装,各位小伙伴们有推荐吗
DSMPS 3kW - LLC STM32F334x 源码资源在哪里可以下载到?
STM32F373的PGA(SDADC前置)怎么校正
请问STM32F373的内部基准为什么不准确?
stm32f373中SDADC和ADC的1.2V片内基准是不是同一个?
STM32F373的VREFINT是指什么?含义混乱
nucleo-l053r8 BOARD NAME修改
IHM08M1一直过流保护
HTIM我也没玩过。
其实你要输出PWM直接用定时器TIMx就很方便,为何要用HRTIM?
搬运工,搬运一个网上下载的代码,不知道能用否:
评分
查看全部评分
static void MX_HRTIM1_Init(void)
{
HRTIM_TimeBaseCfgTypeDef pTimeBaseCfg;
HRTIM_TimerCfgTypeDef pTimerCfg;
HRTIM_CompareCfgTypeDef pCompareCfg;
HRTIM_OutputCfgTypeDef pOutputCfg;
hhrtim1.Instance = HRTIM1;
hhrtim1.Init.HRTIMInterruptResquests = HRTIM_IT_NONE;
hhrtim1.Init.SyncOptions = HRTIM_SYNCOPTION_NONE;
if (HAL_HRTIM_Init(&hhrtim1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_HRTIM_DLLCalibrationStart(&hhrtim1, HRTIM_CALIBRATIONRATE_14) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_HRTIM_PollForDLLCalibration(&hhrtim1, 10) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
pTimeBaseCfg.Period = 30000;
pTimeBaseCfg.RepetitionCounter = 0x00;
pTimeBaseCfg.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL32;
pTimeBaseCfg.Mode = HRTIM_MODE_CONTINUOUS;
if (HAL_HRTIM_TimeBaseConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_E, &pTimeBaseCfg) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
pTimerCfg.InterruptRequests = HRTIM_MASTER_IT_NONE;
pTimerCfg.DMARequests = HRTIM_TIM_DMA_NONE;
pTimerCfg.DMASrcAddress = 0x0000;
pTimerCfg.DMADstAddress = 0x0000;
pTimerCfg.DMASize = 0x1;
pTimerCfg.HalfModeEnable = HRTIM_HALFMODE_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_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_D_E_DELAYEDPROTECTION_DISABLED;
pTimerCfg.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_NONE;
pTimerCfg.ResetTrigger = HRTIM_TIMRESETTRIGGER_UPDATE;
pTimerCfg.ResetUpdate = HRTIM_TIMUPDATEONRESET_ENABLED;
if (HAL_HRTIM_WaveformTimerConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_E, &pTimerCfg) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
pCompareCfg.CompareValue = 15000;
if (HAL_HRTIM_WaveformCompareConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_E, HRTIM_COMPAREUNIT_1, &pCompareCfg) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
pOutputCfg.Polarity = HRTIM_OUTPUTPOLARITY_LOW;
pOutputCfg.SetSource = HRTIM_OUTPUTSET_TIMPER;
pOutputCfg.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1;
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_E, HRTIM_OUTPUT_TE1, &pOutputCfg) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
if (HAL_HRTIM_WaveformOutputConfig(&hhrtim1, HRTIM_TIMERINDEX_TIMER_E, HRTIM_OUTPUT_TE2, &pOutputCfg) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
HAL_HRTIM_MspPostInit(&hhrtim1);
}
谢谢前辈的回复,但是还是不行,我找到库里函数的原型,应该是:
HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TE1);
HAL_HRTIM_WaveformOutputStart(&hhrtim1, HRTIM_OUTPUT_TE1);
加上这两个函数后还是没有反应,我又写了个函数使能timer E
void timerE_enable(void) //使能timer E
{
HRTIM_Master_TypeDef pmaster;
pmaster.MCR= HRTIM_TIMERID_TIMER_E;
}
在主函数里面调用,还是没有反应,能不能再帮忙给看看,尤其是CUBEMX里面HRTIM的设置界面里面有没有参数选择的不对?谢谢!已经弄了一整天了
烧录后PC8,PC9始终没有输出,调试了一整天,没有任何头绪,希望用过的高手能帮忙给看看问题出在哪儿,非常感谢
好像少了输出使能:
HAL_HRTIM_WaveformOutputStart(&hhrtim1, ENABLE);
评分
查看全部评分
HRTIM_OutputCfgTypeDef HRTIM_TIM_OutputStructure;//配置输出特性,高低电平等
HRTIM_BaseInitTypeDef HRTIM_BaseInitStructure;//配置基本参数,这部分和普通定时器一样
HRTIM_TimerInitTypeDef HRTIM_TimerInitStructure; //配置不同模式
HRTIM_TimerCfgTypeDef HRTIM_TimerWaveStructure;//配置波形参数,错误等
HRTIM_CompareCfgTypeDef HRTIM_CompareStructure;//配置比较寄存器
用以上几个部分就能产生最简单的PWM波形
评分
查看全部评分
暂时没有找到HAL库的例子,管脚配置我找不出毛病来,
因为HRTIM功能比较强大,向后面熟悉了做数字电源用,程序我试一下,谢谢
评分
查看全部评分
谢谢!你说的有道理,我觉得还是回到根本,重新再看一遍寄存器
/* TD1 output toggles at ~430kHz (this frequency can vary depending on compiler and optimizations options) */
HAL_HRTIM_WaveformSetOutputLevel(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD1, HRTIM_OUTPUTLEVEL_ACTIVE);
HAL_HRTIM_WaveformSetOutputLevel(&hhrtim, HRTIM_TIMERINDEX_TIMER_D, HRTIM_OUTPUT_TD1, HRTIM_OUTPUTLEVEL_INACTIVE);
评分
查看全部评分
好的,我试一下,谢谢!
1.检查GPIO是否设为复用模式,复用序号对不对
2.检查ONER,ODSR是否设为正常输出状态
3.检查SET和RST寄存器选择的置位和复位信号
4.观察CNT确定计数器在运行
评分
查看全部评分
这个函数调用之后确实开始有输出了,但是这个函数的作用很奇怪,我暂时没弄清楚他的作用,感觉不应该用在这里