帮忙分析下334配置问题:
TA1输出:MASTER周期下置位,MASTER_CMP1下复位; TA2输出:TIMER_A周期下置位,TIMER_A_CMP1下复位; 其中MASTER_CMP2下触发TIMER_A(MASTER_CMP2=Period/2), 逻辑如图: 问题:PWM占空比恰好在50%附近的时候,TA2输出的占空比不稳定,瞬间发生突变,忽大忽小,TA1的输出一直正常,规律是,master_CMP2触发timer_a,把master_CMP2设置到多少,TA2输出的PWM在其对应的占空比附近就会发生突变 怀疑是MASTER_CMP2下触发TIMER_A的这部分配置问题,导致TIMER_A计数出现BUG,但是一直没有找到问题在哪里,帮忙指点一下,不胜感激! 以下是:程序配置部分 /************************************************************************************************************************ * 模块名称 : 高分辨率定时器模块 * 文件名称 : bsp_hrtim.c * 说 明 : 高分辨率定时器HRTIM1产生2路PWM输出 * 硬件连接 :PA8 - HRTIM1_CHA1 * PA9 - HRTIM1_CHA2 * * Copyright (C), 2015-2100,Tommy Guo ************************************************************************************************************************/ #include "bsp.h" #include "param.h" #include "bms.h" /*=====================================================================================================================*/ uint32_t BUCK_PWM_PERIOD; /* PWM时钟计数周期值 */ /*=====================================================================================================================*/ /************************************************************************************************************************ * 函数名:bsp_InitHRTIM * 描 述:HRTIM1初始化 * 输 入: pwm_period - PWM时钟计数周期值(PWM分辨率) * 输 出:无 * 调 用:内部调用 ************************************************************************************************************************/ void bsp_InitHRTIM(uint32_t pwm_period) { GPIO_InitTypeDef GPIO_InitStructure; HRTIM_BaseInitTypeDef HRTIM_BaseInitStructure; HRTIM_TimerCfgTypeDef HRTIM_TimerWaveStructure; HRTIM_TimerInitTypeDef HRTIM_TimerInitStructure; HRTIM_OutputCfgTypeDef HRTIM_OutputStructure; HRTIM_CompareCfgTypeDef HRTIM_CompareStructure; HRTIM_ADCTriggerCfgTypeDef HRTIM_ADCTrigStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA,GPIO_PinSource8,GPIO_AF_13); GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_13); /* HRTIM全局初始化 */ RCC_HRTIM1CLKConfig(RCC_HRTIM1CLK_PLLCLK); RCC_APB2PeriphClockCmd(RCC_APB2Periph_HRTIM1,ENABLE); HRTIM_DLLCalibrationStart(HRTIM1,HRTIM_CALIBRATIONRATE_14); HRTIM1_COMMON->DLLCR |= HRTIM_DLLCR_CALEN; while(HRTIM_GetCommonFlagStatus(HRTIM1,HRTIM_ISR_DLLRDY) == RESET); /* MASTER定时器工作模式和PWM频率配置 */ HRTIM_BaseInitStructure.Period = (uint32_t)(1152e6 / pwm_period); HRTIM_BaseInitStructure.RepetitionCounter = 0; /* n+1个PWM周期发生1次中断 */ HRTIM_BaseInitStructure.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL8; /* 8倍频到1152MHz */ HRTIM_BaseInitStructure.Mode = HRTIM_MODE_CONTINOUS; HRTIM_TimerInitStructure.HalfModeEnable = HRTIM_HALFMODE_DISABLED; HRTIM_TimerInitStructure.StartOnSync = HRTIM_SYNCSTART_DISABLED; HRTIM_TimerInitStructure.ResetOnSync = HRTIM_SYNCRESET_DISABLED; HRTIM_TimerInitStructure.DACSynchro = HRTIM_DACSYNC_NONE; HRTIM_TimerInitStructure.PreloadEnable = HRTIM_PRELOAD_ENABLED; /* 预加载使能 */ HRTIM_TimerInitStructure.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT; HRTIM_TimerInitStructure.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK; HRTIM_TimerInitStructure.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED; /* 使能 */ HRTIM_Waveform_Init(HRTIM1,HRTIM_TIMERINDEX_MASTER,&HRTIM_BaseInitStructure,&HRTIM_TimerInitStructure); /* TIMER_A定时器工作模式和PWM频率配置 */ HRTIM_BaseInitStructure.Period = (uint32_t)(1152e6 / pwm_period); HRTIM_BaseInitStructure.RepetitionCounter = 0; /* n+1个PWM周期发生1次中断 */ HRTIM_BaseInitStructure.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL8; /* 8倍频到1152MHz */ HRTIM_BaseInitStructure.Mode = HRTIM_MODE_SINGLESHOT; HRTIM_TimerInitStructure.RepetitionUpdate = HRTIM_UPDATEONREPETITION_DISABLED; /* 禁止 */ HRTIM_Waveform_Init(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,&HRTIM_BaseInitStructure,&HRTIM_TimerInitStructure); /* TIMER_A定时器输出及寄存器更新配置 */ HRTIM_TimerWaveStructure.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED; /* CH1和CH2信号独立*/ HRTIM_TimerWaveStructure.DelayedProtectionMode = HRTIM_TIMDELAYEDPROTECTION_DISABLED; /* 延时保护:无 */ HRTIM_TimerWaveStructure.FaultEnable = HRTIM_TIMFAULTENABLE_NONE; /* 故障位:可读写 */ HRTIM_TimerWaveStructure.FaultLock = HRTIM_TIMFAULTLOCK_READONLY; HRTIM_TimerWaveStructure.PushPull = HRTIM_TIMPUSHPULLMODE_DISABLED; //指定触发定时器复位的源 HRTIM_TimerWaveStructure.ResetTrigger = HRTIM_TIMRESETTRIGGER_MASTER_CMP2; /* MASTER_CMP2下触发TIMER_A */ //指定定时器计数器复位时是否触发寄存器更新 HRTIM_TimerWaveStructure.ResetUpdate = HRTIM_TIMUPDATEONRESET_DISABLED;//DISABLED //指定触发定时器的寄存器更新的源 HRTIM_TimerWaveStructure.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_MASTER; /* MASTER更新TIMER_A */ HRTIM_WaveformTimerConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,&HRTIM_TimerWaveStructure); /* TA1输出配置 */ HRTIM_OutputStructure.Polarity = HRTIM_OUTPUTPOLARITY_HIGH; /* 极性控制,正极性 */ HRTIM_OutputStructure.SetSource = HRTIM_OUTPUTSET_MASTERPER; /* MASTER周期下置位 */ HRTIM_OutputStructure.ResetSource = HRTIM_OUTPUTRESET_MASTERCMP1; /* MASTER_CMP1下复位 */ HRTIM_OutputStructure.IdleMode = HRTIM_OUTPUTIDLEMODE_IDLE; /* 输出不受空闲状态影响 */ HRTIM_OutputStructure.IdleState = HRTIM_OUTPUTIDLESTATE_INACTIVE; HRTIM_OutputStructure.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE; /* 输出不受故障影响 */ HRTIM_OutputStructure.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED; /* 不使用斩波器 */ HRTIM_OutputStructure.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR; /* 死区时间不插入空闲状态 */ HRTIM_WaveformOutputConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_OUTPUT_TA1,&HRTIM_OutputStructure); /* TA2输出配置 */ HRTIM_OutputStructure.Polarity = HRTIM_OUTPUTPOLARITY_HIGH; /* 极性控制,正极性 */ HRTIM_OutputStructure.SetSource = HRTIM_OUTPUTSET_TIMPER; /* TIMER_A周期下置位 */ HRTIM_OutputStructure.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1; /* TIMER_A_CMP1下复位 */ HRTIM_OutputStructure.IdleMode = HRTIM_OUTPUTIDLEMODE_IDLE; /* 输出不受空闲状态影响 */ HRTIM_OutputStructure.IdleState = HRTIM_OUTPUTIDLESTATE_INACTIVE; HRTIM_OutputStructure.FaultState = HRTIM_OUTPUTFAULTSTATE_NONE; /* 输出不受故障影响 */ HRTIM_OutputStructure.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED; /* 不使用斩波器 */ HRTIM_OutputStructure.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR; /* 死区时间不插入空闲状态 */ HRTIM_WaveformOutputConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_OUTPUT_TA2,&HRTIM_OutputStructure); /* MASTER_CMP1、MASTER_CMP2赋初值 */ HRTIM_MasterSetCompare(HRTIM1,HRTIM_COMPAREUNIT_1,HRTIM_BaseInitStructure.Period*0.05); HRTIM_MasterSetCompare(HRTIM1,HRTIM_COMPAREUNIT_2,HRTIM_BaseInitStructure.Period*0.50); /* TIMER_A_CMP1赋初值 */ HRTIM_CompareStructure.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; HRTIM_CompareStructure.AutoDelayedTimeout = 0; HRTIM_CompareStructure.CompareValue = HRTIM_BaseInitStructure.Period*0.05; HRTIM_WaveformCompareConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_COMPAREUNIT_1,&HRTIM_CompareStructure); /* ADC触发初始化 */ HRTIM_CompareStructure.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; HRTIM_CompareStructure.AutoDelayedTimeout = 0; HRTIM_CompareStructure.CompareValue = HRTIM_BaseInitStructure.Period*0.50; /* TIMER_A_CMP2初值 */ HRTIM_WaveformCompareConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_2,&HRTIM_CompareStructure); HRTIM_ADCTrigStructure.Trigger = HRTIM_ADCTRIGGEREVENT13_TIMERA_CMP2; HRTIM_ADCTrigStructure.UpdateSource = HRTIM_ADCTRIGGERUPDATE_TIMER_A; HRTIM_ADCTriggerConfig(HRTIM1,HRTIM_ADCTRIGGER_1,&HRTIM_ADCTrigStructure); /* HRTIM1_TIMA中断初始化 */ NVIC_InitStructure.NVIC_IRQChannel = HRTIM1_TIMA_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); HRTIM_ITConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_TIM_IT_REP,ENABLE); HRTIM_WaveformCounterStart(HRTIM1,HRTIM_TIMERID_TIMER_A); /* 启动TIMER_A */ HRTIM_WaveformCounterStart(HRTIM1,HRTIM_TIMERID_MASTER); /* 启动MASTER */ BUCK_PWM_PERIOD = HRTIM_BaseInitStructure.Period; HRTIM_OutputStop(); } /*=====================================================================================================================*/ /************************************************************************************************************************ * 函数名:HRTIM_OutputStop * 描 述:停止输出PWM * 输 入: 无 * 输 出:无 * 调 用:外部调用 ************************************************************************************************************************/ void HRTIM_OutputStop(void) { HRTIM_WaveformOutputStop(HRTIM1,HRTIM_OUTPUT_TA1); /* 停止TA1输出PWM */ HRTIM_WaveformOutputStop(HRTIM1,HRTIM_OUTPUT_TA2); /* 停止TA2输出PWM */ } /*=====================================================================================================================*/ /************************************************************************************************************************ * 函数名:HRTIM_OutputStart * 描 述:启动输出PWM * 输 入: 无 * 输 出:无 * 调 用:外部调用 ************************************************************************************************************************/ void HRTIM_OutputStart(void) { HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TA1); /* 启动TA1输出PWM */ HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TA2); /* 启动TA2输出PWM */ } /*=====================================================================================================================*/ /************************************************************************************************************************ * 函数名:PWM_Update * 描 述:PWM占空比更新 * 输 入: CompareValue->占空比 * 输 出:无 * 调 用:内部调用 ************************************************************************************************************************/ void PWM_Update(uint32_t CompareValue) { /* 更新MASTER_CMP1,TA1输出 */ HRTIM_MasterSetCompare(HRTIM1,HRTIM_COMPAREUNIT_1,CompareValue); /* 更新TIMA_CMP1,TA2输出 */ HRTIM_SlaveSetCompare(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_COMPAREUNIT_1,CompareValue); /* 更新TIMA_CMP2,在TA2的PWM中点触发ADC */ HRTIM_SlaveSetCompare(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_COMPAREUNIT_2,CompareValue*0.5); } /*=====================================================================================================================*/ /************************************************************************************************************************ * 函数名:bsp_InitPWM * 描 述:初始化PEM,包含MPPT初始参数、PID初始参数 * 输 入: 无 * 输 出:无 * 调 用:外部调用 ************************************************************************************************************************/ void bsp_InitPWM(void) { bsp_InitHRTIM(PWM_FREQUENCY); /* PWM开关频率 */ MPPT_PNO_Init(&PNO); /* 扰动法MPPT参数初始化 */ MPPT_INCC_Init(&INCC); /* 增量电导法MPPT参数初始化 */ PID_Init(); /* PID参数初始化 */ } /*=====================================================================================================================*/ /************************************************************************************************************************ * 函数名:HRTIM1_TIMA_IRQHandler * 描 述:HRTIM1_TIMA中断服务程序,50us * 输 入: 无 * 输 出:无 * 调 用:无 ************************************************************************************************************************/ void HRTIM1_TIMA_IRQHandler(void) { if (HRTIM_GetITStatus(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_TIM_FLAG_REP) != RESET) { BUCK_Scan(); /* 运行BUCK */ HRTIM_ClearITPendingBit(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_TIM_FLAG_REP); } } /*=====================================================END OF FILE=====================================================*/ |
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一直过流保护
这边用相应的电路板做了验证,TA2输出没有碰到你所反馈的占空比50%左右时波形剧烈抖动的情形。
另外,从你的视频来看,感觉比较器的值被修改了。
你再检查确认下代码?是否别的地方影响到了芯片工作? TA2有接到外部电路吗?
评分
查看全部评分
是的,像是比较器的值被突然改动了一下,TA1和TA2接的是IGBT驱动,改了很多地方的还是没有解决,实在没有办法现已经不用HRTIM了,这两个IO口正好也是TIM1的通道输出,就改用了TIM1,目前各功能测试正常,说明硬件没有问题,还是HRTIM的使用有隐含问题没有找出来。