2

I'm working on a project that requires the use of a microcontroller, and for this reason, I decided to use the Beaglebone Black. I'm still new to the Beaglebone world and I'm facing some problems that I hope you guys can help me with.

In my project I will have to continuously read from all the 7 analog read pins and do some processing accordingly. My question is, what will be the fastest programming language to do so (I must read as much samples as possible and in a very short time!) and how to increase the sampling rate from KHz to MHz?

I tried the following codes:

Javascript Code:

var b = require('bonescript');//this variable is to refer to my beaglebone
time = new Date();
b.analogRead("P9_39");
console.log(new Date() - time);

this code will simply perform one analog read and will print out the time needed to perform the read. Surprisingly, the result was 111ms!! which means that my sampling rate is 10 if I'm not wrong.

An alternative was to use pyhton:

import Adafruit_BBIO.ADC as ADC
import time

ADC.setup()
millis = int(round(time.time() * 1000))
ADC.read_raw("P9_39")
millis = millis = int(round(time.time() * 1000)) - millis
print millis

this code took less time (4ms) but still, if I wanted to read form the 7 analog input pins, I will only be able to read around 35 samples from each.

Using the terminal:

echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
time cat /sys/devices/ocp.3/helper.15/AIN0
############OR############
time cat /sys/devices/ocp.3/44e0d000.tscadc/tiadc/iio\:device0/in_voltage0_raw 

and this took 50ms.

I want my sampling rate to be something in MHz. How can I do so? I know that the Beaglebone Black is capable of that but I could not find a clear way to do so. Any help is appreciated. Thanks in advance.

2 Answers 2

8

Sampling rate of AM335x ADC is 200K (link). This means you won't get into MHz range with stock BeagleBone Black ADC.

To get something working with a latency of 5 µs in non-real-time OS like Linux is impossible. You will be at a mercy of OS to schedule your execution thread. Other kernel threads will take priority and will preempt your thread, even if you assign it the highest scheduling priority.

From my experience with digital IO on BeagleBone Black, I stated seeing missed frames starting around 1K samples per second. Now, it will depend on your level of tolerance to missing samples -- if you only need working semi-reliably you can probably squeeze out 10 K samples per second by switching to C/C++ and increasing priority of your process with nice --10 ... command. However if you cannot tolerate missed frames, you have to do one of these:

  1. Bypass OS entirely and write C program for naked AM335x processor (no OS).
  2. Use another hardware -- an ADC with a buffer to accumulate samples while your program is preempted.
  3. Use PRUSS processors on BBB. They run at 200 MHz, so if you have a tight loop with e.g. 20 assembly instructions you will get reliable sampling rate of 10 MHz. That is if you had a faster ADC in the first place, and of course it would handle the stock 200 KHz ADC easily.

I personally went with option #3 and was happy to see my device perform sub-millisecond GPIO operations extremely reliably.

5
  • Thank you sir. ANy code and a How to please? Thanks. Sep 13, 2014 at 6:35
  • @user3787524, I would start by searching for any existing PRUSS library. Libpruio sounds promising, but I never used it. If you cannot find something that suits your requirements, you will have to code it all up in PRUSS assembler. I did it in assembler with C++, using prussdrv user mode library from TI, which is relatively straightforward, although debugging PRUSS assembler code was painful.
    – seva titov
    Sep 13, 2014 at 17:53
  • any How To tutorials? or steps to know how to do so? Sep 13, 2014 at 17:57
  • @user3787524, I cannot find a link I was using (it was a year ago), but a google search for 'prussdrv programming' gets few tutorials with step-by step instructions.
    – seva titov
    Sep 13, 2014 at 18:05
  • 2
    The newest documentation from TI claims a 24MHz clock for the ADC, which bumps the theoretical maximum read speed up to 1.6M samples/sec.
    – Gladclef
    Aug 29, 2017 at 3:01
0

Use 127 beaglebone blacks plugged into 127 usb hub ports and breakout visual basic and write a usb program to automatically sequencially fire 127 beagle bones 1 after the other and read the data in a textbox...You will get around 16 mhz / msps consective adcs per fast cpu with say windows 10....lyj2021 You may have over lapping data...But you can track this with each fire of each beagle bone black...consecutively...

1
  • To get mhz frequencies you need to argue with the fcc cause they are the ones limiting adc communications...so are the major os creators and chip manufacturers....You need to redesign all this stuff then you can hack signals....And you might be able to rig up an oscilloscope with usb and large memory depth to record fast samples....Until you can actually build this stuff from scratch , they wont let you have a large bandwidth...Its all encrypted and locked up....lyj2021 Aug 11, 2021 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.