Page 1 of 2
Differential ADC
Posted: Mon Nov 10, 2014 7:29 pm
by antd_a
Hi everybody!
I am a newbie in using ChibiOS and I would need to use the ADCs of my STM32F3DISCOVERY board in differential mode.
Reading the microcontroller reference manual, I understood what should happen at low level to do so. Anyway crossing these info with the ADC driver written in ChibiOS, it seems to me that it has not been implemented this function yet.

Am I right? I hope no... If so, can anyone help me to use this function?
Thanks in advance,
Antonio.
Re: Differential ADC
Posted: Mon Nov 10, 2014 8:15 pm
by Giovanni
Hi,
The driver should work as-is, differential or single ended makes no difference. You must setup the DIFSEL register after starting the driver but before starting a conversion. See the STM32 Reference Manual for details.
Giovanni
Re: Differential ADC
Posted: Wed Nov 12, 2014 1:14 am
by antd_a
Hi Giovanni,
and thanks for your reply.
I tried to follow your suggestion and I wrote this simple code for testing:
Code: Select all
#include "ch.h"
#include "hal.h"
#define ADC_NUM_CHANNELS 1
#define ADC_BUF_DEPTH 128
static adcsample_t ADCsamples[ADC_NUM_CHANNELS*ADC_BUF_DEPTH] = {0};
static uint32_t average = 0;
static const ADCConversionGroup adcgrpcfg =
{
FALSE,
ADC_NUM_CHANNELS,
NULL,
NULL,
ADC_CFGR1_RES_12BIT, /* CFGR */
ADC_TR(0, 4095), /* TR1 */
ADC_CCR_CKMODE_ADCCK, /* CCR */
{ /* SMPR[2] */
ADC_SMPR1_SMP_AN2(ADC_SMPR_SMP_1P5),
0
},
{ /* SQR[4] */
ADC_SQR1_SQ1_N(ADC_CHANNEL_IN2),
0,
0,
0
}
};
int main(void)
{
int i = 0;
halInit();
chSysInit();
palSetGroupMode(GPIOA, PAL_PORT_BIT(1) | PAL_PORT_BIT(2), 0, PAL_MODE_INPUT_ANALOG);
adcStart(&ADCD1, NULL);
ADC1->DIFSEL = ADC_DIFSEL_DIFSEL_1;
adcConvert(&ADCD1, &adcgrpcfg, &ADCsamples[0], ADC_BUF_DEPTH);
for (i = 0; i < ADC_BUF_DEPTH; i++)
{
average = average + ADCsamples[i];
}
average = average/ADC_BUF_DEPTH;
while (TRUE)
{
chThdSleepMilliseconds(1);
}
return 0;
}
I expected to be able to convert the voltage drop between pins PA1 (channel 2 of ADC1) and PA2 (channel 2 of ADC1), but it does not work. It just converts the voltage drop between pins PA1 and GND, as in single-ended mode. I tried to move the DIFSEL setting before "adcStart", but with the same result.
Have you any idea about what can be wrong? Is the way I set DIFSEL right? (building the project does not return any error or warning)
Thank you in advance...
Re: Differential ADC
Posted: Wed Nov 12, 2014 9:39 am
by Giovanni
Not sure, never used the differential mode but it is just matter of enabling it. Are you sure you are using the right DIFSEL bit?
Giovanni
Re: Differential ADC
Posted: Thu Sep 10, 2015 10:23 am
by neums
Hello,
will there be a possibility to set up the differential mode with the ADCConversionGroup in future?
Thanks

Re: Differential ADC
Posted: Thu Sep 10, 2015 6:11 pm
by Giovanni
Hi,
It should be already possible, what do you think is missing?
Giovanni
Re: Differential ADC
Posted: Fri Sep 11, 2015 12:55 pm
by neums
Hello,
i am working with the STM32F303 now. Via ADCConversionGroup defined in adc_lld the ADCx_DIFSEL register is not accessible. You have to initialize this register directly in the ADCD handle which is a possible way but not really a nice way, isn't it?
Re: Differential ADC
Posted: Fri Sep 11, 2015 2:43 pm
by Giovanni
Of course, so I need to add the register to the configuration.
Giovanni
Re: Differential ADC
Posted: Fri Sep 11, 2015 4:15 pm
by antd_a
I think it would be very valued, thanks
Antonio
Re: Differential ADC
Posted: Fri Sep 18, 2015 8:43 am
by neums
Hello,
did you already add this register to the ADCConversionGroup?