PSOC 5 - SAR ADC and clock signal - different results

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RiTa_288331
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted

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?

0 Likes
2 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Please post your code so we can check it.

0 Likes
lock attach
Attachments are accessible only for community members.
RiTa_288331
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted

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) >> 😎  );
   UART_1_PutChar('3'); //Use this as a diagnostic statement ("are we alive?")
}

   

</code>

0 Likes