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

    PSoC 5 Battery Measurements




      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:








      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 */
              /* 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. */


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