3 Replies Latest reply on Mar 24, 2017 6:22 AM by michael.kupfner

    CyDelay between ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) and ADC_GetResult16() necessary?


      Dear Cypress Developer Community,

      I got inspired by the hackster.io project "PSoC 4 : (4+3=) 7$ Auto Ranging Ohms Meter" (https://www.hackster.io/PSoC_Rocks/psoc-4-4-3-7-auto-ranging-ohms-meter-41dc9e).

      Because I do not have a PSoC 4 available, I ported the project to PSoC5LP (CY8CKIT-059). By testing the code, I noticed that the ohms meter is working fine for lower unknown resistance values (Rx less than few hundred ohms), but auto ranging ohms meter is showing significant errors for higher resistances.

      Step-by-step I changed the hackster.io code to try to identify the error. Attached you can find my latest PSoC Creator version. For simplicity, only 4 predefined measurement-currents are taken: 2mA, 0,2mA, 20uA, 2uA. In the first attempt, IDAC is set to 2mA. If the measured ADC-voltage is above 1V, the next current range is taken (0.2mA), and so on...
      As soon as measured voltage is below 1V, the resistance value is calculated by R = U/I.

      For debugging purposes, the i-range is printed out at the character LCD-display as well.

      Here are some measurement results:
      Rx-value      resistance measured by PSoC      range
      100Ohm           98 Ohm                                     0
      1,5kOhm      1482 Ohm                                     1
      47kOhm         50 kOhm                                     2
      100kOhm     279 kOhm                                     3

      Interestingly, if I put a break point at code line 63 (adc_result = ADC_GetResult16();) and press continuously F5 (Resume Execution) in debug mode, I get much better measurement results:

      Rx-value      measured in debug mode               range
      100Ohm          99 Ohm (99.14 Ohm)                 0
      1,5kOhm     1487 Ohm (1487.79 Ohm)             1
      47kOhm        46 kOhm (46.410 Ohm)               2
      100kOhm    103 kOhm (103.947 Ohm)             3

      I figured out that I need to add a CyDelay between



      adc_result = ADC_GetResult16();

      to get closer voltages. If the delay is 200ms, I still see significant errors with 100k testing resistor (measured: 133k). By setting delay to 1s, everything seems fine... but ohms meter is acting quite slow... and furthermore, I do not understand why a CyDelay is needed here at all ?!?!


      I'm open for any ideas... because currently I have no clue what's going wrong here...


        • 1. Re: CyDelay between ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) and ADC_GetResult16() necessary?

          Dear sir,


          to avoid issue, you can wait the end of conversion before read the result of conversion.




          SAR_result = ADC_SAR_GetResult16();









          • 2. Re: CyDelay between ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) and ADC_GetResult16() necessary?

            Generally your code is ok. There is absolutely no need for a wait after the conversion is done.


            You might have three sources for errors in your design:

            • Noise on the input lines
            • Noise at your Vref (where does that come from? Buffered ??)
            • No reference resistor used

            A more reliable design will use a reference resistor in series to the R to measure. This will allow for gain corrections of the ADC and offset cancelling.





            • 3. Re: CyDelay between ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) and ADC_GetResult16() necessary?

              Rob1, Bob,


              ... thanks for your hints. In the meantime I found the error... by looking closer to the schematic of PSoC5LP Prototyping Kit (CY8CKIT-059) I noticed that Cypress connected a 1µF capacitor at Pin 3.2. That's the pin I used for ADC input... and for sure, the capacitor gets charged - the smaller the amount of current, the longer it takes... and that's why the delay is needed.




              After changing the pin the Ohms meter project is working fine.




              @Rob1: I had the same idea... but




              should be blocking;  it does not return a result until the ADC conversion is complete. That's why I tried


               while( ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) == 0) {}


              as well.




              @Bob: I didn't get your hint regarding "reference resistor" which allows for gain corrections... could you please add some more words on this idea? You made me curious...




              Thanks for your hints,