Algorithm for Flexible Data Acquisition Systems - Page 1
Forum section: electronics / projects

author: johnmx
author_rank: Frequent Contributor
timestamp: April 18, 2015, 08:03:04 pm
content: The idea of this topic is to discuss the best algorithm for a data acquisition system based on microcontrollers. Because all projects are different, I think is more important the flexibility rather than speed efficiency. In this way, it should be easier to reuse the code, or part of it, from one project to another.So the algorithm should follow the following rules:1st– Code flexibility2nd– Speed efficiencyThe algorithm must be valid for a simple 1-input/1-output system and also for a multi-input/multi-output system.In my opinion a good acquisition system should do the following:- All acquisition should be done inside interrupt routines (ISR)- The data should go into temporary buffers- The data should be processed in the main code (not inside the ISR)- The output of the data should be done inside ISR’s whenever possibleOne important thing here is how to implement and handle the temporary buffers. For a simple project this may be very basic, but for a complex project it is not so easy.You may take for example this project:- 2 inputs from an external ADC- 1 input from the internal ADC- 1 input from an external temperature sensor- 3 outputs: SD card, Wireless and a serial portAll the input data should go to all the three outputs preferably without data loss.One problem to be solved is how the buffers will handle the 3 different outputs rates. The serial port works at a fixed rate, the SD card writing is usually fast but the SD card controller may take a lot of time to find a new free page and finally the wireless connection may suffer temporary communication errors, e.g. due to external electromagnetic noise.What do you think is the best way to implement this?Use circular buffers, one for each input. But how to handle the 3 different outputs?Use one circular buffer for each input and also for each output, and the main code should copy the data from one buffer to the other?Thanks

author: ivaylo
author_rank: Frequent Contributor
timestamp: April 19, 2015, 05:39:37 am
content: Sounds like you are talking about a single MCU system, yet this:Quoteimplies something much more scalable. If you allow for multiple MCUs the solutions will be vastly different.

author: daedalus
author_rank: Regular Contributor
timestamp: April 19, 2015, 08:56:42 pm
content: you might want to take a look at the etherCAT standard, that's doing multi-input multi-output distributed control, using an Ethernet based link between slave microcontroller nodes.

author: johnmx
author_rank: Frequent Contributor
timestamp: April 19, 2015, 09:49:30 pm
content: What I look for is a general algorithm for a single microcontroller project like this 3 block system:Acquition -> Data processing -> Data outputI have done several acquisition systems in the past and I always optimize the code for speed. This makes very difficult to reuse the code between project changes or new projects.

author: JuKu
author_rank: Frequent Contributor
timestamp: April 19, 2015, 11:18:04 pm
content: > Use one circular buffer for each input and also for each output, and the main code should copy the data from one buffer to the other?This. The input routine shouldn't know or care where the data needs to go. Also, an RTOS isn't a bad idea.

author: nctnico
author_rank: Super Contributor
timestamp: April 20, 2015, 12:09:55 am
content: Look at how Gstreamer solves this problem. It uses components with one or more sinks (input) and one or more sources (outputs). I think this is a place where an object oriented approach will shine. However don't expect this to be efficient! The best way is still to sample everything using the highest required samplerate (but not necessarily sample everything at this rate; you can skip 'ticks') as a time reference and do the processing inside the ISR.