cancel
Showing results for 
Search instead for 
Did you mean: 

SPC560D30L3 - ADC states

ssk
Associate II
Posted on March 18, 2015 at 15:55

Hello,

I am trying to use the ADC driver (ADCD2) for SPC560D30L3 device using Discovery kit (I have replaced SPC560D40 with SPC560D30 MCU). I am trying to implement a state machine using different states of ADC driver. If my understanding is correct, I shall access the states as below,

switch (ADCD2.state)

{

case ADC_UNINIT:

break;

case ADC_STOP:

break;

case ADC_READY:

break;

case ADC_ACTIVE:

break;

case ADC_COMPLETE:

break;

case ADC_ERROR:

break;

}

If above way is correct the statement 'ADCD2.state' itself is not working! Can anybody clarify the issue? What other settings are required?

Thanks in advance for your help.

Mike.

#adc
11 REPLIES 11
Erwan YVIN
ST Employee
Posted on March 18, 2015 at 16:17

Hello Mike ,

if you try to intercept all the states of your ADC Driver to update them..

In order to be generic, i advice you to patch or create adc.c/adc.h  (using the patch mode) to update your own states machines.

Maybe you can send your application examples .

               Best regards

                                  Erwan

ssk
Associate II
Posted on March 18, 2015 at 16:23

Hello Erwan,

Thanks for reply. Can you please explain how to use the patch mode? Whcih document I need to refer for understanding the patching?

Thanks.

Mike.

Posted on March 19, 2015 at 09:07

Hi Mike,

Why are you trying to read the driver states? under normal circumstances this should not be required.

Giovanni

ssk
Associate II
Posted on March 19, 2015 at 10:15

I have 3-4 ADC channels configured for measurements. Based on the app requirement, I will initiate all or individual channel measurements (i.e. ADC_Start_Conversion). The main function will follow the ADC states to know when to stop the ADC and do the measurements (ie.e ADC_Stop_Conversion). This is my requirement. Can you please elaborate how I can make use of different driver states/flags to implement this?

Thanks in advance.

Mike.
Posted on March 19, 2015 at 16:09

Hi,

Unless you are using a circular buffer you don't need to stop conversions.

The function adcConvert() returns after the conversion is finished, no need to synchronize.

The function adcStartConvert() starts the conversion and gives you a callback on conversion finish (and it stops there unless you used a circular buffer).

Giovanni

ssk
Associate II
Posted on March 26, 2015 at 14:01

That means I can (or need to) write separate callback for each ADC channel configured? And using each callback, I can collect ADC data when I initiate conversion for respective channel using adcStartConvert(). Is my understanding correct?

Thanks.

Mike.

Erwan YVIN
ST Employee
Posted on March 27, 2015 at 11:21

Hello Mike ,

You can write (not mandatory) some separate callbacks for each ADC Channel by the configurator

(Cf screenshot).

If your ADC configuration is in

circular mode, no need to restart the conversion.

it is automatically restarted.

Best Regards

Erwan

________________

Attachments :

2015-03-27_110731.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0HK&d=%2Fa%2F0X0000000bZM%2FNSUhw1TF4b_l3DYaz.PcpTuDeexHO0uk_CsRPPBI3fA&asPdf=false
ssk
Associate II
Posted on April 22, 2015 at 12:51

Hello Erwan,

Referring to below mail, I have configured an ADC channel for SPC560D30L1. I am using linear buffer with maximum sequential set to 1. I have configured the callbacks to read the ADC count and to convert it to voltage value. Here, I have observed that ADC conversion is required to be initiated (ADC_Start_Conversion) in order to read the new input value. I am doing this on a key press. How can I configure the ADC for continuous read and get the updated count value when input changes? 

Please note that I have 3-4 more ADC channels independent of each other where I required similar functionality. How to implement this?

Thanks in advance for your help.

Mike.

Please find below the callbacks,

/*

 * ADC streaming callback, the name is defined in the ADC graphic

 * configuration.

 */

size_t nx = 0, ny = 0;

void ADC_conversion_callback (ADCDriver *adcp, adcsample_t *buffer, size_t n)

{

  (void)adcp;

  if (samples == buffer)

  {

    nx += n;

  }

  else

  {

    ny += n;

  }

  g_adc_val = samples[0];

  g_adc_vol = ((5.0/4096)*g_adc_val);

}

/*

 * ADC error callback, the name is defined in the ADC graphic

 * configuration.

 */

uint32_t errore = 30;

void ADC_error_callback (ADCDriver *adcp, adcerror_t err)

{

  (void)adcp;

  errore = err;

  osalSysHalt(''ADC failure'');

}

Erwan YVIN
ST Employee
Posted on April 22, 2015 at 13:44

Hello Mike ,

yes for a linear buffer you should

re-start the conversion

after each ADC Conversion.

Maybe you should switch to the circular mode no need to restart the conversion

with maximum sequential set to 1 , it should be the latest value.

  • Linear Buffer, the driver performs a series of groupconversions then stops. This mode is like a one shot conversion repeatedN times, the buffer pointer increases after each conversion. The bufferis organized as an S(CG)*N samples matrix, when S(CG) is the conversiongroup size (number of channels) and N is the buffer depth (number ofrepeated conversions).
  • Circular Buffer, much like the linear mode but the operationdoes not stop when the buffer is filled, it is automatically restartedwith the buffer pointer wrapping back to the buffer base.
if you want to display the updated value after a key press i advice to use a External IRQ easy to configure

or use a example cf ChibiOS-RT SPC560Dxx ADC Test Application for Discovery.

   Best regards

                 Erwan