BBB Libpruio Analog Data

45 views
Skip to first unread message

Ritesh Bhatt

unread,
Mar 9, 2021, 3:15:01 PM3/9/21
to BeagleBoard
Hello! I'm a graduate student working with a BBB trying to collect analog data from some sensors through the onboard PRUs (we need high sampling rate on the order of 20kHz since it's a frequency based experiment). I'm working with code from previous students that worked on this project and they used Libpruio to accomplish this. Specifically, they are collecting the data using Ring Buffer mode and saving it to a text file to be processed further for some feature extraction and further analysis.

What I'm trying to understand is this: how does Ring Buffer sampling actually work? As in, if I'm reading data using two analog inputs and saving it to a text file, what order are the values in? How do I parse them into meaningful sensor values? I've attached the C code I'm working with, and greatly appreciate any help or pointers!
readTwoADCChannel.c

TJF

unread,
Mar 10, 2021, 2:26:30 PM3/10/21
to BeagleBoard
Hi!

ritesh...@gmail.com schrieb am Dienstag, 9. März 2021 um 21:15:01 UTC+1:
Specifically, they are collecting the data using Ring Buffer mode and saving it to a text file to be processed further for some feature extraction and further analysis.

What I'm trying to understand is this: how does Ring Buffer sampling actually work? As in, if I'm reading data using two analog inputs and saving it to a text file, what order are the values in? How do I parse them into meaningful sensor values? I've attached the C code I'm working with, and greatly appreciate any help or pointers!

Your code doesn't save to a text file. Instead it saves the raw data to a binary file. The unshifted values (0-4095) are stored as 16-bit (unsigned short) binary numbers in the order as captured, like

AIN-1, AIN-2, AIN-1, AIN-2, AIN-1, AIN-2, AIN-1, AIN-2, ...

In order to parse the file, just read it into a buffer and access that buffer by a unsigned short pointer variable. 0 (null) means 0V, 4095 means 1V8. So multiply the unsigned shorts by the factor 1.8/4095 to get the voltage as a real value.

Ritesh Bhatt

unread,
Mar 11, 2021, 11:31:31 AM3/11/21
to BeagleBoard
Hello TJF,

Thank you for the explanation that is very useful! With parsing the file, I'm doing that in Node-Red reading in the file as a binary buffer, but for some reason the buffer is 4x the number of sampling points I set. Like let's say I tell the script to sample the analog inputs 5000 times, the file will come back with 20000 when I read it into Node-Red (I'd expect 10000 points since I'm using 2 analog inputs). What could be the cause?

Thanks!

TJF

unread,
Mar 14, 2021, 7:12:39 AM3/14/21
to BeagleBoard
16 bit = 2 byte!

Parsing the buffer in JavaScript code:

const val = new Uint16Array(Buffer); // val.length = 10000 (2 channels x 5000 samples)

// output raw data: integer from 0 (=0V) to 4095 (=1V8)
console.log(val[0], val[1]); //  first samples AIN-1, AIN-2
console.log(val[2], val[3]); // second samples AIN-1, AIN-2
...

// output voltage: foating point from 0.0 V to 1.8 V
const f = 1.8 / 4095;
console.log(f*val[0], f*val[1]); //  first samples AIN-1, AIN-2
console.log(f*val[2], f*val[3]); // second samples AIN-1, AIN-2
...

Reply all
Reply to author
Forward
0 new messages