Fast Signal Sampling (Part 6)

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

So far, the PlainADC library was able to generate unsigned 8 bits, unsigned 16 bits or unsigned 10 bits (encoded) data. While these formats are very convenient for storing the largest amounts of data, they are uneasy to interface with applications which make use of double formated data. The gap is bridged now thanks to the latest revision of the PlainADC library. Care must be taken with the size of vectors, because double formated value use four times more room than bytes.

The library uses now four types of storage modes and it is NOT compatible with the previous version:

#define ADC_ACQ_MOD_UINT8 0 /* 8 bits mode */
#define ADC_ACQ_MOD_UINT16 1 /* 16 bits mode, stored in 2 bytes */
#define ADC_ACQ_MOD_DEL_ENCODING 2 /* 10 bits mode, delta encoding */
#define ADC_ACQ_MOD_DOUBLE 3 /* 32 bits double format */

Data are still stored in bytes arrays, so that some sort of conversion must me used in order to get the double formated value. Firstly, you will need to declare a union type variable in order to map the double formated value and the array of bytes:

union mappedVar {
 uint8_t buffer[4];
 double value; 
} mapped; 

And secondly you will need a little converting routine in order to read the data from the vector of data. In this way:

		for (uint8_t j = 0; j < 4; j++) {
			mapped.buffer[j] = vData[(i << 2) + j];
		Serial.print(((mapped.value * 5.0) / 1024.0) , 4);

Or in this other (nicer) way:

memcpy((uint8_t*)&mapped.buffer, (uint8_t*)&vData[(i << 2)], sizeof(mapped.buffer)); 
Serial.print(((mapped.value * 5.0) / 1024.0) , 4);

Please check this page if you are interested in the code.. It contains many new features which will ease the interfacing with other applications: you fill find "how to" by checking the example sketches.

Next post on same subject


  1. […] Next post on same subject Tags: Data acquisition, Programming, Sensors, Sound capture Comment (RSS)  |  Trackback […]

Leave a Reply

You must be logged in to post a comment.