BeagleBone Black ADC & PWM Simultaneously

Hey all. I trying to use the BeagleBone Black to drive a motor system and simultaneously read the output voltage. Originally I was using the native sysfs ADC and PWM modules. The PWM worked perfectly however the ADC would lock, return erroneous values, and give the error “Resource Temporarily Unavailable”. After extensive research this was narrowed down to a kernel driver error. Therefore to get around this I decided to utilize the PRU’s via the freebasic libpruio library. This effectively solved the ADC issue or so I thought. Using the PRU’s for ADC from say a trim pot or a photo-resistor to measure values works flawlessly…

However I have noticed that attempting to read ADC values (even when using the PRU’s) while simultaneously outputting a PWM signal to drive the motor system causes the ADC to “freeze”. That is the value gets stuck and will not update, even though other values will continue to update. Closing the program and rerunning it causes the program to hang requiring a force exit. And to get it working again requires a reboot.

I find it hard to believe that no one else has run into this issue, I also find it hard to believe that no one else has ever attempted to simultaneously use the ADC and PWM on the BeagleBoard.

So …

  1. Has anyone run into this issue before?

  2. Does anyone have a possible solution?

  3. Does anyone have an effectively working method of driving a motor with on board PWM while simultaneously reading analog values with the on board ADC?

Thank you in advance. I have been losing my mind over this.


I can confirm the ADC issues with sysfs (, but didn’t test sysfs PWM yet).

Why don’t you use libpruio features for PWM?


1) Has anyone run into this issue before?

2) Does anyone have a possible solution?

3) Does anyone have an effectively working method of driving a motor with on board PWM while simultaneously reading analog values with the on board ADC?

I have seen this issue before. In the two different ways I’ve used the ADC. But it’s not that the values simply repeat every sample. It’s that the values repeat in some context related to the FIFO.

e.g. I see different value, for maybe( I have not actually counted ) let’s say 100 values ? Where then the values all repeat. Actually, I’ve used the ADC three different ways technically. Used sysfs one-shot mode, and continuous mode. As well as directly mapping the ADC module registers through /dev/mem/ + mmap(). Using the later here is very similar to using the PRU’s to achieve the same, except the executable scope is all on the main processor - Of course.

A couple things to keep in mind. While I might be considered somewhat of an expert when it comes to programming with a few different languages. I am in no way an expert when it comes to this hardware. I am also relatively new to writing software for / on Linux ( couple years hands on now ). Another thing to consider is that I did not use any PWM module, and the ADC values I read in were from floating pins( nothing connected to the pins ).

SO here is one thing I’ve read about somewhere ( possibly the TRM ). Once you’re done reading from the FIFO, you’re supposed to clear it somehow. I think what I read was you need to write a “1” to a certain register . . . and I experimented with clearing the FIFO manually, but all that gave back in return was all zero’s . . . I’ve since gotten side tracked and have not looked into this issue any further.

I honestly do not think this is a kernel module problem however . . . I think this is more of “user not understanding the hardware completely” issue. Definitely in my case.

Hmm thats interesting. I think I have narrowed my issue a littler more. It seems to ONLY occur when the motor system being powered by the PWM is actually running, i.e. given a supply voltage. If the power is off or even if the power is on and I simply disconnect the wire it works fine. (Well the PRU part. Sysfs still has issues) So naturally I thought EMI from the motors. I moved the wires, board, and motors as far apart as I could and still the issue persists. Again only when the motors are actually running. I then thought maybe it is an over voltage spike, but the same behavior occurs even when the wires are not connected that is floating pins or connected to a quite separate trim pot fed by VDD_ADC.

It is driving crazy.

Is it possible that EMI at a different part of the board could affect the ADC? For example the P9_01 pin is pretty close to the motor system under normal setup but would EMI there cause issues with pin P9_36 (AIN5) ?

Check for noise on all of your power rails wen the motor is running. You may need to filter the power that goes to the motor to prevent it from going back onto the main power rails.