ADC1 configuration

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ADC1 configuration

Post by Giovanni »

Note that the values are not so random.

Giovanni
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: ADC1 configuration

Post by Nemesis2065 »

Yes, they are not so random after all, but not usefull :?
I just tried on PB0 and PB1 pins, and I got the same result...
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: ADC1 configuration

Post by Nemesis2065 »

Hi,

I changed my ADC configuration and took the demo code as example. I want to read PC1(internal temp sensor) PC4 et PC5.
So I made this config :

Code: Select all

#define ADC_GRP1_NUM_CHANNELS  4
#define ADC_GRP1_BUF_DEPTH         4
const ADCConversionGroup adcgrp1_cfg =
{
    FALSE,
    ADC_GRP1_NUM_CHANNELS,
    NULL,
    NULL,
    0,
    ADC_CR2_SWSTART,
    ADC_SMPR1_SMP_AN14(ADC_SAMPLE_56) |
    ADC_SMPR1_SMP_AN15(ADC_SAMPLE_56) |
    ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_56) |
    ADC_SMPR1_SMP_VREF(ADC_SAMPLE_56),
    0,
    ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
    0,
    ADC_SQR3_SQ4_N(ADC_CHANNEL_VREFINT) |
    ADC_SQR3_SQ3_N(ADC_CHANNEL_SENSOR) |
    ADC_SQR3_SQ2_N(ADC_CHANNEL_IN15) |
    ADC_SQR3_SQ1_N(ADC_CHANNEL_IN14)
};


This init :

Code: Select all

adcStart(&ADCD1, NULL);
adcSTM32EnableTSVREFE();
palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG);    /*  IN11  : stm32 temp sensor   */
palSetPadMode(GPIOC, 4, PAL_MODE_INPUT_ANALOG);    /*  IN14  : temp sensor         */
palSetPadMode(GPIOC, 5, PAL_MODE_INPUT_ANALOG);    /*  IN15  : IR telemeter        */


And I'm reading hte ADC values like this in a 1s Thread:

Code: Select all

adcConvert(&ADCD1, &adcgrp1_cfg, ADC_Samples, ADC_GRP1_BUF_DEPTH);

/* Calculates the average values from the ADC samples.*/
avg_PC4 = (ADC_Samples[0] + ADC_Samples[4] + ADC_Samples[8]  + ADC_Samples[12]) / 4;      
avg_PC5 = (ADC_Samples[1] + ADC_Samples[5] + ADC_Samples[9]  + ADC_Samples[13]) / 4;
avg_PC1 = (ADC_Samples[2] + ADC_Samples[6] + ADC_Samples[10] + ADC_Samples[14]) / 4;    // internal temp sensor
avg_VREF = (ADC_Samples[3] + ADC_Samples[7] + ADC_Samples[11] + ADC_Samples[15]) / 4;
       
chprintf((BaseSequentialStream*) &SD3, "PC4 value  : %d, %d, %d, %d \r\n", ADC_Samples[0], ADC_Samples[4], ADC_Samples[8], ADC_Samples[12]);
chprintf((BaseSequentialStream*) &SD3, "PC5 value  : %d, %d, %d, %d \r\n", ADC_Samples[1], ADC_Samples[5], ADC_Samples[9], ADC_Samples[13]);
chprintf((BaseSequentialStream*) &SD3, "PC1 value  : %d, %d, %d, %d \r\n", ADC_Samples[2], ADC_Samples[6], ADC_Samples[10], ADC_Samples[14]);
chprintf((BaseSequentialStream*) &SD3, "VREF value : %d, %d, %d, %d \r\n", ADC_Samples[3], ADC_Samples[7], ADC_Samples[11], ADC_Samples[15]);
chprintf((BaseSequentialStream*) &SD3, "\r\n");


And I obtain this :
Image

Whatever is connected on the pins PC4 and PC5 (GND, 3.3v) I have the same result...

Any ideas ?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ADC1 configuration

Post by Giovanni »

Are the pins unconnected on the board?

Giovanni
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: ADC1 configuration

Post by Nemesis2065 »

PC5 is unconnected, but PC4 is connected to a thermal sensor (LM35).
And I assume that PC1 should be connected to the internal sensor of the STM.
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: ADC1 configuration

Post by Nemesis2065 »

Hi,

It's now working !
I suppressed the Sensor and VREF channel, and also augmented the ADC_GRP1_BUF_DEPTH to 512 instead of 4.
I don't know well why this config is better, but it's better :D

Here is my new config:

Code: Select all


#define ADC_GRP1_NUM_CHANNELS   2
#define ADC_GRP1_BUF_DEPTH      512

adcsample_t ADC_Samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];

const ADCConversionGroup adcgrp1_cfg =
{
    FALSE,
    ADC_GRP1_NUM_CHANNELS,
    NULL,
    adc_error_cbk,
    0,
    ADC_CR2_SWSTART,
    ADC_SMPR1_SMP_AN14(ADC_SAMPLE_56) |
    ADC_SMPR1_SMP_AN15(ADC_SAMPLE_56) |,
    0,
    ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
    0,
    ADC_SQR3_SQ2_N(ADC_CHANNEL_IN15) |
    ADC_SQR3_SQ1_N(ADC_CHANNEL_IN14)
};
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ADC1 configuration

Post by Giovanni »

The depth of the buffer should not make a difference.

Giovanni
Post Reply