1 Reply Latest reply on Apr 23, 2020 3:59 PM by MoTa_728816

    CY8C4245AXI-473 Sequencing SAR Accumulator

    MaSw_4576221

      I am using the CY8C4245AXI-473 for a project I am working on. I have set up an 8-channel (all single ended) sequencing SAR component in Psoc Creator.

       

      From the sequencing SAR datasheet in PSoc Creator:

       

      Averaging Mode

      This parameter sets how the averaging mode operates. If the accumulate option is selected, each ADC result is added to the sum and allowed to grow until the sum attempts to outgrow a 16 bit value, at which point it is truncated. If the Fixed Resolution mode is selected, the LSb is truncated so that the value does not grow beyond the maximum value for the given resolution.

       

      AVG

      This option selects whether or not the channel is averaged. When selected, the SAR sequencer stays on the channel and takes N readings, then adds the results together. The number of samples taken is determined by the Samples averaged parameter. Averaging is available only for the maximum Resolution selected in a particular channel. Select ALT resolution for all channels to allow averaging on fewer than 12 bits resolution. Averaging is always right-aligned; therefore, the Data Format Justification parameter is ignored.

       

      I am a little confused; if I set the "Samples average: 16" and check the "AVG" check box on each channel will the result from "ADC_GetResult16(CHANNEL_0)" be a 16-bit average or a 16-bit accumulated number?

       

      I don't quiet have the hardware setup just yet to just test it to find out. Am I just being confused by the term "Averaging Mode" and thinking that it should give me an average but it actually just accumulates?

        • 1. Re: CY8C4245AXI-473 Sequencing SAR Accumulator
          MoTa_728816

          Hi,

           

          That is a good question!

           

          I also have been wondering about it,

          but I have never tested it by myself.

           

          So this morning, I took the chance.

          IMG_4254.JPG

          On a CY8CKIT-042, CY8C4245AXI-483 is mounted,

          and I hope this device is enough close to yours.

           

          So I created a sample as follows

           

          Schematic

          010-schematic.JPG

          Pins

          011-pins.JPG

          main.c

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

          #include "project.h"

          #include "stdio.h"

           

          #define STR_LEN 32

          char    str[STR_LEN+1] ;

          void    print(char *str)

          {

              UART_UartPutString(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") ;

          }

           

          void init_hardware(void)

          {

              CyGlobalIntEnable; /* Enable global interrupts. */  

              UART_Start() ;

              ADC_Start() ;

          }

           

          void measure(void)

          {

              uint16_t raw_count ;

              int16_t  mV ;

            

              ADC_StartConvert() ;

              ADC_IsEndConversion(ADC_WAIT_FOR_RESULT) ;

              raw_count = ADC_GetResult16(0) ;

              mV = ADC_CountsTo_mVolts(0, raw_count) ;

              snprintf(str, STR_LEN, "count = %4d : %d.%03d V\n\r",

                  raw_count, mV/1000, mV%1000) ;

              print(str) ;

          }

           

          int main(void)

          {

              init_hardware() ;

           

           

              splash("CY8CKIT-042 ADC Test") ;

            

              for(;;)

              {

                  measure() ;

                  CyDelay(1000) ;

              }

          }

          =================\

           

          Then I configured ADC with fixed resolution

          005-sample8_av_fix.JPG

           

          004-AVG_x.JPG

           

          The result Tera Term log was

          006-Tera_term.JPG

           

          Then I changed ADC to Accumulate mode

          007-sample8_accum.JPG

           

          008-AVG_x.JPG

           

          The result Tera Term log was

           

          009-TeraTerm-log.JPG

           

          So, Yes, in the accumulate mode, the ADC counts were accumulated.

          But ADC_CountsTo_mVolts() API, took care of it, too.

           

          I hope this can be a hint for you ;-)

           

          moto

          1 of 1 people found this helpful