可以看一下代码,然后我将配置过程说一下。
while (1)
{
/* Monitoring for every one second */
Cy_SysLib_Delay(1000);
Cy_ADCMic_SetInterruptMask(adcmic_0_HW, CY_ADCMIC_INTR_DC);
Cy_ADCMic_ClearInterrupt(adcmic_0_HW, CY_ADCMIC_INTR);
/* Enable the DC monitoring */
Cy_ADCMic_Enable(adcmic_0_HW);
/* ADC Settling Time */
Cy_SysLib_Delay(10);
/* Enable ADC timer to generate interrupt for reading the sample */
Cy_ADCMic_EnableTimer(adcmic_0_HW);
/* Wait for DC monitoring samples to complete */
while(batmon_cplt);
for (int i = 0; i < NO_OF_DC_SAMPLES; i++)
{
batmon_dc_avg = batmon_dc_avg + batmon_samples[i];
}
batmon_dc_avg = batmon_dc_avg/NO_OF_DC_SAMPLES;
/* Convert the ADC code in millivolts */
batt_level_mv = Cy_ADCMic_CountsTo_mVolts((int16_t)batmon_dc_avg, adcmic_0_config.dcConfig->context );
printf("我的电压为多少mv : %d \r\n",batt_level_mv);
/* Reset for the next set of readings */
batmon_cplt = 1;
batmon_dc_avg = 0;
}
使用的是P3.5引脚
在这里设置
设置电压的范围
在板子引脚悬空的时候,看一下电压情况:
看一下串口调试助手
|