1 Reply Latest reply on Mar 19, 2019 5:21 AM by VasanthR_91

    SAR PSoc6  doesn't work

    VeSe_4052481

      I have a  project whit a PSoc6  and a SAR ADC v 3.1.0 .

      The program reads a single ended channel by PIN P10_0 but the value thta I read is always zero....

      thank you...

       

       

       

      The code is:

       

       

      int main(void)

      {

         

        /* UART initialization status */

          cy_en_scb_uart_status_t uart_status ;

          /* String to transmit over UART. */

          char uartString[200];

         

          static int16_t chanResult;

          static int16_t chanResultmV;

          /* ADC SAR initialization status */

          cy_en_sar_status_t status;

         

          char flag=0;

         

           /* Initialize UART operation. Config and Context structure is copied from Generated source. */

          uart_status  = Cy_SCB_UART_Init(Uart_Printf_HW, &Uart_Printf_config, &Uart_Printf_context);

          if(uart_status != CY_SCB_UART_SUCCESS)

          {

              HandleError();

          }

          Cy_SCB_UART_Enable(Uart_Printf_HW);

         

         

          /* Enable analog reference block needed by the SAR. */

          Cy_SysAnalog_Init(&Cy_SysAnalog_Fast_Local);

          Cy_SysAnalog_Enable();

          Cy_SAR_Enable(SAR);

          /* Initiate continuous conversions. */

          Cy_SAR_StartConvert(SAR, CY_SAR_START_CONVERT_CONTINUOUS);

       

       

       

          for(;;)

          { 

             

         /* Query end of conversion status. */

                  status = Cy_SAR_IsEndConversion(SAR, CY_SAR_RETURN_STATUS);

                  if (CY_SAR_SUCCESS == status)

                  {     

                            chanResult = Cy_SAR_GetResult16(SAR, 0);

         

                           chanResultmV = Cy_SAR_CountsTo_mVolts(SAR, 0, chanResult);

                           /* Transmit results over UART. */

                          sprintf(uartString, "Volt  = %d \r\n", chanResultmV);

                          Cy_SCB_UART_PutString(Uart_Printf_HW, uartString);

                           Cy_GPIO_Inv(LED_Red_P0_3_PORT, LED_Red_P0_3_NUM);

                           CyDelay(200);

                 

                 }    }

      }