比较器配置代码: void bspCMP_Init(void) { stc_vc_general_config_t stcVcGeneralCfg; stc_vc_channel_config_t stcVcChannelCfg; //变量清0 DDL_ZERO_STRUCT(stcVcGeneralCfg); DDL_ZERO_STRUCT(stcVcChannelCfg); Clk_SetPeripheralGate(ClkPeripheralVcLvd, TRUE);//开启VC时钟 Clk_SetPeripheralGate(ClkPeripheralAdcBgr, TRUE);//配置ADC时钟 M0P_BGR->CR_f.BGR_EN = 0x1u;//必须使能 delay100us(1); Gpio_SetAnalog(3, 2, TRUE); Gpio_SetAnalog(3, 3, TRUE); genChannel = VcChannel1;//配置VC输入通道 stcVcGeneralCfg.bDivEn = FALSE;//6位DAC不使能 // stcVcGeneralCfg.enDivVref = VcDivVrefAdc; stcVcGeneralCfg.enDivVref = VcDivVrefAvcc;//VcDivVrefAvcc;//分压的参考电压为VCC stcVcGeneralCfg.u8DivVal = 0x3F;//分压值为1 stcVcChannelCfg.enVcChannel = genChannel;//VC通道设置----------------- stcVcChannelCfg.enVcCmpDly = VcDelayoff;//迟滞配置 stcVcChannelCfg.enVcBiasCurrent = VcBias20ua;//功耗选择 // stcVcChannelCfg.enVcFilterTime = VcFilter7us;//输出滤波时间配置 stcVcChannelCfg.enVcInPin_P = VcInPCh2;//P3.2 stcVcChannelCfg.enVcInPin_N = VcInNCh3;// stcVcChannelCfg.enVcOutConfig = VcOutDisable;//输出配置寄存器 stcVcChannelCfg.enVcIrqSel = VcIrqFall; stcVcChannelCfg.pfnAnalogCmpCb = VcIrqCallback; Vc_GeneralInit(&stcVcGeneralCfg); Vc_ChannelInit(genChannel, &stcVcChannelCfg); Vc_EnableFilter(genChannel); Vc_ConfigIrq(stcVcChannelCfg.enVcChannel, stcVcChannelCfg.enVcIrqSel); Vc_EnableIrq(stcVcChannelCfg.enVcChannel); Vc_EnableChannel(stcVcChannelCfg.enVcChannel); }
模拟电压比较器经过配置后,正端的电压降到0V,而负端的电压保持与电源一致3.3V,如图。 file:///C:/Users/panpan/AppData/Local/Temp/ksohtml8248/wps1.jpg 若是正端的输入电压没有电源电压那么高,比较器不就一直输出低电平吗?
|