手册里讲STM32F051内部比较器可以连接到定时器的OCREF_CLR输入,可是怎么配置就是实现不了内部连接(外部连接已实现逐周期电流控制),有没有高手用到这个东西,指点下什么情况,
定时器配置 /****************************************************** 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); |
【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?
RE:关于STM32F051比较器与定时器的逐波电流控制问题!
回复:关于STM32F051比较器与定时器的逐波电流控制问题!
黄色的通道是比较器同相端输入可调电位器,紫色为比较器反相端输入DAC模拟的锯齿波,蓝色为控制后PWM波形。
比较器输出端PA6直连到定时器1ETR端PA12
COMPControlTIM.rar
2012-9-5 14:21 上传
点击文件名下载附件
下载积分: ST金币 -1566.25 KB, 下载次数: 231, 下载积分: ST金币 -1
回复:关于STM32F051比较器与定时器的逐波电流控制问题!