0

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.

StarSword
  • 11
  • 4

2 Answers2

1

15V? Maybe it's because I haven't seen your circuit, but I'm not sure I'm aware of any MCU that allows such an high voltage on a gpio.

If it is within the normal operation voltage for that pin, the first few things I'd check are the initialization of your clocks, initialization of the ADC module, initialization of your IO's. Then, if all that is fine (and the chip is known functional, I'd look into the implementation. I'm not an expert with Cypress and don't know what is in the function Cy_SAR_Init. So it's hard to comment on your implementation. Hope this helps!

Julien
  • 1,717
  • 14
  • Sorry, I should have been more clear that the 15V signal is being sent through an 8:1 voltage divider before it gets to the MCU (I did mention that in a comment in the code but I guess it wasn't as obvious as I thought). So the ADC should actually be receiving 1.875V. – StarSword Jul 14 '23 at 18:49
  • Ok, i would then check it with an high impedance dmm to ensure your circuit works fine. I doubt that this will be the issue, but what is the reference voltage for the adc? – Julien Jul 16 '23 at 12:14
1

Solution courtesy of Andri-setyabudi on the Infineon forum:

You need to Activate the AREF and call these functions : Cy_SysAnalog_Init and Cy_SysAnalogEnable before activate the SAR_ADC. Please refer to this document on section 2.3.3.2

 As an additional note, you need to use int32_t type instead of int16_t for resultADC since function Cy_SAR_GetResult32 will return the result data as a signed 32-bit integer.

StarSword
  • 11
  • 4