本帖最后由 zjh20070904 于 2022-6-18 10:19 编辑
1 概述高级定时器有个死区控制功能,依据手册配置想要的死区时间时比较麻烦,于是依据手册自己总结了配置死区时间的计算方法。
2 计配置DTS寄存器的计算方法2.1 关键寄存器描述
2.2 计算方法(1)依据死区时间确定范围 对于CLKDIV配置为00、TMR1的时钟分别为8M、72MHz时,对应的死区配置范围是:
其中TDTS=CKD/TMR1_CLK
(2)依据死区时间范围代入对应的公式计算要配置的寄存器数值
3 应用案例代码中的时钟关系如下 (1)系统时钟为72MHz; (2)APB2的时钟未分频即72MHz; (3)TMR1挂接在APB2总线上,且时钟分频系数CLKDIV为00,因此TMR1的时钟为72MHz (4)CLKDIV默认配置为:00
3.1 TMR1_BDT_ConfigStruc.deadTime=36
3.2 TMR1_BDT_ConfigStruc.deadTime=(72+128-64)
3.3 TMR1_BDT_ConfigStruc.deadTime=(36+192-32)
3.4 TMR1_BDT_ConfigStruc.deadTime=(36+224-32)
3.5 CLKDIV对死区的影响
4 应用案例代码int main(void)
{
GPIO_Config_T GPIO_ConfigStruct;
TMR_BaseConfig_T TMR_TimeBaseStruct;
TMR_OCConfig_T OCcongigStruct;
TMR_BDTConfig_T TMR1_BDT_ConfigStruc;
RCM_EnableAPB2PeriphClock((RCM_APB2_PERIPH_T)(RCM_APB2_PERIPH_GPIOA | RCM_APB2_PERIPH_TMR1 | RCM_APB2_PERIPH_GPIOB));
GPIO_ConfigStruct.pin = GPIO_PIN_13;
GPIO_ConfigStruct.mode = GPIO_MODE_AF_PP;
GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz;
GPIO_Config(GPIOB, &GPIO_ConfigStruct);
GPIO_ConfigStruct.pin = GPIO_PIN_8;
GPIO_Config(GPIOA, &GPIO_ConfigStruct);
TMR_TimeBaseStruct.clockDivision = TMR_CLOCK_DIV_2;
TMR_TimeBaseStruct.countMode = TMR_COUNTER_MODE_UP;
TMR_TimeBaseStruct.division =72-1;
TMR_TimeBaseStruct.period = 40-1;
TMR_ConfigTimeBase(TMR1, &TMR_TimeBaseStruct);
OCcongigStruct.idleState = TMR_OC_IDLE_STATE_RESET;
OCcongigStruct.mode = TMR_OC_MODE_PWM1;
OCcongigStruct.nIdleState = TMR_OC_NIDLE_STATE_RESET;
OCcongigStruct.nPolarity = TMR_OC_NPOLARITY_HIGH;
OCcongigStruct.outputNState = TMR_OC_NSTATE_ENABLE;
OCcongigStruct.outputState = TMR_OC_STATE_ENABLE;
OCcongigStruct.polarity = TMR_OC_POLARITY_HIGH;
OCcongigStruct.pulse =16;
TMR_ConfigOC1(TMR1, &OCcongigStruct);
TMR1_BDT_ConfigStruc.RMOS=TMR_RMOS_STATE_DISABLE;
TMR1_BDT_ConfigStruc.IMOS=TMR_IMOS_STATE_ENABLE;
TMR1_BDT_ConfigStruc.lockLevel=TMR_LOCK_LEVEL_OFF;
TMR1_BDT_ConfigStruc.deadTime=(36+192-32);
TMR1_BDT_ConfigStruc.BRKState=TMR_BRK_STATE_DISABLE;
TMR1_BDT_ConfigStruc.BRKPolarity=TMR_BRK_POLARITY_LOW;
TMR1_BDT_ConfigStruc.automaticOutput=TMR_AUTOMATIC_OUTPUT_DISABLE;
TMR_ConfigBDT(TMR1,&TMR1_BDT_ConfigStruc);
TMR_ConfigOC1Preload(TMR1, TMR_OC_PRELOAD_ENABLE);
TMR_EnableAutoReload(TMR1);
TMR_Enable(TMR1);
TMR_EnablePWMOutputs(TMR1);
while(1)
{
}
}
|