2 Replies Latest reply on Dec 2, 2018 7:11 PM by NughitzaA.Astarita

    Counts to volt in SAR ADC

    NughitzaA.Astarita

      Dear all,

       

      I'm a newbie for using PSoC. I don't really understand how to use SAR ADC in PSoC. I'm trying to get the digital input from piezoelectric ceramics and also the analog input (mvolt). But I can't get the voltage result. I'm using the following code :

       

      #include "project.h"

      #include "stdio.h"

      #include "stdlib.h"

       

       

      char data[60];

      uint16_t raw;

      float32_t v;

       

       

      int main(void)

      {

          __enable_irq(); /* Enable global interrupts. */

       

       

          ADC_Start();

          ADC_StartConvert();

          UART_1_Start();

       

          for(;;)

          {

             if (ADC_IsEndConversion(CY_SAR_RETURN_STATUS)){

             raw = ADC_GetResult16(0);

             v = ADC_CountsTo_mVolts(0,raw);

             sprintf(data,"v= %f mv raw= %d \n",v,raw);

              }

             UART_1_PutString(data);

             

              CyDelay(100);

             }

      }

      /* [] END OF FILE */

       

       

      Is there something wrong with the code?

       

      Thank you for your help,

      Tita