implement ADC using mmap

In my project i want very fast ADC reading method for my distance sensor’s Analog value readings so i read about mmap and tried to implement it and yeah it was quiet easy for GPIO controlling but i could not find some good resource for ADC so tried to look up on the web for already written codes and i found this one very promising : https://github.com/alban-rochel/pixbox-controls/blob/master/service/gpio_mmap.cpp

i run the code and found out that the code is running without any errors and i m getting some analog value for my pin AIN0 but when i cross checked it with the value in the sysfs file “/sys/bus/iio/devices/iio:device0/in_voltage0_raw” the observation were very different.
When i connected the pin to ground the value from this code was as always kind of some random number and value in the sysfs file was correct as it was 0.

Things i tried:

  1. I thought that FIFO0DATA register may be giving out value of other pin so i enabled the Step_ID_tag in CTRL register(0x44E0_D040) of ADC_TSC and checked the ID of pin before taking the 12 bit data from register, result was i have enabled only StepConfig1 register out of all 16 but FIFO0DATA register is also giving out values for other Config pins also and the value of stepConfig is also not correct.

Plz help me by pointing out some error in the code or suggest some other resource.

Thanks in advance

Give libpruio a try. Beside a lot of other features it provides fast GPIO and ADC sampling. Code examples are included in the package.

Regards.

Thanks Samstag for reply : Give libpruio a try. Beside a lot of other features it provides fast GPIO and ADC sampling. Code examples are included in the package.Regards.

Sorry for late reply. Thank you for the suggestion. It is a very good library and i m able to get ADC working using this but i haven’t been able to completely understand this library and trying to do so but i wanna ask this. Is this library compatible with “wiringBone” : https://github.com/AbhraneelBera/wiringBone as other components of my project are dependent on wiring bone.

Is this library compatible with “wiringBone” : https://github.com/AbhraneelBera/wiringBone as other components of my project are dependent on wiring bone.

Which components do you miss?

I don’t know that project. The description

Capture pulse width and time period of incoming pulse train from 26 pins.

looks like they use both PRUSS for CAP (and PWM) features, so no PRUSS left for libpruio. Also it uses beaglebone-universal-io for pinmuxing, which is more resource consuming, unflexible and unsave than libpruio pinmuxing (and therefor incompatible). I guess you’ll have to make your choise.

Regards

Hi Montag, Thanks for your reply :

looks like they use both PRUSS for CAP (and PWM) features, so no PRUSS left for libpruio. Also it uses beaglebone-universal-io for pinmuxing, which is more resource consuming, unflexible and unsave than libpruio pinmuxing (and therefor incompatible). I guess you’ll have to make your choise.

I am using a velocity controller which work on the input of encoders and communicates with BeagleBone using serial communication, It’s library was designed by the company for ARDUINO (https://www.dimensionengineering.com/software/KangarooArduinoLibrary/html/annotated.html). WiringBone was making my work very much easier and as i don’t know very much about BeagleBone my arduino work was directly implementable using wiringBone. As it use sysfs files for GPIO and ADC and they are slow so i was trying to implement only these two using mmap and i was succesful in case of GPIO and thanks to that my encoders were working but ADC using mmap is still incomplete.
I will try to check if velocity controller’s library can be modified to be used to libpruio,then it will be great or else i have to go for mmap of ADC as that’s my best shot for now.

Any further help appreciated.

Why an external controller when you have a BBB? Anyway, this library seems to be compatible with libpruio.

Hi Montag,

Why an external controller when you have a BBB? Anyway, this library seems to be compatible with libpruio.

It is a very good velocity controller just give the input from encoders and tune it once , it will rotate the wheel in many different ways(fast,slow,rising etc.) and finds out PID tuning constants itself and we don’t need to bother the tuning if there is changes done on the robot just tune it again (it hardly takes 5min) and writing the same kind of code would be very tricky. It makes the circuitry very modular , just send the value of speed you want to maintain in encoder ticks/second.

It’s great that it is compatible with libpruio. Any suggestion on how to setup the serial communication along with libpruio.
Thanks in advance.

It’s great that it is compatible with libpruio.

I said it “seems to be”. I don’t know it and didn’t test yet.

Any suggestion on how to setup the serial communication along with libpruio.

Thanks in advance.

I neither know about your targets nor have I seen a single line of your code. How should I suggest anything?

It seems that you just have to replace the wiringBone dependency in your code by a libpruio dependency, and replace the API calls by similar libpruio calls. That should work strait forward as long as you didn’t use PWM or CAP features provided by wiringBone-PRUSS code. You wont need mmap GPIO, libpruio should be fast enough (disable unused subsystems if you need further speed).