Beaglebone black – ADC

Beaglebone black – ADC – Getting started

These are the quick exact steps I’ve personally used in order to experiment with the Beaglebone black – ADC. The process I used to setup the Linux image is exactly as demonstrated here. Including the kernel version shown at the beginning.

Check that the ADC device tree file exists

If the output from the above command does not come back with “BB-ADC-00A0.dtbo”, then the steps shown here are required. I would also recommend using the same kernel, if you need to follow the steps in this article, exactly.

Load ADC device tree file
Check to see if the ADC device tree file loaded
Check to make sure module is loaded
Inspect the ADC sysfs pseudo file structure
ADC one-shot mode
Writing a simple ADC test application
Source code
Compile the Source code
Run the application with time

That is it for this short demonstration. To be sure, the ADC can also operate in continuous mode. This is something that I have not personally experimented with, but perhaps will at a later date. According to what I’ve read however, continuous mode will only achieve ~4k ~10k samples a second from userspace. ~4k is what I’ve read for one-shot mode. However(again), those figures were from a couple of years ago, and many improvements have been made between kernels 3.8.x, and 4.1.x. Most noticeably to me, the kernel is much more responsive. With that said, it is doubtful that the people who wrote the information I’ve read used fork() on multiple channels simultaneously. Which I think could improve the sampling rate *somewhat*. I would really need to test by running an infinite loop, and check process stats. As I’m fairly sure what I have now, is using a lot of CPU. Another aspect to consider is that the kernel I’ve used for this demonstration is a TI RT kernel. Which should offer reduced latency. Whether or not that applies to this situation, I have yet to test . . . Happy Beagling !!!

Update: The code above is modified from the original, in that when running continuous, the executable after about 30 seconds would exit with error: Resource temporarily unavailable. The quick fix was as shown above. But essentially, if(len == -1) {close(fd); continue;} which tests for len == -1, and if true, closes the file descriptor, then execution jumps back to the top of the loop. As written and run for 300,000 iterations. The sample rate is about 2960 *exactly* 4997 samples a second( my initial math was *way* off. CPU load was at around 77%, so not much in the way for improvement I think when using one-shot mode. I’ve been reading on and off all day on the subject, and found a good bit of information. It seems, if a major improvement is needed. That the PRU’s will have to be involved. No real surprises there, but was hoping to eek out a little more performance . . .

Update #2: I’ve since changed to a non TI kernel, but is other wise similar. Kernel version is 4.1.9-bone-rt-r16, and is in RCN’s APT repo. When running the code again for 300,000 iterations. I get 5235 samples a second. When commenting out the printf() statements in the main code loop. I get 5890 samples a second. That’s an ~11-12% difference in samples! For what it is worth. CPU load is also solid at 93%.

Beaglebone black – ADC

One thought on “Beaglebone black – ADC

  • December 12, 2015 at 6:41 pm

    Thanks for this, I wrote some C++ code for this the over a year ago, but had to stop working on the BeagleBone Black. This helps me get back into it with the /sys/ changes.

Comments are closed.