Fast Signal Sampling (Part 2)

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

The key components for this piece of code are

  • Acquisition parameter settings
  • Interrupts Service Requests (ISR)
  • Data acquisition function
  • Depending upon the expected sophistication of the code, we may add some more functions, such as

  • Acquisition engine start/stop
  • Smoothing
  • etc.
  • And even more complex ones, e.g. triggering acquisition.

    The list of functions below illustrates the minimal requirements for using the data acquisition engine:

    setAcquisitionParameters(channel, samplesBufferSize, frequency);
    startAcquisitionEngine();
    stopAcquisitionEngine();
    acquireData(*vData);

    The acquisition engine itself uses a token system in order to keep the ISR content as small as possible, using the least number of variables. Here is the “master” function:

    void acquireData(uint8_t *vData) {
    	if (acqEngineStatus == ACQ_ENG_STOPPED) startAcquisitionEngine();
    	// Reset number of acquired samples
    	uint8_t samples = 0;
    	dataAcqStatus = DAT_ACQ_WAITING;
    	// Set acquisition status
    	do {
    		if (dataAcqStatus == DAT_ACQ_TRIGGERED) {
    			// PORTB ^=  (1 << PINB5); // Comment in normal operation mode
    			vData[samples] = adcValue; // Store data
    			samples++; // Increment sample counts
    			dataAcqStatus = DAT_ACQ_WAITING; // Toggle status
    		}
    	} while (samples != _samplesBufferSize);
    	dataAcqStatus != DAT_ACQ_IDLE; // Reset status
    }
    

    And here the "slave" function:

    ISR(ADC_vect){
    // Invoked on completion of conversions
    	//PORTB ^=  (1 << PINB4); // Comment in normal operation mode
    	if (dataAcqStatus == DAT_ACQ_WAITING) {
    		adcValue = ADCH;
    		dataAcqStatus = DAT_ACQ_TRIGGERED;
    	}
    } 
    

    Note: May be you noticed the use of PINB4 and 5 for testing purpose. They should be commented under normal operation mode. However, they were very usefull while checking the accuracy of the sampling time at various frequencies.

    Next post on same subject

    Leave a Reply

    You must be logged in to post a comment.