Fast Signal Sampling (Part 12)

Part 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 11, 12

Too bad Marcel, you experienced an unexpected flaw which drove me to rework the PlainADC library… There was a bug in the data acquisition parameters set and reset mechanism. Also, I reintroduced the single shot acquisition function… nammed at GetSingleUInt16Data and GetSingleDbl32Data. They happen to be very usefull while using combinations of single shot and scan modes of data acquisition, like in MicroCAPM.
The new release of PlainADC features the noise reduction option, and other refinements.

A set of 5 sketches contains various combination of use for the code. What is new too is the serialization of my code packages in order to improve the version tracking. Next is a copy of the user manual content which will give you an idea of PlainADC content and specifications:

Copyright (C) 2012 Didier Longueville

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see .
	
PlainADC library contains a set of functions which are dedicated to signal acquisition. 
These functions have been made versatile enough to cover most of the usual needs. 

Principle of use:
- Set acquisition engine parameters
- Run acquisition engine
- Read acquired data
- Release acquisition engine

Data can be:
- unsigned 16 bits integer
- 32 bits floats

The vector containing data can be user defined or automatically created while setting acquisition engine parameters.
 Care shall be taken with the size of the vector. Arduino processors have a limited amount of ram (up to 2K on ATEMEGA328)

Here are the various options for setting the acquisition engine parameters (from the simplest to the most advanced)

---------------------------------------------------------------------------------------------------
Average(vData, samples)
---------------------------------------------------------------------------------------------------

with:
- vData is a pointer to the vector of doubles containing samples
- samples is the number of samples 

returns:
- average of sample intensities

comments:
- average is equivalent to arithmetic mean


---------------------------------------------------------------------------------------------------
GetDataAddress()
---------------------------------------------------------------------------------------------------

with:
- no parameters

returns:
- pointer to the acquired data. This address is nulled while releasing the acquisition engine

comments:
- none


---------------------------------------------------------------------------------------------------
GetScanData
---------------------------------------------------------------------------------------------------

with:
- no parameters

returns:
- nothing

comments:
- on completion of function, data are available in the data vector as per the acquisition parameter settings 


---------------------------------------------------------------------------------------------------
GetSingleDbl32Data
---------------------------------------------------------------------------------------------------

with:
- no parameters

returns:
- 32 bits float containing the 10 bits from the ADC

comments:
- Data acquisition is performed using the parameters as in SetAcquisitionEngine


---------------------------------------------------------------------------------------------------
GetSingleUInt16Data
---------------------------------------------------------------------------------------------------

with:
- no parameters

returns:
- 16 bits integer containing the 10 bits from the ADC

comments:
- Data acquisition is performed using the parameters as in SetAcquisitionEngine


---------------------------------------------------------------------------------------------------
ReadDbl32Data(sample)
---------------------------------------------------------------------------------------------------

with:
- sample: index of sample within the last acquired vector of data

returns:
- 32 bits double containing 10 bits precision data

comments:
- single channel mode


---------------------------------------------------------------------------------------------------
ReadUInt16Data(sample)
---------------------------------------------------------------------------------------------------

with:
- sample: index of sample within the last acquired vector of data

returns:
- 16 bits integer containing a 10 bits precision data, depending upon the acquisition parameters

comments:
- single channel mode


---------------------------------------------------------------------------------------------------
ReleaseAcquisitionEngine
---------------------------------------------------------------------------------------------------
	
without parameter
returns nothing

comments:
- nulls the destination vector of data


---------------------------------------------------------------------------------------------------
RMS(vData, samples)
---------------------------------------------------------------------------------------------------

with:
- vData is a pointer to the vector of doubles containing samples
- samples is the number of samples 

returns:
- the true root mean square computed over the sample intensities

comments:
- none


---------------------------------------------------------------------------------------------------
SetAcquisitionEngine(adcChannel, refVoltage, samplingFrequency, samples, dataFormat)
---------------------------------------------------------------------------------------------------

with:
- adcChannel: one adc channel, allowed range from 0 to 5
- refVoltage: the adc reference voltage, as per constants ADC_REF_VOL_x in PlainADCS.h
- samplingFrequency: in hertz, check specifications for min and max values
- samples: number of samples acquired during each run
- dataFormat: format of acquired data, as per constants ADC_DAT_FMT_x in PlainADCS.h

returns:
- pointer to the acquired data. This address is nulled while releasing the acquisition engine

comments:
- single channel mode
- you may forget everything about the pointer to the acquired data, if ReadUInt16Data and ReadDbl32Data functions
  are enough for you

  
---------------------------------------------------------------------------------------------------
Constants
---------------------------------------------------------------------------------------------------

Data formats:
- ADC_DAT_FMT_UNDEFINED: undefined
- ADC_DAT_FMT_INT: 16 bits unsigned integer
- ADC_DAT_FMT_DBL : 32 bits double float

Voltage references:
- ADC_REF_VOL_EXTERNAL: As per AREF pin voltage
- ADC_REF_VOL_DEFAULT: VCC, typically 5V
- ADC_REF_VOL_INTERNAL: 1V1 on ATMEGA 168/328

Sampling Frequency:
- ADC_MIN_SMP_FRQ = 0.125 Hz
- ADC_MAX_SMP_FRQ_INT_MODE = 100000.0 Hz
- ADC_MAX_SMP_FRQ_DBL_MODE = 60000.0 Hz

Same procedure as before, the latest code version is available on simple request.

Next post on same subject

Leave a Reply

You must be logged in to post a comment.