6 Replies Latest reply on Feb 5, 2020 5:26 PM by MoTa_728816

    Datasheet equivalent code

    LuMo_4610041

      Hello,

      As I tried to create code, I found myself obligated to use only the code in the ADC datasheet that is associated with the code I intend to use. Unless I use such corresponding code I get errors as in the example shown in the attached picture. Is it expected that one use such code, or I am doing something wrong? Also, as I Build I get two errors which I am not sure  are due to this funky conversion.  Should I switch to a different version of ADC, and if so how.?

       

      The purpose of this project to read the voltage drop in a thermistor to be fed into a ADC for reading into a LCD. Please see attached a picture with my code and the before mentioned error.

       

      I am using PSoC 5LP CY8CKIT-59 in a Windows 10PC. Datrasheet: Delta Sigma Analog to Digital Converter (ADC_DelSig) 3.30

       

      Environment:

      PSoC Creator  4.2 (4.2.0.641)

      Culture: English (United States)

      OS Version: Microsoft Windows NT 10.0.18362.0

      CLR Version: 4.0.30319.42000

       

      Installed CyInstaller Products:

      CY8CKIT-059 PSoC 5LP Prototyping Kit 1.0 Rev.*A

      Peripheral Driver Library 3.0.1

      Peripheral Driver Library 3.0.3

      Peripheral Driver Library 3.0.4

      Peripheral Driver Library 3.1.0

      PSoC Programmer 3.28.5

      PSoC Creator 4.2

       

      You guidance is much appreciated.

        • 1. Re: Datasheet equivalent code
          GaneshD_41

          Hi,

           

          Have you checked code example "CE95381 Thermistor temperature calculation with PSoC 3/5LP" in the following PSoC 3,4 and 5 code examples web page?

           

          https://www.cypress.com/documentation/code-examples/psoc-345-code-examples

           

          https://www.cypress.com/documentation/code-examples/ce95381-thermistor-temperature-calculation-psoc-35lp

           

          Thanks

          Ganesh

          • 2. Re: Datasheet equivalent code
            LePo_1062026

            LuMo,

             

            Did you create a function called ADC_StattConvert()?  Or did you mean to call it ADC_StartConvert()?

             

            Len

            • 3. Re: Datasheet equivalent code
              VasanthR_91

              Hi ,

               

              First of all there is a typo in ADCStartConvert API.

               

              Secondly if you are trying to type cast use the following method,

              voltage=  (uint16) ADC_CountsTo_mVolts((uint32) adcCounts);
              

               

              Otherwise remove the explicit data type usage.

               

              Best Regards,
              Vasanth

              • 4. Re: Datasheet equivalent code
                LuMo_4610041

                Everyone, thanks for your feedback.

                Here is a different version of the original question, why can't I run the code like below instead of having to use all those "void" and corresponding code in the datasheet?

                 

                for(;;)

                    {

                ADC_Start();

                ADC_StartConvert();

                ADC_IsEndConversion(ADC_WAIT_FOR_RESULTS);

                number =  ADC_GetResults32();

                ADC_Stop_Convert;

                voltage =ADC_Voltage_CountsTo_mVolts(number);

                temp = (voltage/10.00);

                sprint(str, “%.1f”, temp);LCD_Position (3,5);

                LCD_PrintString (str);

                }

                • 5. Re: Datasheet equivalent code
                  BoTa_264741

                  LuMo,

                  Do you realize that total execution time of the code in the loop is shorter than ADC conversion time? You need to add something like

                  CyDelay(100); // pause for 100ms

                  inside the loop to slow it down.

                  /odissey1

                  • 6. Re: Datasheet equivalent code
                    MoTa_728816

                    Hi,

                     

                    The annotation in the datasheet, something like below

                    005-get_result32.JPG

                    means that the function ADC_GetResult32() returns value of type int32

                    and the special word "void" means that it does not require any argument(s).

                     

                    As you know we may just discard the return value or receive it with a variable of type int32.

                    So practically the code will look like

                     

                    int32 adc_counts ;

                    ...

                        adc_counts = ADC_GetResult32() ;

                     

                    Meantime, you may be having problem with floating format "%.1f", about this I posted a memo

                    printf and float rhapsody (aka, yet another printf and floating topic)

                     

                    Anyway I tried to write a sample for CY8CKIT-059.

                    I connected a pot at VDD, P1[7], GND.

                     

                    schematic

                    000-schematic.JPG

                    ADC Configure(s)

                    001-ADC_Config1.JPG

                    002-ADC_Config2.JPG

                    pins

                    003-Pins.JPG

                     

                    main.c

                    ====================

                    #include "project.h"

                    #include "stdio.h"

                     

                    #define STR_LEN 64

                    char str[STR_LEN+1] ;

                    void print(char *str)

                    {

                        UART_PutString(str) ;

                    }

                     

                    void cls(void)

                    {

                        print("\033c") ; /* reset */

                        CyDelay(20) ;

                        print("\033[2J") ; /* clear screen */

                        CyDelay(20) ;

                    }

                     

                    void splash(char *prog_name)

                    {

                        cls() ;

                        if (prog_name && *prog_name) {

                            print(prog_name) ;

                        }

                        print(" (") ;

                        print(__DATE__) ;

                        print(" ") ;

                        print(__TIME__) ;

                        print(")\n") ;

                    }

                     

                    int main(void)

                    {

                        int32_t adc_counts ;

                        int16_t voltage ;

                       

                        CyGlobalIntEnable; /* Enable global interrupts. */

                     

                        UART_Start() ;

                        splash("5LP ADC Test") ;

                       

                        ADC_Start() ;

                     

                        for(;;)

                        {

                            ADC_StartConvert() ;

                     

                            ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ;

                     

                            adc_counts = ADC_GetResult32() ;

                     

                            // ADC_StopConvert() ; // I set ADC single conversion, so this is not required

                     

                            voltage = ADC_CountsTo_mVolts(adc_counts) ;

                     

                            if (voltage >= 0.0) {

                                snprintf(str, STR_LEN, "%d.%03d", voltage /1000, voltage % 1000) ;

                            } else {

                                voltage = -voltage ;

                                snprintf(str, STR_LEN, "-%d.%03d", voltage /1000, voltage % 1000) ;

                            }

                     

                            // LCD_Position(3, 5) ;

                            // LCD_PrintString(str) ;

                     

                            print(str) ;

                            print("\n\r") ;

                     

                            CyDelay(1000) ; // adjust value depending on your need

                        }

                    }

                    ====================

                     

                    The result Tera Term log looked like

                    004-TeraTerm-log.JPG

                     

                    moto