#技术资源# (波形截图见附件) 1 概述在调试定时器时,自动重装载缓冲使能、使能输出比较通道 1 预装载、产生更新事件的概念不好理解,经过使能、禁止的对比采集PWM波形,对比这几个寄存器的概念。 2 寄存器功能定义(1)数值类 寄存器 | | | 自动重装载数值(Auto Reload Value) |
(2)控制类 寄存器 | | | TMRx_AUTORLD-> ARPEN: 自动重装载缓冲使能(Auto-reload Preload Enable) |
寄存器 | | | TMRx_CCx-> OC1PEN: 使能输出比较通道 1 预装载(Output Compare Channel1 Preload Enable) |
寄存器 | | | TMRx_CEG->UEG: 产生更新事件(Update Event Generate) |
3 自动重装载缓冲实验现象3.1 禁止自动重装载缓冲区 寄存器数值 | | | // TMR_EnableAutoReload(TMR1); | | |
3.2 使能自动重装载缓冲区 寄存器数值 | | | TMR_EnableAutoReload(TMR1); | | |
3.3 总结使能“自动重装载缓冲”时,PWM的频率会在下一个周期(更新事件)改变; 禁止“自动重装载缓冲”时,PWM的频率会立刻改变。 3.4 参考测试代码说明:代码中的GPIO翻转用作触发信号,以采集波形 void Trigger_IO_Init(void) { GPIO_Config_T configStruct; RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_GPIOC); configStruct.pin = GPIO_PIN_0; configStruct.mode = GPIO_MODE_OUT_PP; configStruct.speed = GPIO_SPEED_50MHz; GPIO_Config(GPIOC, &configStruct); } void SoftDelay(uint32_t counter) { int i=0,j=0; for(i=0;i<counter;i++) { for(j=0;j<100;j++) { __NOP();__NOP();__NOP();__NOP();__NOP(); } } } int main(void) { GPIO_Config_T GPIO_ConfigStruct; TMR_BaseConfig_T TMR_TimeBaseStruct; TMR_OCConfig_T OCcongigStruct; uint32_tpclk1_value=0,pclk2_value; Trigger_IO_Init(); RCM_ReadPCLKFreq(&pclk1_value,&pclk2_value); 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_1; TMR_TimeBaseStruct.countMode = TMR_COUNTER_MODE_UP; TMR_TimeBaseStruct.division=720-1; TMR_TimeBaseStruct.period = 10-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 = 3; TMR_ConfigOC1(TMR1, &OCcongigStruct); TMR_ConfigOC1Preload(TMR1, TMR_OC_PRELOAD_ENABLE); // TMR_EnableAutoReload(TMR1); TMR_Enable(TMR1); TMR_EnablePWMOutputs(TMR1); SoftDelay(100); TMR_ConfigAutoreload(TMR1,20-1); GPIO_SetBit(GPIOC,GPIO_PIN_0); __NOP();__NOP();__NOP();__NOP();__NOP(); GPIO_ResetBit(GPIOC,GPIO_PIN_0); __NOP();__NOP();__NOP();__NOP();__NOP(); while(1) { } }
|