![shequ.stmicroelectronics.cn](./template/st_v1/static/img/logo2.png)
SMT32高精度定时器HRTIM,要配成一路:180的推挽PWM,分别是占空比0-48%,通道A上下互补通道B上下互补共四个脚输出,运行中切换成,配成另一路180的推挽PWM,分别是占空比50-98%,通道A上下互补通道,B通道关闭。现在是能分别配出,但是在切换过中就不对,。是哪里不对,求各位指点。 占空比50-98%通道A上下互补通道,B通道关闭,二个脚输出 以下是占空比0-48%通道A上下互补通道B上下互补共四个脚输出, |
nucleo-l053r8 BOARD NAME修改
IHM08M1一直过流保护
STM32是小端模式,但为什么Keil中memory窗口和反汇编窗口的32位指令不一致?
在使用Motor Pilot_6.3.0,点击Connect不能连接到板子,出现这个问题怎么解决?
MCSDK 直线电机速度控制
LY的SPI PSRAM搭配STM32F0/STM32F1/STM32F2/STM32F3/STM32F4/系列
ST大部分芯片现货有需求可添加联系 VX 一八六六五五一四八二九
STM32F334比较器消隐和HRTIM的事件消隐功能如何实现
MCSDK 位置控制
STM32F334如何实现cycle-by-cycle current control
void HRTIM_Config_Charge(void) { HRTIM_Stop();
HRTIM_OutputCfgTypeDef HRTIM_TIM_OutputStructure; //输出通道置位复位配置 HRTIM_BaseInitTypeDef HRTIM_BaseInitStructure; //定时器参数配置,周期等 HRTIM_TimerInitTypeDef HRTIM_TimerInitStructure; //定时器模式初始化 HRTIM_TimerCfgTypeDef HRTIM_TimerWaveStructure; //输出波形配置 HRTIM_CompareCfgTypeDef HRTIM_CompareStructure; //比较器配置 HRTIM_ADCTriggerCfgTypeDef HRTIM_ADCTrigStructure; //ADC触发设置 // HRTIM_DeadTimeCfgTypeDef HRTIM_TIM_DeadTimeStructure; //死区时间配置 NVIC_InitTypeDef NVIC_InitStructure; //中断服务函数设置 HRTIM_EventCfgTypeDef HRTIM_TIM_EVENT_Structure; HRTIM_TimerEventFilteringCfgTypeDef HRTIM_TimerEventFiltering_Structure;
RCC_HRTIM1CLKConfig(RCC_HRTIM1CLK_PLLCLK); //选择时钟来源72MHZ*2=144MHZ 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); //等待矫正完成
HRTIM_TimerInitStructure.HalfModeEnable = HRTIM_HALFMODE_DISABLED; //HALF用于调频,Duty=50%,不用 HRTIM_TimerInitStructure.StartOnSync = HRTIM_SYNCSTART_DISABLED; //外部同步信号关闭 HRTIM_TimerInitStructure.ResetOnSync = HRTIM_SYNCRESET_DISABLED; //外部同步信号关闭 HRTIM_TimerInitStructure.DACSynchro = HRTIM_DACSYNC_NONE; //不用DAC HRTIM_TimerInitStructure.PreloadEnable = HRTIM_PRELOAD_ENABLED; //预加载使能 HRTIM_TimerInitStructure.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT; //DMA猝发时独立执行 HRTIM_TimerInitStructure.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK; //不使用Burstmode HRTIM_TimerInitStructure.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
HRTIM_BaseInitStructure.Period = PWM_PERIOD; //定义PWM周期,详细见Config.h文件 HRTIM_BaseInitStructure.RepetitionCounter = 1; //多少个周期触发一次中断 HRTIM_BaseInitStructure.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL32; //锁相环144MHZ*32=4.6GHZ////可以调频率 HRTIM_BaseInitStructure.Mode = HRTIM_MODE_CONTINOUS; //循环计数 HRTIM_Waveform_Init(HRTIM1, HRTIM_TIMERINDEX_MASTER, &HRTIM_BaseInitStructure, &HRTIM_TimerInitStructure); HRTIM_Waveform_Init(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, &HRTIM_BaseInitStructure, &HRTIM_TimerInitStructure); HRTIM_Waveform_Init(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, &HRTIM_BaseInitStructure, &HRTIM_TimerInitStructure);
/ ------------------------------------------------ / / TIMERA output and registers update configuration / / ------------------------------------------------ / HRTIM_TimerWaveStructure.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED; //关闭使能死区 HRTIM_TimerWaveStructure.DelayedProtectionMode = HRTIM_TIMDELAYEDPROTECTION_DISABLED;//关闭延时保护模式 HRTIM_TimerWaveStructure.FaultEnable = HRTIM_TIMFAULTENABLE_NONE; //错误保护模式关闭 HRTIM_TimerWaveStructure.FaultLock = HRTIM_TIMFAULTLOCK_READWRITE; //错误锁定功能关闭 HRTIM_TimerWaveStructure.PushPull = HRTIM_TIMPUSHPULLMODE_ENABLED; //推挽模式开启,同步整流BOOST-BUCK要关闭 HRTIM_TimerWaveStructure.ResetTrigger = HRTIM_TIMRESETTRIGGER_MASTER_PER; //主定时器复位时从定时器也复位 HRTIM_TimerWaveStructure.ResetUpdate = HRTIM_TIMUPDATEONRESET_ENABLED; //使能复位更新事件 HRTIM_TimerWaveStructure.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_MASTER; //更新触发源,选择注定是其 HRTIM_WaveformTimerConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, &HRTIM_TimerWaveStructure); HRTIM_WaveformTimerConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, &HRTIM_TimerWaveStructure);
HRTIM_TIM_OutputStructure.Polarity = HRTIM_OUTPUTPOLARITY_HIGH; //高电平设置为正极性 HRTIM_TIM_OutputStructure.SetSource = HRTIM_OUTPUTSET_TIMPER; //计数器回0是输出拉高 HRTIM_TIM_OutputStructure.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1|HRTIM_OUTPUTRESET_EEV_6; //计数到CMP1寄存器值,输出拉低 HRTIM_TIM_OutputStructure.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE; //如果不开启BURST-MODE,这一项建议关闭 HRTIM_TIM_OutputStructure.IdleState = HRTIM_OUTPUTIDLESTATE_INACTIVE; //立即执行,关闭输出 HRTIM_TIM_OutputStructure.FaultState = HRTIM_OUTPUTFAULTSTATE_INACTIVE; //错位u发生时关闭输出,失能 HRTIM_TIM_OutputStructure.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED; //斩波模式关闭 HRTIM_TIM_OutputStructure.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;//选择进入BURST-MODE延时 HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &HRTIM_TIM_OutputStructure); HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB1, &HRTIM_TIM_OutputStructure); HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA2, &HRTIM_TIM_OutputStructure); //开启使能死区此互补脚函数不用 HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB2, &HRTIM_TIM_OutputStructure); //开启使能死区此互补脚函数不用
/ Set compare registers for duty cycle on TA1 / HRTIM_CompareStructure.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; HRTIM_CompareStructure.AutoDelayedTimeout = 0; HRTIM_CompareStructure.CompareValue =100; HRTIM_WaveformCompareConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, &HRTIM_CompareStructure); HRTIM_WaveformCompareConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, &HRTIM_CompareStructure);
HRTIM_TIM_EVENT_Structure.FastMode=HRTIM_EVENTFASTMODE_ENABLE; HRTIM_TIM_EVENT_Structure.Filter=HRTIM_EVENTFILTER_1; HRTIM_TIM_EVENT_Structure.Polarity=HRTIM_EVENTPOLARITY_HIGH; HRTIM_TIM_EVENT_Structure.Sensitivity=HRTIM_EVENTSENSITIVITY_LEVEL; HRTIM_TIM_EVENT_Structure.Source=HRTIM_EVENTSRC_2; HRTIM_EventConfig(HRTIM1, HRTIM_EVENT_6,&HRTIM_TIM_EVENT_Structure);
HRTIM_TimerEventFiltering_Structure.Filter=HRTIM_TIMEVENTFILTER_NONE; HRTIM_TimerEventFiltering_Structure.Latch=HRTIM_TIMEVENTLATCH_DISABLED; HRTIM_TimerEventFilteringConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_EVENT_6,&HRTIM_TimerEventFiltering_Structure); HRTIM_CompareStructure.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; //设置ADC触发模式,立即执行 HRTIM_CompareStructure.AutoDelayedTimeout = 0; //延时为零 HRTIM_CompareStructure.CompareValue = 50; //ADC采样时刻点 HRTIM_WaveformCompareConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_3, &HRTIM_CompareStructure);//设定为比较器3触发ADC // HRTIM_ADCTrigStructure.Trigger = HRTIM_ADCTRIGGEREVENT13_TIMERA_CMP3; //选择触发源 HRTIM_ADCTrigStructure.UpdateSource = HRTIM_ADCTRIGGERUPDATE_TIMER_A; //HRTIMA计数回零时可以更新ADC触发来源 HRTIM_ADCTrigStructure.UpdateSource = HRTIM_ADCTRIGGERUPDATE_TIMER_B; HRTIM_ADCTriggerConfig(HRTIM1, HRTIM_ADCTRIGGER_1, &HRTIM_ADCTrigStructure); //开始配置 //
//非逐周期环路计算时可以采用以下中断,比如设置为2个PWM周期中断一次 / Interrupt initialization / / -------------------------/ NVIC_InitStructure.NVIC_IRQChannel = HRTIM1_TIMA_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); / TIMER A issues an interrupt on each repetition event / HRTIM_ITConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_TIM_IT_REP, ENABLE); / Start HRTIM's TIMER A /
// HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = 22600; //更新HRTIMA(比较寄存器的值)最大42600死区时间800us //// HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = 5000; // // HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_B].CMP1xR = 22600; //更新HRTIMB(比较寄存器的值)最大42600死区时间800us //// HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_B].CMP2xR = 5000;
HRTIM_WaveformCounterStart(HRTIM1, HRTIM_TIMERID_MASTER); //启动定时器 HRTIM_WaveformCounterStart(HRTIM1, HRTIM_TIMERID_TIMER_A); //启动定时器 HRTIM_WaveformCounterStart(HRTIM1, HRTIM_TIMERID_TIMER_B); //启动定时器
Delay_us(100); HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TA1); HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TA2); HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TB1); HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TB2);
}
void HRTIM_Config_Put(void) { HRTIM_Stop();
HRTIM_OutputCfgTypeDef HRTIM_TIM_OutputStructure; //输出通道置位复位配置 HRTIM_BaseInitTypeDef HRTIM_BaseInitStructure; //定时器参数配置,周期等 HRTIM_TimerInitTypeDef HRTIM_TimerInitStructure; //定时器模式初始化 HRTIM_TimerCfgTypeDef HRTIM_TimerWaveStructure; //输出波形配置 HRTIM_CompareCfgTypeDef HRTIM_CompareStructure; //比较器配置 HRTIM_ADCTriggerCfgTypeDef HRTIM_ADCTrigStructure; //ADC触发设置 // HRTIM_DeadTimeCfgTypeDef HRTIM_TIM_DeadTimeStructure; //死区时间配置 NVIC_InitTypeDef NVIC_InitStructure; //中断服务函数设置 HRTIM_EventCfgTypeDef HRTIM_TIM_EVENT_Structure; HRTIM_TimerEventFilteringCfgTypeDef HRTIM_TimerEventFiltering_Structure;
RCC_HRTIM1CLKConfig(RCC_HRTIM1CLK_PLLCLK); //选择时钟来源72MHZ*2=144MHZ 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); //等待矫正完成
HRTIM_TimerInitStructure.HalfModeEnable = HRTIM_HALFMODE_DISABLED; //HALF用于调频,Duty=50%,不用 HRTIM_TimerInitStructure.StartOnSync = HRTIM_SYNCSTART_DISABLED; //外部同步信号关闭 HRTIM_TimerInitStructure.ResetOnSync = HRTIM_SYNCRESET_DISABLED; //外部同步信号关闭 HRTIM_TimerInitStructure.DACSynchro = HRTIM_DACSYNC_NONE; //不用DAC HRTIM_TimerInitStructure.PreloadEnable = HRTIM_PRELOAD_ENABLED; //预加载使能 HRTIM_TimerInitStructure.UpdateGating = HRTIM_UPDATEGATING_INDEPENDENT; //DMA猝发时独立执行 HRTIM_TimerInitStructure.BurstMode = HRTIM_TIMERBURSTMODE_MAINTAINCLOCK; //不使用Burstmode HRTIM_TimerInitStructure.RepetitionUpdate = HRTIM_UPDATEONREPETITION_ENABLED;
HRTIM_BaseInitStructure.Period = PWM_PERIOD; //定义PWM周期,详细见Config.h文件 HRTIM_BaseInitStructure.RepetitionCounter = 1; //多少个周期触发一次中断 HRTIM_BaseInitStructure.PrescalerRatio = HRTIM_PRESCALERRATIO_MUL32; //锁相环144MHZ*32=4.6GHZ////可以调频率 HRTIM_BaseInitStructure.Mode = HRTIM_MODE_CONTINOUS; //循环计数 HRTIM_Waveform_Init(HRTIM1, HRTIM_TIMERINDEX_MASTER, &HRTIM_BaseInitStructure, &HRTIM_TimerInitStructure); HRTIM_Waveform_Init(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, &HRTIM_BaseInitStructure, &HRTIM_TimerInitStructure); HRTIM_Waveform_Init(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, &HRTIM_BaseInitStructure, &HRTIM_TimerInitStructure);
/ ------------------------------------------------ / / TIMERA output and registers update configuration / / ------------------------------------------------ / HRTIM_TimerWaveStructure.DeadTimeInsertion = HRTIM_TIMDEADTIMEINSERTION_DISABLED; //关闭使能死区 HRTIM_TimerWaveStructure.DelayedProtectionMode = HRTIM_TIMDELAYEDPROTECTION_DISABLED;//关闭延时保护模式 HRTIM_TimerWaveStructure.FaultEnable = HRTIM_TIMFAULTENABLE_NONE; //错误保护模式关闭 HRTIM_TimerWaveStructure.FaultLock = HRTIM_TIMFAULTLOCK_READWRITE; //错误锁定功能关闭 HRTIM_TimerWaveStructure.PushPull = HRTIM_TIMPUSHPULLMODE_ENABLED; //推挽模式开启,同步整流BOOST-BUCK要关闭 HRTIM_TimerWaveStructure.ResetTrigger = HRTIM_TIMRESETTRIGGER_MASTER_PER; //主定时器复位时从定时器也复位 HRTIM_TimerWaveStructure.ResetUpdate = HRTIM_TIMUPDATEONRESET_ENABLED; //使能复位更新事件 HRTIM_TimerWaveStructure.UpdateTrigger = HRTIM_TIMUPDATETRIGGER_MASTER; //更新触发源,选择注定是其 HRTIM_WaveformTimerConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, &HRTIM_TimerWaveStructure); HRTIM_WaveformTimerConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, &HRTIM_TimerWaveStructure);
HRTIM_TIM_OutputStructure.Polarity = HRTIM_OUTPUTPOLARITY_LOW; //高电平设置为正极性 HRTIM_TIM_OutputStructure.SetSource = HRTIM_OUTPUTSET_TIMPER; //计数器回0是输出拉高 HRTIM_TIM_OutputStructure.ResetSource = HRTIM_OUTPUTRESET_TIMCMP1|HRTIM_OUTPUTRESET_EEV_6; //计数到CMP1寄存器值,输出拉低 HRTIM_TIM_OutputStructure.IdleMode = HRTIM_OUTPUTIDLEMODE_NONE; //如果不开启BURST-MODE,这一项建议关闭 HRTIM_TIM_OutputStructure.IdleState = HRTIM_OUTPUTIDLESTATE_INACTIVE; //立即执行,关闭输出 HRTIM_TIM_OutputStructure.FaultState = HRTIM_OUTPUTFAULTSTATE_INACTIVE; //错位u发生时关闭输出,失能 HRTIM_TIM_OutputStructure.ChopperModeEnable = HRTIM_OUTPUTCHOPPERMODE_DISABLED; //斩波模式关闭 HRTIM_TIM_OutputStructure.BurstModeEntryDelayed = HRTIM_OUTPUTBURSTMODEENTRY_REGULAR;//选择进入BURST-MODE延时 HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA1, &HRTIM_TIM_OutputStructure); // HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB1, &HRTIM_TIM_OutputStructure); HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_OUTPUT_TA2, &HRTIM_TIM_OutputStructure); //开启使能死区此互补脚函数不用 // HRTIM_WaveformOutputConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_OUTPUT_TB2, &HRTIM_TIM_OutputStructure); //开启使能死区此互补脚函数不用
/ Set compare registers for duty cycle on TA1 / HRTIM_CompareStructure.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; HRTIM_CompareStructure.AutoDelayedTimeout = 0; HRTIM_CompareStructure.CompareValue =100; HRTIM_WaveformCompareConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_1, &HRTIM_CompareStructure); HRTIM_WaveformCompareConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_B, HRTIM_COMPAREUNIT_1, &HRTIM_CompareStructure);
HRTIM_TIM_EVENT_Structure.FastMode=HRTIM_EVENTFASTMODE_ENABLE; HRTIM_TIM_EVENT_Structure.Filter=HRTIM_EVENTFILTER_1; HRTIM_TIM_EVENT_Structure.Polarity=HRTIM_EVENTPOLARITY_HIGH; HRTIM_TIM_EVENT_Structure.Sensitivity=HRTIM_EVENTSENSITIVITY_LEVEL; HRTIM_TIM_EVENT_Structure.Source=HRTIM_EVENTSRC_2; HRTIM_EventConfig(HRTIM1, HRTIM_EVENT_6,&HRTIM_TIM_EVENT_Structure);
HRTIM_TimerEventFiltering_Structure.Filter=HRTIM_TIMEVENTFILTER_NONE; HRTIM_TimerEventFiltering_Structure.Latch=HRTIM_TIMEVENTLATCH_DISABLED; HRTIM_TimerEventFilteringConfig(HRTIM1,HRTIM_TIMERINDEX_TIMER_A,HRTIM_EVENT_6,&HRTIM_TimerEventFiltering_Structure); HRTIM_CompareStructure.AutoDelayedMode = HRTIM_AUTODELAYEDMODE_REGULAR; //设置ADC触发模式,立即执行 HRTIM_CompareStructure.AutoDelayedTimeout = 0; //延时为零 HRTIM_CompareStructure.CompareValue = 50; //ADC采样时刻点 HRTIM_WaveformCompareConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_COMPAREUNIT_3, &HRTIM_CompareStructure);//设定为比较器3触发ADC // HRTIM_ADCTrigStructure.Trigger = HRTIM_ADCTRIGGEREVENT13_TIMERA_CMP3; //选择触发源 HRTIM_ADCTrigStructure.UpdateSource = HRTIM_ADCTRIGGERUPDATE_TIMER_A; //HRTIMA计数回零时可以更新ADC触发来源 HRTIM_ADCTrigStructure.UpdateSource = HRTIM_ADCTRIGGERUPDATE_TIMER_B; HRTIM_ADCTriggerConfig(HRTIM1, HRTIM_ADCTRIGGER_1, &HRTIM_ADCTrigStructure); //开始配置 //
//非逐周期环路计算时可以采用以下中断,比如设置为2个PWM周期中断一次 / Interrupt initialization / / -------------------------/ NVIC_InitStructure.NVIC_IRQChannel = HRTIM1_TIMA_IRQn; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); / TIMER A issues an interrupt on each repetition event / HRTIM_ITConfig(HRTIM1, HRTIM_TIMERINDEX_TIMER_A, HRTIM_TIM_IT_REP, ENABLE); / Start HRTIM's TIMER A /
HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_A].CMP1xR = ThComp; //更新HRTIMA(比较寄存器的值)最大42600死区时间800us //// HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_A].CMP2xR = 5000; // HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_B].CMP1xR = ThComp; //更新HRTIMB(比较寄存器的值)最大42600死区时间800us //// HRTIM1->HRTIM_TIMERx[HRTIM_TIMERINDEX_TIMER_B].CMP2xR = 5000;
HRTIM_WaveformCounterStart(HRTIM1, HRTIM_TIMERID_MASTER); //启动定时器 HRTIM_WaveformCounterStart(HRTIM1, HRTIM_TIMERID_TIMER_A); //启动定时器 HRTIM_WaveformCounterStart(HRTIM1, HRTIM_TIMERID_TIMER_B); //启动定时器
Delay_us(100); HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TA1); HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TA2); // HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TB1); // HRTIM_WaveformOutputStart(HRTIM1,HRTIM_OUTPUT_TB2); }
void HRTIM_Stop(void) { HRTIM_WaveformOutputStop(HRTIM1,HRTIM_OUTPUT_TA1); //关闭定时器1通道A上管引脚 HRTIM_WaveformOutputStop(HRTIM1,HRTIM_OUTPUT_TA2); //关闭定时器1通道A下管引脚 HRTIM_WaveformOutputStop(HRTIM1,HRTIM_OUTPUT_TB1); //关闭定时器1通道B上管引脚 HRTIM_WaveformOutputStop(HRTIM1,HRTIM_OUTPUT_TB2); //关闭定时器1通道B上管引脚 Delay_ms(50); HRTIM_WaveformCounterStop(HRTIM1, HRTIM_TIMERID_MASTER); //关闭定时器 HRTIM_WaveformCounterStop(HRTIM1, HRTIM_TIMERID_TIMER_A); //关闭定时器A HRTIM_WaveformCounterStop(HRTIM1, HRTIM_TIMERID_TIMER_B); //关闭定时器B Delay_ms(100); }
希望中途调整TIMA的PWM输出的占空比,同时关闭TIMB的输出。是这个意思吗?
另外,你目前基于什么时机或事件来做调整切换?