Fast Signal Sampling (Part 12)

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

I have good news and bad news…

Where shall I start? Bad news? The bad news is that I released a new revision of the PlainADC library that you may have to ask for if you want to get advantage of the good news!

The good news relate to the uprated specifications of the PlainADC library. Whatever the data format choosen, PlainADC is now capable of 0.125 Hz to 130kHz. The past difference between the performances observed while acquiring in 16 bits integers mode and 32 bits floats mode is also responsible for the overall gain in scanning speed which jumps from 100 kHz to 130 kHz. This gain results from a shorten execution time and from the postponed execution of the integer to double cast on completion of the acquisition loop. Plain trivial isn’t it?

This how the acquisition engine looks like now:

void PlainADC::GetScanData(void) 
/* Acquire data from one specific detector (base 0) */
{
	if (_dataAcqStatus == ADC_IDLE) {
		uint8_t originalTIMSK0 = TIMSK0; /* Record timer/counter0 mask */
		uint8_t originalTIMSK2 = TIMSK2; /* Record timer/counter2 mask */
		TIMSK0 = 0x00; /* Disable timer/counter0 */
		TIMSK2 = 0x00; /* Disable timer/counter2 */
		SMCR |= (1 << SE); /* Activate ADC noise reduction mode */
		/* Reset number of acquired samples */
		uint16_t acquiredSamples = 0;
		uint8_t *dataLocation = _vData;
		do {
			/* Set waiting state */
			_dataAcqStatus = ADC_WAITING;
			/* Wait for triggered state */
			while (_dataAcqStatus != ADC_TRIGGERED);
			/* Write data in vector LSB->MSB */
			uint16_t intData = (_adcLSB | (_adcMSB << 8));
			/* Record data in data buffer */
			memcpy(dataLocation, &intData, 2);
			dataLocation += _dataSize;
			/* Update variables */
			acquiredSamples++; /* Increment sample counts */
		} while (acquiredSamples < _samples);
		TIMSK0 = originalTIMSK0; /* Restore timer/counter0 operation */
		TIMSK2 = originalTIMSK2; /* Restore timer/counter2 operation */
		SMCR &= ~(1 << SE); /* Deactivate ADC noise reduction mode */
		/* Stop sequential recording mode */
		_dataAcqStatus = ADC_IDLE; /* Reset status */
		/* Convert data as appropriate */
		if (_dataFormat == ADC_DAT_FMT_DBL) {
			uint16_t UInt16Data;
			double Dbl32Data;
			for (uint16_t i = 0; i < _samples; i++) {
				/* Read 16 bits int data */
				memcpy(&UInt16Data, (_vData + (i << 2)), 2);
				/* Cast data */
				Dbl32Data = double(UInt16Data);
				/* Write 32 bits double data */
				memcpy((_vData + (i << 2)), &Dbl32Data, 4);
			}
		}	
	}
};

The rest of the code is unchanged

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

Leave a Reply

You must be logged in to post a comment.