程序中配置如下:
//使能电流保护,配置电流保护为比较器3输出,全通道关闭
PWM ->CSR |= PWM_CSR_CP_TRGSEL_1 | PWM_CSR_CPE;
//配置PC14、PC15为模拟输入引脚,做为比较器输入,中速、无迟滞
void Comp_Conf(void)
{
COMP_InitTypeDef COMP_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
//使能比较器的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_CPT, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
配置PC14/15为模拟输入口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
COMP_InitStructure.COMP_InvertingInput = COMP_InvertingInput_IO2;
COMP_InitStructure.COMP_NonInvertingInput = COMP_NonInvertingInput_IO2;
COMP_InitStructure.COMP_Output = COMP_Output_None;
COMP_InitStructure.COMP_OutputPol = COMP_OutputPol_NonInverted;
COMP_InitStructure.COMP_Hysteresis = COMP_Hysteresis_No;
COMP_InitStructure.COMP_Mode = COMP_Mode_MediumSpeed;
COMP_Init(COMP_Selection_COMP3, &COMP_InitStructure);
COMP_Cmd(COMP_Selection_COMP3, ENABLE);
}
|