Fast Signal Sampling (Part 4)

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

Once again, I decided to gather all the scanning engine code in one library (PlainDAC). This is the link to the library, and below is the example code from the library which shows how easy it is now to acquire wave signals with excellent time interval accuracy:

Example of use of the PlainDAC Library
No warranty, no claims, just fun
Didier Longueville invenit et fecit October 2010

PlainDAC DAC = PlainDAC(); // Create DAC object
const uint16_t samples = 128; // Max value depends upon available memory space
uint16_t frequency = 32000; // From 16 Hz to 64 kHz
uint8_t vData[samples];
uint8_t channel = 0; // From 0 to 5 on Diecimila

void setup(){  
	// Initialize serial comm port
	Serial.begin(115200); // 
	// Set acquisition parameters
	DAC.setAcquisitionParameters(channel, samples, frequency);
	// For curiosity
	Serial.print("adcPrescaler: ");
	Serial.println(DAC.adcPrescaler(), DEC);
	Serial.print("timPrescaler: ");
	Serial.println(DAC.timPrescaler(), DEC);
	Serial.print("timUpperCount: ");
	Serial.println(DAC.timUpperCount(), DEC);

void loop() {

void printVector() {
	double timeIntervals = (1.0 / frequency);
	for (uint16_t i = 0; i < samples; i++) {
		Serial.print((timeIntervals * i), 6);
		Serial.print(" ");
		Serial.print((((vData[i] - 128) * 5.0) / 256) , 2);

This is obviously a basic application, that you may feel free to improve. You are kindly invited to leave your comments on it!

Next post on same subject


  1. Tarek says:

    plaindac.h is not in the arduino programming language, where to get that?

  2. admin says:

    You may get PlainDAC.h, PlainDAC.cpp and all other files related to the Data Acquisistion library from the download area (@

  3. girlvslaser says:

    This code, along with the PlainFFT library, is immensely helpful! I’ve already got it all up in running with my little project in its simplest embodiment. I can’t get over how helpful your blog is. Thanks a bunch.

    If one wanted to acquire data on two separate pins, what would your approach be? I have two inputs, and I’d really like to know what my inputs are relative to each other (so that I can extract both frequency and relative phase data), so It would be handy if I could acquire the data all at once without resetting the timers. But looking at this, I can’t quite determine if that would be possible. Of course, I am a complete novice when it comes to programming. Could I add a line that tells it “Oh, and while you’re add it, read this pin too (with the same sampling frequency and number of samples) and throw that information into an additional vector”?

Leave a Reply

You must be logged in to post a comment.