本实验参考 DC Monitoring例程,通过A1引脚进行电压测量。
首先进行外设初始化,其次在主循环里面进行电压测量。
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("batt_level_mv = %d \r\n",batt_level_mv);
/* Reset for the next set of readings */
batmon_cplt = 1;
batmon_dc_avg = 0;
}
把扩展接口的3.3v连接到A1引脚,控制台输出当前电压:
|