3 Replies Latest reply on Oct 29, 2015 8:56 AM by user_1377889

    PSoC 5 Battery Measurements

    neal.o'hara

      Hello.

         

      In the  past, I've used the PSoC 4 BLE battery measure example to make battery measurements on a device.

         

       

         

      I am now trying to do the same for a new project, using the PSoC 5lp.

         

      However, since there is no example, I am struggling to all of the necessary features.

         

       

         

      First off, the PSoC 4 has an external pin labeled VREF that is used for this.  Would one of the VCCD pins be the PSoC 5 equivalent?

         

       

         

      2ndly, there is a visible change in the macros for the PSoC 4 SAR ADC and the PSoC 5 SAR adc. 

         

      I am struggeling to convert the following macros:

         

      ADC_VREF_INTERNAL1024BYPASSED

         

      ADC_VREF_VDDA

         

       

         

      The macros and control registers seem to be different between the PSoC 4 and PSoC 5, which makes sense, I'm just struggeling to conver them.

         

      Any help or advice is appreciated.

         

       

         

      The following is the entire code piece I am trying to convert:

         

      /* Set the reference to VBG and enable reference bypass */
              sarControlReg = ADC_SAR_CTRL_REG & ~ADC_VREF_MASK;
              ADC_SAR_CTRL_REG = sarControlReg | ADC_VREF_INTERNAL1024BYPASSED;

         

              /* 25 ms delay for reference capacitor to charge */
              CyDelay(25);
              
              /* Set the reference to VDD and disable reference bypass */
              sarControlReg = ADC_SAR_CTRL_REG & ~ADC_VREF_MASK;
              ADC_SAR_CTRL_REG = sarControlReg | ADC_VREF_VDDA;

         

              /* Perform a measurement. Store this value in Vref. */
              CyDelay(1);
              ADC_StartConvert();
              ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

         

              adcResult = ADC_GetResult16();
              /* Calculate input voltage by using ratio of ADC counts from reference
              *  and ADC Full Scale counts.
              */
              mvolts = (1.024 * 2048) / adcResult;