Processor is an Infineon CY8C6245LQI-S3D42. We're basing our code on the examples in the documentation but seem to be unable to get an actual reading off the ADC. Debugging has traced the problem to something about our CheckADC()
function.
int main(void) {
cy_rslt_t result;
Cy_GPIO_Write(Batt1Out_PORT, Batt1Out_NUM, 1);
Cy_GPIO_Write(TempPwr_PORT, TempPwr_NUM, 1);
Cy_GPIO_Write(PayloadCtrl_PORT, PayloadCtrl_NUM, 0);
int16_t resultADC;
int16_t resultmV;
int16_t voltagemVolts;
uint32_t chan = 0UL;
Cy_SAR_Init(BusVoltage_HW, &BusVoltage_config); // ADC channel 0 is designated BusVoltage in config
Cy_SAR_Enable(BusVoltage_HW);
Cy_SAR_StartConvert(BusVoltage_HW, CY_SAR_START_CONVERT_CONTINUOUS);
/* snip #if defined block */
int CheckADC( void ) {
resultADC = Cy_SAR_GetResult32(BusVoltage_HW, chan);
resultmV = Cy_SAR_CountsTo_mVolts(BusVoltage_HW, chan, resultADC);
voltagemVolts = resultmV * 8; // 8:1 voltage divider on the input
return 0UL;
}
}
The resultADC
expression is returning a constant value of -2048 and as a result we're getting no useful results when CheckADC()
is called, despite having a 15 V (ETA: 1.875 V after voltage divider), 0.1 A power supply connected to that terminal.