startKIT adc values seem to float

If you have a simple question and just want an answer.
Post Reply
User avatar
aclassifier
Respected Member
Posts: 483
Joined: Wed Apr 25, 2012 8:52 pm
Contact:

startKIT adc values seem to float

Post by aclassifier »

27April2015: update

Oscilloscope picture: green is 3.3V (AC 100mV/div), blue is AD0 (AC 100mV/div) (temperature-voltage converter's output), yellow is LED0 ADC_SAMPLE (DC 1V/div). Looks like I need some decoupling?

I fail to get the adc values returned correctly. I run 14.0.1 

Excerpts from the code below. I also have

  • the standard STARTKIT.xn
  • config.xscope from startkit-adc
  • -O2 -g -report -fxscope in the <default> makefile
The values I get are random (perhaps ok for channel 1,2,3 but not channel 0 which is connected to a temperature-to-voltage converter TC1047 which also takes 3.3V as power. It gives about 800mV. I have measured it.):

Code: Select all

ADC chans = 20880,14768,15312,14704ADC chans = 22560,14800,15968,15504ADC chans = 18400,14384,13296,12736ADC chans = 17088,14304,12656,12224ADC chans = 18080,14464,13728,12880
Code 1:
 
port inP_button_1 = on tile[0]:XS1_PORT_1E;
port inP_button_2 = on tile[0]:XS1_PORT_1J;
int main () {
    chan c_button_1;
    chan c_button_2;
    interface delay_interface i_delay;
    chan c_analogue;
    interface startkit_adc_if i_analogue;
    par {
        on tile[0].core[0]: test_display (i_delay, c_button_1, c_button_2, i_analogue);
        on tile[0].core[1]: inP_Button_Task (BUTTON_1, inP_button_1, c_button_1);
        on tile[0].core[1]: inP_Button_Task (BUTTON_2, inP_button_2, c_button_2);
        on tile[0].core[3]: server_delay_iff(i_delay);
        on tile[0].core[4]: adc_task (i_analogue, c_analogue, 0);
                            startkit_adc (c_analogue);
    }
    return 0;
}
 
Code 2 (I haven't removed irrelevant code, to have in full here): 
 
[[combinable]]
void test_display (
    client interface delay_interface i_delay,
    chanend c_button_1,
    chanend c_button_2,
    client interface startkit_adc_if i_analogue)
{
 
    unsigned delay_ms = 0;
    unsigned wait_for_button = 1;
    unsigned wait_for_adc = 0;
    t_startkit_adc_vals adc_vals;
    // unsigned short adc_val[4] = {0, 0, 0, 0};
 
    test_params_t test_params;
 
    // By default, we'll generate the high voltage from the 3.3v line internally! (neat!)
    Adafruit_SSD1306_i2c_constructor (true);
    Adafruit_SSD1306_i2c_begin (SSD1306_SWITCHCAPVCC, 0x3C, true);  // initialize with the I2C addr 0x3C (for the 128x32)
 
    clearDisplay();
    display();
 
    test_params.test_this_case  = -3;
    test_params.test_this_ascii = 0;
 
    i_delay.delay_control(1); // enable
    i_delay.delay_iff (delay_ms);  // start
 
    while(1) {
        select
        {
            case wait_for_button => c_button_1 :> int x:
            {
                printf("2 Next!\n");
                i_delay.delay_control(0); // disable
                wait_for_button = 0;
                break;
            }
            case wait_for_button => c_button_2 :> int x:
            {
                printf("2 RESTART ====\n");
                i_delay.delay_control(1); // enable
                printf("2 delay control called\n");
                wait_for_button = 0;
                i_analogue.trigger();
                printf("2 adc trigger\n");
                wait_for_adc = 1;
                break;
            }
            case ((wait_for_adc==0) && (wait_for_button==0)) => i_delay.timeout():
            {
                printf("> Example\n");
                delay_ms = examples_adafruit_ssd1306_128x32_i2c (&test_params);
                printf("< Finished\n");
                i_delay.delay_control(1);     // enable
                i_delay.delay_iff (delay_ms); // start
                wait_for_button = 1;
                break;
            }
            case wait_for_adc => i_analogue.complete():
            {
                wait_for_adc = 0;
                if (i_analogue.read (adc_vals.x)) {  // 0 to 65520
                    test_params.test_this_temperature = (adc_vals.x[0] / 1000);
                    printf("ADC chans = ");
                    for (int i=0; i<NUM_STARTKIT_ADC_VALS; i++) {
                        printf("%u", adc_vals.x);
                        if (i < (NUM_STARTKIT_ADC_VALS-1)) {
                            printf(",");
                        } else {
                            printf("\n");
                        }
                    }
                }
                else {
                    printf("3 No ADC!\n");
                    test_params.test_this_temperature = 0;
                }
 
                test_params.test_this_case  = -4;
                test_params.test_this_ascii = 0;
                break;
            }
        }
    }
}
 
Then I have this def (but I have tried the standard array, no difference):
 
#define NUM_STARTKIT_ADC_VALS 4
 
typedef struct tag_startkit_adc_vals {
    unsigned short x[NUM_STARTKIT_ADC_VALS];
} t_startkit_adc_vals;
 
 


--
Øyvind Teig
Trondheim (Norway)
https://www.teigfam.net/oyvind/home/
Post Reply