在线时间1 小时
UID258334
ST金币0
蝴蝶豆0
注册时间2011-1-6
新手上路
- 最后登录
- 2018-8-4
|
a0a.1 0b0c
手册里讲STM32F051内部比较器可以连接到定时器的OCREF_CLR输入,可是怎么配置就是实现不了内部连接(外部连接已实现逐周期电流控制),有没有高手用到这个东西,指点下什么情况,
</b>
定时器配置
/******************************************************
TIM1_Config
*******************************************************/
/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 999;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 47999;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel 1, 2, 3 and 4 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OCInitStructure.TIM_Pulse = 1000;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 100;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse = 100;
TIM_OC3Init(TIM1, &TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
// TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
// TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 1000;
TIM_OC4Init(TIM1, &TIM_OCInitStructure);
// TIM1->CCER = 0x3FF6;
/* Time BDTR configuration */
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStructure.TIM_DeadTime = 0x00;
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);
// TIM_ClearFlag(TIM1, TIM_IT_Update);
// TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_ETRConfig(TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_Inverted, 0x00);
TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Disable);
TIM_SelectOCREFClear(TIM1, TIM_OCReferenceClear_OCREFCLR);
TIM_ClearOC1Ref(TIM1, TIM_OCClear_Disable);
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* TIM1 Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
比较器配置
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
COMP_DeInit();
COMP_InitStructure.COMP_InvertingInput = COMP_InvertingInput_DAC1;
COMP_InitStructure.COMP_Output = COMP_Output_TIM1OCREFCLR;
COMP_InitStructure.COMP_OutputPol = COMP_OutputPol_NonInverted;
COMP_InitStructure.COMP_Hysteresis = COMP_Hysteresis_No;
COMP_InitStructure.COMP_Mode = COMP_Mode_HighSpeed;
COMP_Init(COMP_Selection_COMP1, &COMP_InitStructure);
COMP_Cmd(COMP_Selection_COMP1, ENABLE);
|
-
|