STM32F373 SDADC returns garbage

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

Moderator: RoccoMarco

Post Reply
Vooon
Posts: 15
Joined: Tue Feb 01, 2011 11:13 pm

STM32F373 SDADC returns garbage

Post by Vooon »

I'm trying to use SDADC on my board with STM32F373CB.

Analog inputs on PB0 (AIN6P), PB1 (AIN5P) connected to external pullup resistor, PB2 (AIN4P) to Vbat divider (1/3).
It does not matter closed inputs to ground or power, the result is always:

Code: Select all

SDADC1: 64092 32767 32767 
SDADC1: 32767 32767 32767
SDADC1: 64128 32767 32767
SDADC1: 64390 32767 32767


Configuration:

Code: Select all

/* V bat, engine therm 1 & 2 (OIL) */
static const ADCConfig sdadc1cfg = {
   .cr1 = 0,
   .confxr = {
      SDADC_CONFR_GAIN_1X | SDADC_CONFR_SE_ZERO_VOLT | SDADC_CONFR_COMMON_VSSSD,
      0,
      0}
};

static const ADCConversionGroup sdadc1group = {
   .circular = TRUE,
   .num_channels = 3,
   .end_cb = adc_term_oilp_vbat_cb,
   .error_cb = adc_error_cb,
   .u.sdadc = {
      .cr2 = SDADC_CR2_JSWSTART,
      .jchgr = SDADC_JCHGR_CH(6) |
         SDADC_JCHGR_CH(5) |
         SDADC_JCHGR_CH(4),
      .confchr = {
         SDADC_CONFCHR1_CH6(0) |
            SDADC_CONFCHR1_CH5(0) |
            SDADC_CONFCHR1_CH4(0),
         0
      }
   }
};


ISR & thread run:

Code: Select all

static adcsample_t term_oilp_vbat_samples[3];

static void adc_term_oilp_vbat_cb(ADCDriver *adcp ATTR_UNUSED,
      adcsample_t *buffer, size_t n ATTR_UNUSED)
{
   //sma_insert(&m_term, buffer[0]);
   //sma_insert(&m_oilp, buffer[1]);
   //sma_insert(&m_vbat, buffer[2]);
   /* SAME */
   palTogglePad(GPIOE, GPIOE_STARTER);
}

static void adc_error_cb(ADCDriver *adcd ATTR_UNUSED, adcerror_t err ATTR_UNUSED)
{
   //alert_component(ALS_ADC, AL_FAIL);
}

THD_FUNCTION(th_adc, arg ATTR_UNUSED)
{
   /* SDADC1 */
   adcStart(&SDADCD1, &sdadc1cfg);
   adcSTM32Calibrate(&SDADCD1);

   /* Start continous conversions */
   adcStartConversion(&SDADCD1, &sdadc1group, term_oilp_vbat_samples, 1);

   while (true) {
      chThdSleepMilliseconds(1000);
      //debug_printf(DP_DEBUG, "SDADC1: temp: %d oilp: %d vbat: %d",
      //      sma_get(&m_term),
      //      sma_get(&m_oilp),
      //      sma_get(&m_vbat));
      debug_printf(DP_DEBUG, "SDADC1: %6d %6d %6d",
            term_oilp_vbat_samples[0],
            term_oilp_vbat_samples[1],
            term_oilp_vbat_samples[2]);

      /* notify ADC running */
      //alert_component(ALS_ADC, AL_NORMAL);
   }
}


At that gpio outputs meander near 2.8 kHz.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F373 SDADC returns garbage

Post by Giovanni »

Hi,

There are several ways to configure the SDADC inputs, are you sure you are using the right way? see the RM for details, I remember it was quite complex.

Giovanni
Vooon
Posts: 15
Joined: Tue Feb 01, 2011 11:13 pm

Re: STM32F373 SDADC returns garbage

Post by Vooon »

I checked the configuration, everything seems right (link to my board.h).
I also tried to use ADC1 on PB0, and obtained a normal result.

Later I will try to do a test with ST perith library.
Vooon
Posts: 15
Joined: Tue Feb 01, 2011 11:13 pm

Re: STM32F373 SDADC returns garbage

Post by Vooon »

I tested SDADC library from ST, and it worked.
It turned out that I was not correctly interpreted the raw data.
After reading AN4207 I added conversion to volts, and got the expected values​​.
So in ChibiOS SDADC hal no errors.

Conversion function (SE Zero mode), perhaps useful to someone:

Code: Select all

#define SDADC_VREF 3.3
#define SDADC_GAIN 1
float sdadc_to_volts_se_zero(adcsample_t adc)
{
   return (((int16_t) adc) + 32767) * SDADC_VREF / (SDADC_GAIN * 65535);
}
Post Reply