analog to digital converter MCF52259 with MQX v3.6

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

analog to digital converter MCF52259 with MQX v3.6

Jump to solution
821 Views
drummer
Contributor IV

Does anyone know what, in the ADC_INIT_CHANNEL_STRUCT does "number of samples" and "circular buffer size"

do?

Here is my set - up:

I copied it from the examples given.
 

const ADC_INIT_CHANNEL_STRUCT adc_channel_vinp =
{
ADC_SOURCE_AN7, /* physical ADC channel */
ADC_CHANNEL_MEASURE_ONCE| ADC_CHANNEL_START_TRIGGERED , /* runs continuously after IOCTL trigger */
10, /* number of samples in one run sequence */
0, /* time offset from trigger point in us */
A2D_PERIOD_US, /* period in us (= 0.5 sec) */
0x10000, /* scale range of result (not used now) */
10, /* circular buffer size (sample count) */
ADC_TRIGGER_8, /* logical trigger ID that starts this ADC channel */
#if MQX_USE_LWEVENTS
&evn_vinp
#endif
};

 

I find that my results are "noisy". I was wondering (hoping) if this is some sort of filter.

0 Kudos
1 Solution
367 Views
trailman
Contributor V

Hi,

 

As I understand you have some noise on the ADC input and would like to aveage several sample to get better results (even if the best would be to add a low pass filter on the input)

 

You're right, I did not found any info in the docs (including MQXIOUG.pdf), but the BSP source code is available, so I had a look to the BSP sources (version 3.7) :

mqx/source/io/adc/adc.c

mqx/source/io/adc/adc.c

mqx/source/io/adc/mcf522xx/adc_mcf522xx.c

(located under C:\Program Files\Freescale\/Freescale MQX 3.7 on Windows)

As I understand I would say the driver works as follows :

 

I already used ADC on MCF52259 but used 1 for both parameters (only one sample, with buffer of one entry), and got the results using a read() with a pointer to an ADC_RESULT_STRUCT variable.

 

If you use a greater value for these paramaters (I guess you should use the same value for both parameters), the ADC driver will perform several samples and put the results in the buffer (one result per buffer entry).

Instead of using read() with a pointer to an ADC_RESULT_STRUCT variable, you use a pointer to an array of ADC_RESULT_STRUCT values.

The return value of read() is the size of data read in bytes, so the actual number of samples should be return_value/sizeof(ADC_RESULT_STRUCT)

 

Anyway, at the end, you have to compute the average value from the samples you got.

 

Alternatively, there's also an ADC_CHANNEL_ACCUMULATE option that sums the value of all samples in the same variable but I don't jnow how to get this value. So I don't know how to use it.

View solution in original post

0 Kudos
2 Replies
368 Views
trailman
Contributor V

Hi,

 

As I understand you have some noise on the ADC input and would like to aveage several sample to get better results (even if the best would be to add a low pass filter on the input)

 

You're right, I did not found any info in the docs (including MQXIOUG.pdf), but the BSP source code is available, so I had a look to the BSP sources (version 3.7) :

mqx/source/io/adc/adc.c

mqx/source/io/adc/adc.c

mqx/source/io/adc/mcf522xx/adc_mcf522xx.c

(located under C:\Program Files\Freescale\/Freescale MQX 3.7 on Windows)

As I understand I would say the driver works as follows :

 

I already used ADC on MCF52259 but used 1 for both parameters (only one sample, with buffer of one entry), and got the results using a read() with a pointer to an ADC_RESULT_STRUCT variable.

 

If you use a greater value for these paramaters (I guess you should use the same value for both parameters), the ADC driver will perform several samples and put the results in the buffer (one result per buffer entry).

Instead of using read() with a pointer to an ADC_RESULT_STRUCT variable, you use a pointer to an array of ADC_RESULT_STRUCT values.

The return value of read() is the size of data read in bytes, so the actual number of samples should be return_value/sizeof(ADC_RESULT_STRUCT)

 

Anyway, at the end, you have to compute the average value from the samples you got.

 

Alternatively, there's also an ADC_CHANNEL_ACCUMULATE option that sums the value of all samples in the same variable but I don't jnow how to get this value. So I don't know how to use it.

0 Kudos
367 Views
drummer
Contributor IV

Thanks for your help.

The noise problem was solved with a value of 1 in each parameter.

0 Kudos