High speed data sampling using PRU ADC and DMA

I am working on BeagleBone black.
I want to acquire data at high sampling rate (10 kHz) using inbuilt ADC of BB Black. I want to use PRU and DMA of BB Black. I don’t know how to start it.

Regards
MD

1 Like

We are considering using the bbb’s pru for a project, I don’t have any hands on experience with the pru at this point in time. Here is the link to the tree, it has examples.

git clone https://git.ti.com/cgit/pru-software-support-package/pru-software-support-package.git

This is the README from the tree, it looks like its full of examples.

Programmable Real-time Unit (PRU) Software Support Package
------------------------------------------------------------
============================================================
   EXAMPLES
============================================================

DESCRIPTION

	This directory provides basic "building block" examples for the PRU. Each
	example demonstrates a particular feature of the PRU. The concepts shown in
	these examples can be combined to create PRU applications. Hence, they are
	considered "building blocks."


WHAT EXAMPLES ARE INCLUDED?

	The following examples are included in this directory.

	EXAMPLE
	---------
	PRU_access_const_table
		access_const_table demonstrates how to use the constant table
		and header files to access peripherals and memory.

	PRU_ADC_onChip
		ADC_onChip:
		 * Provides a template for controlling an on-chip
		   peripheral with the PRU
		 * Demonstrates RPMsg with a userspace application

	PRU_Direct_Connect0
	PRU_Direct_Connect1
		Direct_Connect examples demonstrate how to:
		 * Pass INTC configuration to Linux RemoteProc driver
		 * Pass interrupts and data between PRU cores

	PRU_Halt
		Halt examples are basic empty ICSS projects.
		The core gets initialized, and then does nothing.

	PRU_edmaConfig
		edmaConfig demonstrates setting up an EDMA transfer.

	PRU_gpioToggle
		gpioToggle toggles all PRU GPO signals. Note that the GPO
		signals must be pinmuxed to external pins before they can be
		observed.

	PRU_Hardware_UART
		Hardware_UART demonstrates how to initialize the hardware UART
		in the PRU-ICSS, set loopback mode, and send/receive data.

	PRU_IEP
		IEP demonstrates how to use the IEP timer to generate an
		interrupt after a specific timeframe.

	PRU_MAC_Multiply_Accum
		MAC_Multiply_Accum examples demonstrate how to:
		 * Use the multiply with accumulate (MAC) module. See TRM for
		   more.

	PRU_RPMsg_Echo_Interrupt0
	PRU_RPMsg_Echo_Interrupt1
		RPMsg examples demonstrate the RemoteProc RPMsg protocol to
		communicate between the ARM and the PRU. RPMsg is not the best
		inter-processor communication method for every design, but it is
		useful for initial debugging and demonstrations.


ADDITIONAL RESOURCES

	For more information about the PRU, visit:

	PRU-ICSS/PRU_ICSSG docs  - https://software-dl.ti.com/processor-sdk-linux/esd/AM64X/latest/exports/docs/linux/Foundational_Components_PRU_Subsystem.html
	AM335x TRM               - https://www.ti.com/lit/pdf/spruh73
	Support                  - http://e2e.ti.com

Thankyou for the reply. Any further help?

Only way to learn is immerse your self in the project. Being book smart is part of the process and hands on is the “glue” that makes it stick in your mind. You won’t learn squat until you hit a wall and have to mindlessly dig for hours looking for obscure details that will enable a working solution.

Others on here work with the pru and will most certainly help you out when you get stuck.

Myself, first thing I would do is check out the simplest example to validate your hardware is functioning properly. If the known working example does not work everything thing else will fail, so try the simple one first. It should start to fall together after that.

2 Likes

Thankyou for reply.

BB Black PRU_ADC_onChip example started and given me results as expected (shown in multimeter).

But this example is providing only one data. I want to read multiple data at high sampling rate. Can you tell how to do that?

Like from multiple input pins?

If that is the case it will not happen. The pinmux on the SoC is limited to what ever the data sheet specifies as pru inputs/outputs. From your description it would much simpler to use a dedicated A to D with spi or i2c bus output and then read and parse that data. Any thing you can hang on the i2c bus is easier to work with.

I want to you in-built ADC of BB Black to acquire 10 seconds of data at 10kHz sampling rate.

I have testing it using processor. But sampling rate changes.

I think, it is possible with PRU (as seen in some posts). But as seen from some posts, it is does not work with RPMsg (slow for high data rate) and work with DMA (fast for high data rate).

So, I want to use ADC, PRU, DMA for my application.

What are the steps to be following for this?

I understand what you are doing, and yes the pru would clear that up. Have you tried the RT kernels, 6.12 RT you can set the slice time. That might be much easier than setting up the pru. At least you can budget time accordingly. I have not used that 6.12 RT so this is just what I have read about it.

10khz seems rather fast for that board. Some way you need a direct connection to i2c or you will still be chopped up by the kernel since it manages i2c.

Some post have shown in-built ADC can be used for high speed data acquisition using PRU. I want to use that combination (PRU+ADC).

BB Black example acquire only 1 sample and then stop. I want to acquire for 10 seconds (100000 samples) using only 1 ADC channel.

Just place it in a loop and check if the condition of 100000 is met, then terminate. You should be able to wrap that example up and have it exit when done. You are not going to break any thing if the code is wrong. Since its the pru running you will not break the os.

Not sure where you are on your PRU journey, but if you are just getting started with the PRU, I have a guide for my students on how to begin using the PRU:

I also have some notes I present on doing shared memory between the PRU and a Linux app using memory mapping. If you are interested, I can share them with you directly.

I have not worked with the ADC in the PRU, but these resources should at least get you with something working on the PRU and sharing memory to Linux.

Brian.

2 Likes

@Brian_Fraser for your PDF. I needed this kind of example.

I am also looking for an example on DMA. If you have it, please provide that.
How to transfer/receive way DMA. How to implement this using PRU.

I added your work to a github repo I just started just for BBB. If you don’t mind me doing that. Just let me know if you would rather I take it down.

1 Like

Sounds good!

I don’t have anything on DMA, unfortunately. A solid reference for many PRU things is the PRU Cookbook:
https://docs.beagleboard.org/books/pru-cookbook/index.html

However, it seems not to mention DMA.

1 Like

I just added that link to the readme.md. Thank you.