0

I am trying to use hcsr04 sensors on the Beaglebone black (adapted from this code - https://github.com/luigif/hcsr04)

I got it working for 4 different sets of sensors individually, and were now unsure of how to combine them into one program.

Is there a way to give the trigger and receive the echos simultaneously, such that interrupts can be generated as different events to the C program.

Running them one after the other is the last option we have in mind.

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
  • You'd get better visibility if your tags were more appropriate. `beagleboneblack` and `beagleboard` are both going to have people comfortable with the hardware that's at the root of your solution. All of your other tags are...well...too generic. – Russ Schultz Nov 05 '15 at 05:39
  • But, my assumption to solve your problem you're going to need to rewrite the program that runs on the PRU to monitor multiple sensors and report them back to the Cortex. If you're only doing a few sensors and are OK with 5-10 updates a second, then you can just do them serially. If not, then you're going to have to do them in parallel. Lucky for you there appears to be a C compiler now. That and there's 32 registers in the core, which means you could probably get away with keeping everything in registers – Russ Schultz Nov 05 '15 at 05:46
  • (And I wouldn't bother with doing multiple ISRs/Events to the Cortex. It's just easier to gang them all up on one and check to see who changed) – Russ Schultz Nov 05 '15 at 05:47
  • We'll keep it in mind. We are new to the forum and the beaglebone tag wasn't accepted. Thank you. – Priyadarshini S Nov 06 '15 at 05:00
  • Please show your code so far – Rohit Gupta Nov 07 '15 at 06:51

1 Answers1

1

Russ is correct - since there's 2x PRU cores in the BeagleBone's AM335x processor, there's no way to run 4 instances of that PRU program simultaneously. I suppose you could load one compiled for one set of pins, take a measurement, stop it, then load a different binary compiled for a sensor on different pins, but that would be a pretty inefficient (and ugly, IMHO) way to do it.

If you know any assembly it should be pretty straight-forward to update that code to drive all 4 sensors (PRU assembly instructions). Alternatively you could start from scratch in C and use the clpru PRU C compiler as Russ suggested, though AFAIK that's still in somewhat of a beta state and there's not much info out there on it. Either way, I'd recommend reading from the 4 sensors in parallel or one after the other, loading the measurements into the PRU memory at different offsets, then sending a single signal to the ARM.

In that code you linked, the line:

SBCO roundtrip, c24, 0, 4

Takes 4 bytes from register roundtrip (which is register r4, per the #define roundtrip r4 at the top of the file), and loads it into the PRU data RAM (constant c24 is set to the beginning of data RAM in lines 39-41) at offset 0. So if you had 4 different measurements in 4 registers, you could offset the data in RAM, e.g.:

SBCO roundtrip1, c24, 0, 4
SBCO roundtrip2, c24, 4, 4
SBCO roundtrip3, c24, 8, 4
SBCO roundtrip4, c24, 12, 4

Then read those 4 consecutive 32-bit integers in your C program.

Alex Hiam
  • 261
  • 2
  • 8