COMP初始化 comp_init() 实验使用COMP的0号比较器,操作比较器控制状态寄存器(COMP1_CSR),配置输出滤波、迟滞电压、输出极性、输出方向选择、正相输入通道、反相输入通道及功耗模式。 void comp_init()
{
/* Output filter. */
COMP->CSR[0] |= COMP_CSR_OFLT(COMP_OutFilter_4); /* If the comparison result remains unchanged for four clock cycles, the output is valid. COMP_OutFilter_4 = 2. */
/* Hysteresis. */
COMP->CSR[0] |= COMP_CSR_HYST(COMP_Hysteresis_Alt3); /* 90mV, COMP_Hysteresis_Alt3 = 3. */
/* No invert output. */
COMP->CSR[0] |= COMP_CSR_POL(false); /* In-phase output. */
/* Not output to other peripheral input. */
COMP->CSR[0] |= COMP_CSR_OUTSEL(COMP_OutMux_None); /* COMP_OutMux_None = 0. */
/* Positive side. */
COMP->CSR[0] |= COMP_CSR_INPSEL(COMP_InMux_Alt0); /* COMP_INP[0], PA1, COMP_InMux_Alt0 = 0. */
/* Inverse side. */
COMP->CSR[0] |= COMP_CSR_INMSEL(COMP_InMux_Alt0); /* COMP_INM[0], PA5, COMP_InMux_Alt0 = 0. */
/* The faster the speed, the higher the power consumption. */
COMP->CSR[0] |= COMP_CSR_MODE(COMP_Speed_High); /* COMP_Speed_High = 0, high speed, high power. */
}
|