2 Replies Latest reply on Mar 11, 2017 8:29 PM by user_1409605

    PSOC 5 - SAR ADC and clock signal - different results

    user_1409605

      Hello All!

         

      A "test" program that I'm doing: using a clock-->PWM-->ADC, I'm changing the sample rate of the 12 bit SAR ADC and then reading the results in the debugger (I have a break point in the interrupt - this is triggered when the ADC's eoc signal is high).

         

      I change the clock rate (using 12Hz, 12kHz, and 12MHz), and I apply a constant DC voltage to the ADC pin.  I notice that, when I change the clock signal (which ultimately changes the ADC sampling rate), I get VERY different results.  I'm not sure why this is, and which clock rate produces the "correct" ADC result?

         

      Example: applying 2.0V at the ADC pin with a 12kHz clock (thus giving me a 10 millisec sampling rate) gives an ADC result of 0x1EE

         

      Changing to a 120Hz clock (sampling rate = 1 second) give an ADC result of 0x5A6

         

      What am I missing here?  Shouldn't the ADC results be the same?

        • 1. Re: PSOC 5 - SAR ADC and clock signal - different results
          user_242978793

          Please post your code so we can check it.

          • 2. Re: PSOC 5 - SAR ADC and clock signal - different results
            user_1409605

            Greetings!  My code and a screenshot of the schematic are here:

               

            <code>

               

            #include "project.h"
            #include <stdio.h> //We include this in order to use the sprintf() function

               

            int dummy = 0;
            int16 result = 0;
            /* Interrupt prototypes */
            //Interrupts in PSOC Creator MUST have prototypes
            CY_ISR_PROTO(ADC_DONE);

               

            int main(void)
            {
                CyGlobalIntEnable; /* Enable global interrupts. */

               

                /* Place your initialization/startup code here (e.g. MyInst_Start()) */
                //Start the peripherals:
                UART_1_Start();
                PWM_1_Start();
                ADC_SAR_1_Start();
                //Start the interrupts:
                isr_adc_eoc_StartEx(ADC_DONE);  //This enables this interrupt
                CyGlobalIntEnable; // Enable global interrupts
                
                for(;;)
                {
                    /* Place your application code here. */
                    //UART_1_PutCRLF('3'); //Use this as a diagnostic statement ("are we alive?")
                    //CyDelay(1000);
                }
            }

               

            //Interrupt routines here:
            CY_ISR(ADC_DONE) {
               //int16 result;

               

               isr_adc_eoc_ClearPending();    //MUST have this so that the interrupt doesn't repeatedly fire out-of-turn
                
               result = ADC_SAR_1_GetResult16();
               //UART_1_PutChar( (int8)((0xFF) && result)  );
               //UART_1_PutCRLF( (int8)((result && 0xFF00) >> 8)  );
               UART_1_PutChar('3'); //Use this as a diagnostic statement ("are we alive?")
            }

               

            </code>