ADC Read Two Separate Channels

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

ADC Read Two Separate Channels

Post by daviddawe1982 »

Hello,
What I am trying to do is read two adc channels IN11 and IN15.
I want to read them separately.
Each one reads in its own thread and so far I am using ADCD1 and ADCD2.
My problem is when using the two ADCD's it appears to be resource hungry as my code stops when trying to read the two at the same time but when I only use one ADCD for both (While testing) my code works fine.
Can I read IN11 and IN12 both separately on ADCD1 and save resources?
Or should I not be using threads?
My board is a stm32f4 discovery.
Thank You.
I get this during debug
0x080018ae in chSysHalt (reason=0x8009700 <__func__.7418> "adcStartConversionI") at ../os/rt/src/chsys.c:164
164 ch.dbg.panic_msg = reason;
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ADC Read Two Separate Channels

Post by Giovanni »

You should be able to use both ADCs.

Please post the whole stack trace and the string pointed by ch.dbg.panic_msg, most likely you have a call violation (function called out of proper context).

Giovanni
daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: ADC Read Two Separate Channels

Post by daviddawe1982 »

Well I tried to simplify my code a bit and now i get this..
trace..
Thread [1] <main> (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)
adc_lld_serve_rx_interrupt.lto_priv.102() at adc_lld.c:86 0x800229c
Vector128() at stm32_dma.c:315 0x8001d52
0xffffffec


and this..


The target endianness is set automatically (currently little endian)


Temporary breakpoint 1, main () at main.c:1098
1098 halInit();

No breakpoint number 2.

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0800229c in adc_lld_serve_rx_interrupt.lto_priv.102 (adcp=0x20000ff8 <ADCD2>, flags=32) at ../os/hal/ports/STM32/STM32F4xx/adc_lld.c:86
86 if (adcp->grpp != NULL) {
daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: ADC Read Two Separate Channels

Post by daviddawe1982 »

This Is my code.

Code: Select all

//***********************************//
//ADC SETUP
//***********************************//
#define ADC_GRP1_NUM_CHANNELS   1
#define ADC_GRP1_BUF_DEPTH      10

#define ADC_GRP2_NUM_CHANNELS   1
#define ADC_GRP2_BUF_DEPTH      1
static adcsample_t samples1[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
static adcsample_t samples2[ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH];
/*
 * ADC streaming callback.
 */
size_t nx = 0, ny = 0;


static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {

  (void)adcp;
  (void)err;
}
/*
 * ADC conversion group.
 * Mode:        Linear buffer, 10 samples of 1 channel, SW triggered.
 * Channels:    IN11.
 */
//Coil Sample ADC
static const ADCConversionGroup adcgrpcfg1 = {
  TRUE,
  ADC_GRP1_NUM_CHANNELS,
  NULL,
  NULL,
  0,                        /* CR1 */
  ADC_CR2_SWSTART,          /* CR2 */
  ADC_SMPR1_SMP_AN11(ADC_SAMPLE_112),
  0,                        /* SMPR2 */
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,                        /* SQR2 */
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
};
/*
 * ADC conversion group.
 * Mode:        Linear Buffer, 10 samples of 1 channel, SW triggered.
 * Channels:    IN11, IN12, IN11, IN12, IN11, IN12, Sensor, VRef.
 */
//Battery Level ADC
static const ADCConversionGroup adcgrpcfg2 = {
  TRUE,
  ADC_GRP2_NUM_CHANNELS,
  NULL,
  NULL,
  0,                        /* CR1 */
  ADC_CR2_SWSTART,          /* CR2 */
  ADC_SMPR1_SMP_AN15(ADC_SAMPLE_112),
  0,                        /* SMPR2 */
  ADC_SQR1_NUM_CH(ADC_GRP2_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN15)
};


then starting the adc's

Code: Select all

adcStart(&ADCD1, NULL);
adcStart(&ADCD2, NULL);
adcStartConversion(&ADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);
adcStartConversion(&ADCD2, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);

then I am using two threads to process each of the samples.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ADC Read Two Separate Channels

Post by Giovanni »

Please proceed as follow:

1) Make sure that debug options are enabled in chconf.h: assertions, checks and state checker.
2) The application should halt if something is caught.
3) Retrieve the message pointed by ch.dbg.panic_msg in memory after the halt, it is a string terminated by zero.
4) Get the stack trace from the halted position.

The message will tell you the nature of the problem, the stack trace will tell you where the problem is.

Giovanni
daviddawe1982
Posts: 94
Joined: Thu Apr 11, 2013 10:35 am

Re: ADC Read Two Separate Channels

Post by daviddawe1982 »

Well it turned out to not be the ADC's causing the problem.
I was using the GPT with polled delay as I need a 10us delay in one of the threads and this was causing the problem.
I did try the halPolledDelay but I get a "Undefined reference" error.
I am using chibios 3.0 has it been implemented yet?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: ADC Read Two Separate Channels

Post by Giovanni »

Hi,

halPolledDelay () is no more part of 3.0, now the functionality is in the kernel and is called chSysPolledDelayX().

Giovanni
Post Reply