libpruio (fast and easy D/A - I/O)

3556 views
Skip to first unread message

TJF

unread,
May 9, 2014, 10:23:18 AM5/9/14
to beagl...@googlegroups.com

A new library called libpruio is availble to support digital input and output as well as analog input on Beaglebone (black) hardware. It uses software running on a PRUSS to configure and control the devices
  • Control Module (pinmuxing)
  • GPIO 0 to 3 (digital IO)
  • TSC_ADC_SS (analog input)
The API is designed for easy usage, but also for fast execution speed. No need for root privilegues or further device tree overlays (just a single overlay to start the PRUSS).

It's compiled by the FreeBASIC compiler, but also includes a wrapper to be used with C compilers. The package contains example code in both languages. Development and testing has been done on a BeagleboneBlack under Ubuntu 13.10.

Find more informations at
or check out the online documentation.

Jason Kridner

unread,
May 9, 2014, 11:42:50 AM5/9/14
to beagl...@googlegroups.com
This looks pretty awesome  from the surface. You should register at http://beagleboard.org/project. Do you want this included the default image?
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

TJF

unread,
May 9, 2014, 1:08:26 PM5/9/14
to beagl...@googlegroups.com
Thanks for the registration tip / link, done.

And thanks for your positive statement. I hope you find some time to look under the hood. Would be nice if you can run some of the pre-compiled examples and tell us your thoughts.

The licences are LGPLv2 / GPLv3, so it could get in to the default image. I'd like to get some feedback and fix the major bugs, first. Is there a deadline?

Jason Kridner

unread,
May 9, 2014, 4:25:40 PM5/9/14
to beagl...@googlegroups.com
No particular deadline as we already shipped the Rev C image. We will push a bug fix version over the next 2-3 weeks as reports come in. If we don't squeeze in there, there's always another release coming. 


On Friday, May 9, 2014, TJF <jeli.f...@gmail.com> wrote:

Jason Kridner

unread,
May 12, 2014, 7:35:49 AM5/12/14
to beagl...@googlegroups.com
No set deadline. We should be doing new releases multiple times this
summer as issue reports and feature requests start coming in on Rev C
as we get more users.

TJF

unread,
May 12, 2014, 4:20:14 PM5/12/14
to beagl...@googlegroups.com, jason....@hangerhead.com
For the default image we need the binary libpruio.so (not sure about libpruio.a). And we need the headers. Currently there're 4 headers, but I think I should create an all-in-one version called pruio.h and drop the documentation comments to save some memory.

Where to send the fine-tuned files? (Please be patient, that's my first project here.)

Who cares about the dependencies (libprussdrv)?

TJF

unread,
Jun 6, 2014, 7:38:38 AM6/6/14
to beagl...@googlegroups.com, jason....@hangerhead.com
Version 0.0.2 is out now:
  • added: new example button.bas (.c)
  • bugfix: gpio_get() returns correct value now
  • cosmetic: pruio_c_wrapper.h contains headers pruio.h and pruio.hp (all-in-one)
  • cosmetic: minor changes in documentation

sufialh...@gmail.com

unread,
Sep 3, 2014, 12:05:05 PM9/3/14
to beagl...@googlegroups.com, jason....@hangerhead.com

Hi TJF,

I just managed to compile and run the libpruio example apps on beaglebone white PRU.

I was experimenting with the button.c, trying to set the pin 8_07 as active high, using ->

if (pruio_gpio_set(io, PIN, PRUIO_IN_0, PRUIO_LOCK_CHECK)) { 
    printf("failed setting PIN (%s)\n", io->Errr); break;}

But, when I compile and run it, I still see its '1'.

./analyse reveals->

P8_07, GPIO 2/02: input, pullup

Am I missing something?

Forgive me if this sounds like a stupid question. Please help.

Thanks and regards,
Shoaib Ahmed.

TJF

unread,
Sep 3, 2014, 2:33:09 PM9/3/14
to beagl...@googlegroups.com, sufialh...@gmail.com
Hi Shoaib Ahmed,

thanks for your interrests in libpruio.


Am Mittwoch, 3. September 2014 18:05:05 UTC+2 schrieb sufialh...@gmail.com:
Am I missing something?

Forgive me if this sounds like a stupid question. Please help.

No stupid question. A stupid author of libpruio, instead. Pinmuxing doesn't work in your version. See

http://www.freebasic.net/forum/viewtopic.php?f=14&t=22501&start=30#p198962

It'll be fixed in the next release (version 0.2). Meanwhile use external tools, please.

Sorry for your trouble.

nils....@gmail.com

unread,
Sep 17, 2014, 4:25:05 PM9/17/14
to beagl...@googlegroups.com
Hey TJF,

I'm currently working on underwater ultrasonic sound and wonder if you think that with your library can produce constant and reliant ADC input at sample rates of 200Khz per pin. On top of that I'm interested to see version 0.2 and the ring buffer you're been talking about.

Since it seems that you've already been able to produce results with the ring buffer, I only need to read ADC input right now and I'm on a tight schedule right now I would like to ask you if you want to provide a test version of said feature. I can provide the results of the tests.

Greetings,
Nils Kohrs

TJF

unread,
Sep 19, 2014, 3:11:27 AM9/19/14
to beagl...@googlegroups.com, nils....@gmail.com
Hello Nils!


Am Mittwoch, 17. September 2014 22:25:05 UTC+2 schrieb nils....@gmail.com:
Hey TJF,

I'm currently working on underwater ultrasonic sound and wonder if you think that with your library can produce constant and reliant ADC input at sample rates of 200Khz per pin

The PRUSS code is ready to work at that speed. Unfortunately the BBB hardware (TSC_ADC_SS) is limited to a maximum total sampling rate of 160 kHz (one channel, software triggered start). If you need more than one channel, you've to add some delay for switching (multiplexing) the input.
 
On top of that I'm interested to see version 0.2 and the ring buffer you're been talking about.

The code is ready (95 %). I'm working on the documentation (any help is welcome).
 
Since it seems that you've already been able to produce results with the ring buffer, I only need to read ADC input right now and I'm on a tight schedule right now I would like to ask you if you want to provide a test version of said feature. I can provide the results of the tests.

Beta testing is welcome. Please tell me if you're still interested (in the light of the hardware limitations).

BR

TJF

unread,
Oct 26, 2014, 1:17:02 PM10/26/14
to beagl...@googlegroups.com
libpruio-0.2 is out now:


New:

  • Ring buffer (RB) run mode (samples analog input continously).
  • PWM output in IO and RB mode (variable frequency and duty cycles).
  • CAP input in IO and RB mode (analyses frequency and duty cycles of a pulse train).
  • New examples *pwm_adc*, *pwm_cap*, *rb_oszi*.
  • Subsystem control (enable or disable single subsystems at run-time).
  • Device tree overlay included (universal pinmuxing at run-time).
  • Tools included to create, compile and install universal or customized device tree overlays.
  • Advanced error messages from constructor.

Changes:

  • Completely renewed source code (modular now, for easier expansions).
  • Completely renewed documentation (interferences between C and FB source solved).
  • API adapted to modular structure (see file migration.txt.
  • Version 0.0 examples adapted (*1*, *analyse*, *button*, *io_input*, *sos*, *stepper*, *oszi*, *triggers*).
  • Adaptions for new FreeBASIC compiler fbc-1.00.
  • Access to all subsystem registers supported.

Bugfixes:

  • Pinmuxing now available.
  • GPIO output fixed (former gpio_set sometimes skipped a setting).

Download (as in first post)


William Hermans

unread,
Oct 26, 2014, 5:44:17 PM10/26/14
to beagl...@googlegroups.com
TJF, It would be nice if you're going to link to a site to a majority of English speakers, that the link you give to us links to a written English page.

At minimum you're posting in English so yeah, be nice to us.

TJF

unread,
Oct 27, 2014, 4:00:45 AM10/27/14
to beagl...@googlegroups.com
William, sorry, my fault!

"us" can find the 'brand new' English project page at

http://beagleboard.org/project/libpruio/

Don't hesitate to ask if you need further assistance on downloading.

niro...@gmail.com

unread,
Oct 30, 2014, 9:43:03 AM10/30/14
to beagl...@googlegroups.com
Hey TJF,

Nice to see the update, I really happy with the new features :)

What would be the highest consistent samplerate possible with the c wrapper with 1 channel. Using the RB would be the nicest but using MM is also an option if the samplerate is higher with that.

I think if I know that I could figure out the rest myself, however it would be nice to have sample code of config&start rb/mm(possibly on max samplerate) and data retrieving in c.

Greetings,
Nils Kohrs

TJF

unread,
Oct 30, 2014, 1:50:55 PM10/30/14
to beagl...@googlegroups.com, niro...@gmail.com
Hello Nils,

thanks for feedback!

The maximum sample rate is limited by the ADC subsystem. It's 159 kS/s (15 cycles @ 2.4 MHz + safety buffer) for a single step (channel). It neither matters if you operate in RB or MM mode, nor if you use FB or C compilers.

For me, writing C examples is exhausting and time consuming. For an experianced C programmer it should be easy to translate the FB examples rb_oszi and triggers, where you can find the code you're loocking for. (I'd appreciate it if I can include such a translation in to the documentation.)

For maximum sample rate you've to configure a customized step with no delays and no avaraging. And you've to activate this step only, like

pruio_adc_setStep(Io, 9, 4, 0, 0, 0); // step 9 for AIN-4

pruio_config
(Io, Samples, 1 << 9, 6285, 4); // '1 << 9' -> step 9, '6285' ns -> 159.1 kHz

pruio_rb_start
(Io);

BR
Message has been deleted

niro...@gmail.com

unread,
Nov 6, 2014, 11:16:43 AM11/6/14
to beagl...@googlegroups.com, niro...@gmail.com
Hey TJF,

with 6285 ns I was only able to set the amount of samples to 1 without getting an error. With 6290 works everything fine.

Here is some c samplecode for you, it keeps writing all the samples to a file in burst of 1000000/4 samples per writing burst.

#include "unistd.h"
#include "stdio.h"
#include "../c_wrapper/pruio.h"


//! The main function.
int main(int argc, char **argv)
{
  FILE
* oFile;
  uint8 bDiv
= 4, bStep;
  uint32 bSize
= 1e6;
  uint32 bsSize
= bSize/bDiv;
  oFile
= fopen("output","wb");
  pruIo
*io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new driver structure
  pruio_adc_setStep
(io, 9, 4, 0, 0, 0); // step 9 for AIN-4
 
if (pruio_config(io, bSize, 1 << 9, 6290, 0)){ // '1 << 9' -> step 9, '6285' ns -> 159.1 kHz
        printf
("config failed (%s)\n", io->Errr);}
 
else{
    pruio_rb_start
(io);
    sleep
(1);
   
while(1){
     
while(io->DRam[0] < (bStep+1) * bsSize && io->DRam[0] > bStep * bsSize){
        sleep
(1);
     
}
      printf
("start writing %u\n",bStep*bsSize);
      fwrite
(io->Adc->Value, sizeof(uint16), 16000, oFile);
      printf
("end writing %u\n",(bStep+1)*bsSize);
      bStep
= bStep+1 < bDiv ? bStep+1 : 0;
   
}
 
}
  pruio_destroy
(io);
 
return 0;
}

Greetings,
Nils Kohrs

TJF

unread,
Nov 6, 2014, 1:36:04 PM11/6/14
to beagl...@googlegroups.com
Hello Nils,

thanks for the code. I think about including it in the libpruio examples folder, but your main loop is endless and the user cannot abort the program. (Shouldn't the file get closed?) Perhaps I can adapt it a bit.

Regarding the ADC speed I made some further testing and it seems that I mis-interpreted the TRM. The ADC subsystem can sample at least at 200 kS/s. This speed also works for multiple channels. Find an example of four channels at 44.1 kHz in this post. An overall sampling rate of 200 kHz was also possible (four channels).

So the limiting in the current libpruio-0.2 is too much on the safe site. If you don't want to wait for the next version, you can adapt the code by yourself (FreeBASIC compiler required). Replace in file pruio_adc.bas in function PruIo.configure(...) the lines

      d *= (Conf->ADC_CLKDIV + 1) * 417 '417 ≈ 1000000 / 2400 (= 1 GHz / 2.4 MHz)
      d += 30 '
                            PRU cycles for restart [GHz]
      IF
Tmr <= d THEN     .Errr = @"sample rate too big" : RETURN .Errr

by the following code

      d = (d * (Conf->ADC_CLKDIV + 1) * 1000) \ 24
      IF
Tmr <= d ORELSE Tmr < 5000 THEN _
                           
.Errr = @"sample rate too big" : RETURN .Errr

You may play a bit with the absolute value 5000. On my BBB the timing is OK up to a frequency of 240 kHz (4165). But this may vary from board to board.

niro...@gmail.com

unread,
Nov 6, 2014, 6:18:55 PM11/6/14
to beagl...@googlegroups.com
Hey TJF,

I've got it compiled and working. I can't yet test if the adc keeps up since I the function generator we've ordered got out of stock.... However I changed my code a bit so it would close the files and the whole program has a end statement. It's currently 1 channel at ~220 kS/s. I haven't pushed it further because I don't know what will happen. With my understanding of the PRU I guess the PRU can't break anything on the BBB while doing that, but I don't know so I don't want to push my luck.

#include "unistd.h"
#include "stdio.h"
#include "../c_wrapper/pruio.h"


//! The main function.
int main(int argc, char **argv)
{
  FILE
* oFile;
  uint8 bDiv
= 4, bStep;
  uint32 bSize
= 1e6;
  uint32 bsSize
= bSize/bDiv;

  uint8 cycles
= 2;
 
char fName[12];
 
int i = 0;



  pruIo
*io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new driver structure
  pruio_adc_setStep
(io, 9, 4, 0, 0, 0); // step 9 for AIN-4

 
if (pruio_config(io, bSize, 1 << 9, 4545, 0)){ // '1 << 9' -> step 9, '6285' ns -> 159.1 kHz

        printf
("config failed (%s)\n", io->Errr);}
 
else{
    pruio_rb_start
(io);
    sleep
(1);

   
for(i=0; i<cycles; i++){
      sprintf
(fName, "output.%u",i);
      oFile
= fopen(fName,"wb");
     
while(bStep<bDiv){

       
while(io->DRam[0] < (bStep+1) * bsSize && io->DRam[0] > bStep * bsSize){
          sleep
(1);
       
}

        printf
("writing samples %u-%u\n",bStep*bsSize, (bStep+1)*bsSize);

        fwrite
(io->Adc->Value, sizeof(uint16), 16000, oFile);

        bStep
++;
     
}
      bStep
=0;
      fclose
(oFile);
   
}
 
}
  pruio_destroy
(io);
 
return 0;
}


Greetings,
Nils Kohrs

William Hermans

unread,
Nov 7, 2014, 4:06:48 AM11/7/14
to beagl...@googlegroups.com
Whew ! If you're looking for "fast", you're not going about it the right way.

1) Nested loops are bad.

2) A file open, and close every cycle on the outer loop ? Is that really necessary ?  Big time performance hit.

3) spintf() as I recall is a fairly slow function.

A few things you can do to fix these issues.

Remove the nested loops and replace with a, if/else control block. Make the conditions checks that are most likely to pass more often - first. Also, simplify your math. If the numbers are going to be consistent, and non changing. Hard code the values. Multiplication and division on fast moving code will slow you down. Especially if done on floating point numbers. So unless I missed an assignment somewhere . . .

while(io->DRam[0] < (bStep+1) * bsSize && io->DRam[0] > bStep * bsSize) {
 ...
}


if bsStep which seems to be left unassigned ( 0 ) + 1 = 1

1 * <any value> is going to be that <any value> . . . Some compilers may optimize this out, but why ? It also makes the code less readable.

Also . . .


fwrite(io->Adc->Value, sizeof(uint16), 16000, oFile);


Is a potential performance hit. Quite honestly I am not sure *if* sizeof(uint16) would be checked once at compile time, or if it would be checked every cycle at run time. But you can "fix" this simply by hard coding the value. Make it a constant if you feel it makes the code more readable.


Open the file once before the loop, and close it after the loop is done. That is, if at all possible. Also there is a "trap for new players", in that if the application exits abnormally, the file may still be left opened. So a check when the application first starts may be in order.

As an aside, you can simplify the whole application by just gathering  raw data, and shifting it out to the the general purpose processor ( ARM ). Which then the main processor can be made to do all the heavy math "lifting".

Anyway I hope this is useful information, and my posting is not meant to demean, or otherwise come across as "smart-ass".

--

niro...@gmail.com

unread,
Nov 7, 2014, 4:56:12 AM11/7/14
to beagl...@googlegroups.com
Thanks for the feedback. I know that I'm far from a good c programmer, but I'm not that bad.

From reading the book "The C++ Programming Language" by Bjarne Stourstrup (the maker of c++) I know a thing or two about the compiler.
First of, all sizeof(...) are replace at compile time. Secondly, all operators that can be calculated at compile time will be calculated at compile time. This makes the last two optimizations you suggest just working with the code harder.

I don't know if you've runned this code your self already, but if you would have noticed that the limiting part is the PRU coprocessor and not actually the ARM processor itself.
With that in mind option 1 is just the flavor of code you choose.

About point 3: If you want to concatenate a integer to a string/char[] there are two options. First you can convert the into to a char[] with itoa() and then use strcat(), or you use the minimal slower spintf which is more readable

And lastly about point 2, if you want to write it to multiple files, you'll have to close the old one and open the new one every time you go on to the next file.

This programs was for me to test the performance, and as you see from the one seconds sleeps I've build into it, it runs fine and a lot faster than it needs to be. Also from any of the examples included to libpruio you can expect the reader not to just copy the code 1:1 and live happily ever after. Everyone will edit it to their liking and performance needs. For me this runs fine and error handling with the file io is something you can implement your self, if you need it. This is example code and not production code...

And on a last note, you've made me aware of a little error in my code though, the line:

fwrite(io->Adc->Value, sizeof(uint16), 16000, oFile);

should be

fwrite(io->Adc->Value, sizeof(uint16), bsSize, oFile);

If you want to provide better sample code you're free to go, but please don't be that smart-ass stating facts that are only half or not at all true.

Greetings,
Nils Kohrs

William Hermans

unread,
Nov 8, 2014, 5:30:02 AM11/8/14
to beagl...@googlegroups.com
If you want to provide better sample code you're free to go, but please don't be that smart-ass stating facts that are only half or not at all true.

Ok, that is just plain rude.

So, since we're being rude now. I should mention the code you pasted is C and not C++. I figured you should know this since you think you know everything.

I will tell you what. You keep on trucking on, and nesting while loops 100 deep if you like, and I'll refrain from reading your posts any further to keep my eyes from bleeding.

niro...@gmail.com

unread,
Nov 10, 2014, 7:48:18 AM11/10/14
to beagl...@googlegroups.com
Hey TJF, 

I wanted to give you a heads up on my samplecode. The performance test was right in that is was that exact performance, but I shouldn't write a program in c when I'm sleepy. 
The program had some functional problems which should be fixed now. However, I'll first test it with a function generator to make sure that the code is indeed working as expected. If everything is working fine I'll post it here and you should be able to use it as c samplecode.

Greetings,
Nils Kohrs

TJF

unread,
Nov 10, 2014, 8:05:15 AM11/10/14
to beagl...@googlegroups.com, niro...@gmail.com
Hello Nils,

I just had a closer look at your first example. Sorry, I've new concerns. It seems that the code requires to customize the size of the external memory, which is a downside for beginners. And it doesn't show the ring buffer capabilities (, you could have used MM mode as well).

From my point of view the strange of RB mode is that you can fetch any number of samples with any size of the external memory. And the example should demonstrate that point.

So for the FreeBASIC folder I created a new example called rb_file.bas

/'* \file rb_file.bas
\brief Example: fetch ADC samples in a ring buffer and save to file.

This file contains an example on how to use the ring buffer mode of
libpruio. A fixed step mask of AIN-0, AIN-4 and AIN-7 get sampled and
saved as raw data to some files.

Licence: GPLv3

Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net


Compile by: `fbc -w all rb_file.bas`

\since 0.2
'/

' include libpruio
#INCLUDE ONCE "../pruio/pruio.bi"

CONST tSamp = 123401 _  '*< The number of samples in the files (per step).
      , tmr = 5000 _    '*< The sampling rate in ns (5000 -> 200 kHz).
   , NoStep = 3 _       '*< The number of active steps (must match setStep calls and mask).
   , NoFile = 2 _       '*< The number of files to write.
   , NamFil = "output." '*< The output file names.

VAR io = NEW PruIo()   '*< Create a PruIo structure, wakeup subsystems.

WITH *io
  DO
    IF .Errr THEN                     ?"NEW failed: " & *.Errr : EXIT DO

    IF .Adc->setStep( 9, 0, 0, 0, 0) THEN _
                     ?"step 9 configuration failed: " & *.Errr : EXIT DO
    IF .Adc->setStep(10, 1, 0, 0, 0) THEN _
                    ?"step 10 configuration failed: " & *.Errr : EXIT DO
    IF .Adc->setStep(11, 2, 0, 0, 0) THEN _
                    ?"step 11 configuration failed: " & *.Errr : EXIT DO

    VAR mask = &b111 SHL 9 _         '*< The active steps (9 to 11).
      , tInd = tSamp * NoStep _      '*< The maximum total index.
      , half = ((.ESize SHR 2) \ NoStep) * NoStep '*< The maximum index of the half ring buffer.

    IF half > tInd THEN half = tInd  '        adapt size for small files
    VAR samp = (half SHL 1) \ NoStep '*< The number of samples (per step).

    IF .config(samp, mask, tmr, 0) THEN _ '                configure driver
                                   ?"config failed: " & *.Errr : EXIT DO

    IF .rb_start() THEN _ '                       start ring buffer mode
                                 ?"rb_start failed: " & *.Errr : EXIT DO

    VAR p0 = .Adc->Value _           '*< A pointer to the start of the ring buffer.
      , p1 = p0 + half               '*< A pointer to the middle of the ring buffer.
    FOR n AS INTEGER = 0 TO NoFile - 1
      VAR fnam = NamFil & n, fnr = FREEFILE
      IF OPEN(fnam FOR OUTPUT AS fnr) THEN
        ?"Cannot open " & fnam
      ELSE
        ?"Creating file " & fnam
        VAR i = 0                    '*< Start index.
        WHILE i < tInd
          i += half
          IF i > tInd THEN '          fetch the rest (no complete chunk)
            VAR rest = tInd + half - i _
              , iEnd = IIF(p1 >= p0, rest, rest + half)
            WHILE .DRam[0] < iEnd : SLEEP 1 : WEND
            ?"  writing samples " & (tInd - rest) & "-" & (tInd - 1)
            PUT #fnr, , *p0, rest
            SWAP p0, p1 :                                        EXIT DO
          END IF

          IF p1 > p0 THEN WHILE .DRam[0] < half : SLEEP 1 : WEND _
                     ELSE WHILE .DRam[0] > half : SLEEP 1 : WEND
          ?"  writing samples " & (i - half) & "-" & (i - 1)
          PUT #fnr, , *p0, half
          SWAP p0, p1
        WEND
        ?"Finished file " & fnam
        CLOSE #fnr
      END IF
    NEXT
  LOOP UNTIL 1
  IF .Errr THEN SLEEP
END WITH

DELETE(io)

'' help Doxygen to dokument the main code
'&/
** The main function. */
'&int main() {PruIo::PruIo(); AdcUddt::setStep(); PruIo::config(); PruIo::~PruIo();}

Do you like to translate that code to C to include it in the libpruio package? If so, please add a file header with your copyright notes.

BR

TJF

unread,
Nov 10, 2014, 8:10:04 AM11/10/14
to beagl...@googlegroups.com, niro...@gmail.com
Oups, found a buck right when I posted:

line 70

            SWAP p0, p1 :                                     EXIT DO

should be
            SWAP p0, p1 :                                     EXIT WHILE

Soory!

William Hermans

unread,
Nov 10, 2014, 3:52:26 PM11/10/14
to beagl...@googlegroups.com
TJF,

I'd be willing at some point to help you port some code for your project, Do you have a quick setup guide for your library ? I did read some of your documents a couple months ago, but then i got busy with many other things . . . such is life.

Other problem is that I am not exactly a hardware person so much as a software developer, and I am semi new to embedded Linux. The new to embeded Linux part shouldnt be too much of a problem, just means I need to read up on the libc functions available to me. Not being an EE however slows me down greatly however, since I do not want to fry my boards . . .

As an aside, I must have really really become accustomed to C over the last several years, BASIC syntax hurts my eyes, lol but it was the very first language I picked up 17+ years ago . . .

--

TJF

unread,
Nov 11, 2014, 8:06:08 AM11/11/14
to beagl...@googlegroups.com


Am Montag, 10. November 2014 21:52:26 UTC+1 schrieb William Hermans:
TJF,

I'd be willing at some point to help you port some code for your project,

Hello William, welcome at the libpruio project.

I know about many tasks to improve the libpruio package. Some of them might be fun for you.
 
Do you have a quick setup guide for your library ?

Find the installation guide in the documentation at page Preparation.

Could you check the documentation text? It seems that you're a native speaker with good language skills. You should be able to improve the text a lot. (I could mail a pdf version, where you could add your comments.)
 
Other problem is that I am not exactly a hardware person so much as a software developer, and I am semi new to embedded Linux. The new to embeded Linux part shouldnt be too much of a problem, just means I need to read up on the libc functions available to me. Not being an EE however slows me down greatly however, since I do not want to fry my boards . . .

I'm neither an electronics engineer, nor a programmer, nor an expert on embedded systems, nor a native speaker. I think I realy know what you're talking about.

I'm looking at the project from the user point of view, evaluating how things should work and then do my best to make this happen. And, knowing there's no perfect solution, I try to learn from my failures.
 
As an aside, I must have really really become accustomed to C over the last several years, BASIC syntax hurts my eyes, lol but it was the very first language I picked up 17+ years ago . . .

Basic isn't the first programming language I used, but for me it's the most productive. I'm not speaking about the m$ dialects, which I dislike as well, and which I don't use since the middle 80's. (AFAIR QB 4.5 was the last one I tested and droped.) But there're other dialects, which are in some points more powerful than C, and easier to read for my old eyes.

The libpruio package contains some examples, as you can see at this documentation page. I think all code in folder src/c_examples could have a review. But most important, there're some examples with grafics output
  • pwm_adc.bas,
  • osci.bas,
  • rb_oszi.bas, and
  • triggers.bas

which I didn't translate to C code jet. My idea was to use cairo grafics library, but there might be a more common way to create short and easy C code?

Note: libpruio examples should be easy to understand for beginners and should have less than 200 lines of code.

Feel free to send further colaboration ideas and discuss details (here or PM). Or just make your choice and start.

BR

William Hermans

unread,
Nov 11, 2014, 1:33:33 PM11/11/14
to beagl...@googlegroups.com
Back in the early to mid 80's I was living in Kitzingen,Germany, and I was young. If you catch my meaning.

But anyway, I am still a bit busy, but perhaps in my spare time I can read your documentation a bit at a time to be used to it. It is something I've been wanting to do for a while now . . .

--

TJF

unread,
Nov 11, 2014, 2:04:00 PM11/11/14
to beagl...@googlegroups.com


Am Dienstag, 11. November 2014 19:33:33 UTC+1 schrieb William Hermans:
Back in the early to mid 80's I was living in Kitzingen,Germany, and I was young. If you catch my meaning.

A "Franke", I see. Most of my mess mates were coming from the Würzburg and Aschaffenburg area.

Your surname sounds German. I'm not living in Germany any more. I moved to the "Schluchtenscheißers".

But anyway, I am still a bit busy, but perhaps in my spare time I can read your documentation a bit at a time to be used to it. It is something I've been wanting to do for a while now . . .

 May I send (private mail) a pdf version of the documentation? You could add notes to that document to improve the text.

William Hermans

unread,
Nov 11, 2014, 2:14:44 PM11/11/14
to beagl...@googlegroups.com
Sure. However I am afraid my German reading skills ( translation ) are terrible now days. I will do what I can.

--

elt...@gmail.com

unread,
Nov 13, 2014, 7:08:42 PM11/13/14
to beagl...@googlegroups.com
Hey,

I'm trying to match the below modification in my version of libpruio, but while compiling I run into the following

ld: pruio.o: relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC

and I'm not sure how to get past it. I -think- that I have the freebasic compiler running correctly. Any advice would be welcome.

Thanks,
Michael Todd

TJF

unread,
Nov 14, 2014, 9:19:01 AM11/14/14
to beagl...@googlegroups.com, elt...@gmail.com
Hi Michael,


Am Freitag, 14. November 2014 01:08:42 UTC+1 schrieb elt...@gmail.com:
Hey,

I'm trying to match the below modification in my version of libpruio, but while compiling I run into the following

ld: pruio.o: relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC

and I'm not sure how to get past it. I -think- that I have the freebasic compiler running correctly. Any advice would be welcome.

Thanks,
Michael Todd
 
if you want to compile with the old (experimental) BBB-fbc-0.90 you'll have to use the old build scripts included in libpruio-0.0.x.

But I recommend to install the new BBB_fbc-1.00, which I also use on my board now. Just follow the instructions in (only point 1)

http://users.freebasic-portal.de/tjf/Projekte/libpruio/doc/html/_cha_preparation.html#SecInstallation

BR
Message has been deleted

andreas....@gmx.de

unread,
Mar 5, 2015, 1:24:18 PM3/5/15
to beagl...@googlegroups.com, elt...@gmail.com
Am Freitag, 14. November 2014 15:19:01 UTC+1 schrieb TJF:
But I recommend to install the new BBB_fbc-1.00, which I also use on my board now. Just follow the instructions in (only point 1)

http://users.freebasic-portal.de/tjf/Projekte/libpruio/doc/html/_cha_preparation.html#SecInstallation

Hello TJF,

thanks for librpuio and the effort you spent for this.

I followed the instructions on the side above, but still can not compile the FB examples:

- I run a BBB with a very new Debian Linux image.
- I installed everything according the documentation on the above link.
- fbc is working:
 fbc -version
 FreeBASIC Compiler - Version 1.01.0 (10-14-2014), built for linux-arm (32bit) Copyright (C) 2004-2014 The FreeBASIC development team.

However, compiling an FB example yields:
libpruio-0.2/src/examples# fbc -w all analyse.bas
/usr/local/include/freebasic/BBB/prussdrv.bi(56) error 23: File not found, "crt/sys/types.bi" in '#INCLUDE ONCE "crt/sys/types.bi" '__HEADERS__: sys/types.h'

- I have searched my system manually for "types.bi", but there is none.

Do you have any suggestions what might be missing to compile the libpruio FB examples?
Btw. The C-examples can be compiled without errors.

Thanks.

 

Jelena Freiherr

unread,
Mar 5, 2015, 2:42:00 PM3/5/15
to beagl...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hallo Herr Vogelfrei,

ich hoffe, dass eine deutschsprachige Antwort in Ihrem Sinne ist und
bedanke mich für das Interesse an libpruio.

Am 05.03.2015 um 12:54 schrieb andreas....@gmx.de:
> However, compiling an FB example yields: libpruio-0.2/src/examples#
> fbc -w all analyse.bas
> /usr/local/include/freebasic/BBB/prussdrv.bi(56) error 23: File not
> found, "crt/sys/types.bi" in '#INCLUDE ONCE "crt/sys/types.bi"
> '__HEADERS__: sys/types.h'
>
> - I have searched my system manually for "types.bi", but there is
> none.
>
> Do you have any suggestions what might be missing to compile the
> libpruio FB examples?

Bitte beachten Sie folgenden Satz auf der deutschen Downlaodseite:

Diese fbc Version ist nicht vollständig. Fehlende Dateien, z. B.
Header oder Beispiele, können aus dem GIT Repository bezogen und
nachinstalliert werden.

Mittlerweile habe ich auch ein Debian Paket erstellt, welches die
Installation vereinfachen soll. Dieses ist hier zu finden:

http://www.freebasic-portal.de/downloads/fb-on-arm/debian-package-fbc-1-01-357.html

Da ich bisher keine Zeit hatte das Paket zu testen, würde ich mich
über Ihre Rückmeldung sehr freuen. (Bitte beachten: das Paket
installiert in /usr, nicht in /usr/local. Ggf. vorhandene Dateien und
Ordner in /usr/local vor der Installation löschen.)

MfG


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlT4sV4ACgkQiYQAalShlZ/z8QCgiHg31ijqnDngqyWimYSnX7Gm
wGoAnjgc9twRUAjqlDt0Np75dTwhzHM3
=GitI
-----END PGP SIGNATURE-----

andreas....@gmx.de

unread,
Mar 6, 2015, 9:54:16 AM3/6/15
to beagl...@googlegroups.com
[SOLVED]

Hello TJF,

I will answer in English to give other users the possibility to use this information as well.

Thank you for your answer. With this information I was able to compile the supplied libpruio FreeBASIC examples.

Steps to take (on the BeagleBone, as root, otherwise use 'sudo'):

2.) dpkg --install freebasic_1.01.0debian7_armhf.deb 
              you type: freebasic_1.01.0~debian7_armhf.deb which make copy and paste from the website resulting in an error)
3.) apt-get -f install
4.) rm /usr/local/bin/fbc
5.) reboot
6.) cp -R /usr/local/include/freebasic/BBB /usr/include/freebasic/

After this, compiling fbc -w all analyse.bas works.

Thank you.


TJF

unread,
Mar 6, 2015, 5:47:32 PM3/6/15
to beagl...@googlegroups.com, andreas....@gmx.de
Thanks for feedback!

BR

akj...@gmail.com

unread,
Oct 18, 2015, 8:48:44 PM10/18/15
to BeagleBoard
Hi TJF,

I am trying to use the example you provided here to sample an analog signal.
With the default setting of tmr=5000, I am getting configuration error:

config failed: sample rate too big

It works with tmr=20000 and dumps the data into 2 files. Though the data looks to be in binary format.

Could there be something in my setup that may need tweaking to run this at 200KHz?
I am using libpruio v0.2 and installed it following the steps mentioned here.

Thanks,
Akshay

TJF

unread,
Oct 19, 2015, 12:05:48 PM10/19/15
to BeagleBoard, akj...@gmail.com
Hi Akshay!


Am Montag, 19. Oktober 2015 02:48:44 UTC+2 schrieb akj...@gmail.com:
I am trying to use the example you provided here to sample an analog signal.

I guess you're refering to the example rb_file, which is sampling three analog signals?
 
With the default setting of tmr=5000, I am getting configuration error:

config failed: sample rate too big

It works with tmr=20000 and dumps the data into 2 files. Though the data looks to be in binary format.

Could there be something in my setup that may need tweaking to run this at 200KHz?
I am using libpruio v0.2 and installed it following the steps mentioned here.

This example is pre-published (from next version). In libpruio-0.2 the limit checking for the timer value is too rigid. See this post on how to fix this.
 
BR
Message has been deleted

a.toma...@brainsomeness.com

unread,
Mar 30, 2016, 11:35:38 AM3/30/16
to BeagleBoard, akj...@gmail.com, jeli.f...@gmail.com
Hi TJF,
I'm trying to solve the bug as you described to niro some posts ahead.
After I've followed the instruction on the library site, I've:

cd pruio/
vim pruio_adc
.bas (modify buggy lines)
./make.sh
./build.sh

After that a file named `libpruio.so` appear in the current directory
The problem is that I can't build anything with that lib. When I try to compile the c_example shipped with the library
I run into the annoying error

sos.c:(.text+0x128): undefined reference to `pruio_new' ecc

I'm doing something wrong? Why the libpruio library that I build doesn't export the pruio_* functions?

Thanks,
Andrea

TJF

unread,
Mar 30, 2016, 11:45:14 AM3/30/16
to BeagleBoard, akj...@gmail.com, jeli.f...@gmail.com, a.toma...@brainsomeness.com
Hi Andrea!

It compiles OK, but the linker doesn't find the symbols (= doesn't find the binary libpruio.so).
Where did you place the new binary? It should work when you override the original binary (ie. in /usr/local/lib). Otherwise you have to update the linker cache first: sudo ldconfig Or you can instruct the linker to search for libraries in a custom path, like (for the current directory) LD_LIBRARY_PATH="." & ANY_COMPILE_COMMAND See your linker manual for details (this issue is not related to libpruio).
BR

a.toma...@brainsomeness.com

unread,
Mar 30, 2016, 5:07:55 PM3/30/16
to BeagleBoard, akj...@gmail.com, jeli.f...@gmail.com, a.toma...@brainsomeness.com
Hi TJF,
thank you very much for your reply. You were too fast, I was deleting the post right now.
My mistake was to build only the FreeBasic library and not the one in the folder `c_wrapper`

Sorry for waste your time.

I have another question: I'm trying to read from the ADC the sound from a microphone. So I would like to acquire data at 44100Hz
In order to achive this result I follow your documentation so I've configured the ADC as follow

pruio_config(io, 2, 0x1FE, 0x22675, 4)

I put 22675 as a hexadecimal value because if I put it as a decimal number the library continue to give me the error

config failed (sample rate too big)

Can you, kindly, put me in the right direction to achieve my goal?

Thank you very much,
Andrea

TJF

unread,
Mar 31, 2016, 2:30:26 AM3/31/16
to BeagleBoard, jeli.f...@gmail.com, a.toma...@brainsomeness.com
Hi Andrea!


Am Mittwoch, 30. März 2016 23:07:55 UTC+2 schrieb a.toma...@brainsomeness.com:
My mistake was to build only the FreeBasic library and not the one in the folder `c_wrapper`

No mistake, a lucky find. Just use the matching compiler.
 
I have another question: I'm trying to read from the ADC the sound from a microphone. So I would like to acquire data at 44100Hz
In order to achive this result I follow your documentation so I've configured the ADC as follow

pruio_config(io, 2, 0x1FE, 0x22675, 4)

I put 22675 as a hexadecimal value because if I put it as a decimal number the library continue to give me the error

config failed (sample rate too big)

Can you, kindly, put me in the right direction to achieve my goal?

It's too less code to give detailed advices. What I can see:
  • You specify only 2 samples (second parameter). That's too less. Your ARM code isn't fast enough to fetch the data value by value with appropriate timing.
  • You set 0x1FE as step mask (third parameter). Why do you need steps 1 to 8 (defaults to AIN-0 to AIN-7)? The maximum sampling rate for 8 channels is 25 kHz (= 200 kHz / 8).
  • Your sampling rate (fourth parameter) is 7096.3 Hz (= 1e9 / 0x22765, or in decimal 1e9 / 140917). It's not possible to sample at exactly 44100 Hz, but 44101,43 Hz is possible by using 22765 (= 0x5893) as fourth parameter.
So from my point of view you should
  • Adapt the step mask to the necessary channels (= steps). The correct value depends on your wiring and step configuration (code is missing).
  • Increase the number of samples (use all ERam: 131070 for one step or 65536 for two steps, when using default configuration of driver uio_pruss).
  • Adapt the sampling rate (to 0x5893 = 22765).
Then use RB mode to fetch the samples (and output them to a file or evaluate them directly) or MM mode for a single shot (~ 3 s recording for 1 step, 1.5 s recording for 2 steps).

BR

Arend Lammertink

unread,
May 16, 2016, 6:25:18 AM5/16/16
to BeagleBoard
Hello all,

I am working on a test-setup, which requires at least two pretty fast ADC inputs, like 100 kS/s or more. I worked with an Arduino until now, which is way to slow. So, I bought a BeagleBoard Green and intend to use libpruio for my project. Of course, the first step is to install the library on my board, which required a few tweaks to get working. You find my notes on what I did attached. I did a few other steps, like installing the am33x-pro-package from source, but I re-installed the Debian package after I found out the standard one is OK. As far as I can tell, the steps I documented should work on a cleanly installed board, but I can't guarantee that for the full 100%.

I am running the shipped Debian image (Debian 7.10) with "Linux beaglebone 3.8.13-bone71.1 #1 SMP Wed May 20 20:13:27 PDT 2015 armv7l GNU/Linux" on which I applied all updates using apt-get update & apt-get upgrade. I connected to the board using ssh over ethernet and did everything native on the board.

As a final note, I would suggest renaming the patched pasm to fbpasm or something, so that one does not need to overwrite the standard pasm in /usr/bin.

Best regards and thanks for this nice library!

-- Arend --


readme-install-libpruio.txt
Message has been deleted

TJF

unread,
May 16, 2016, 1:42:36 PM5/16/16
to BeagleBoard
Hi Arend,

thanks for the detailed installation guide/protokol. It's looking good. Full sure, it'll help BBG users to adapt the code. And all BBx users find information on how to fix the ADC sampling rate limitation.

Two notes:
  1. You need not disable UART2 for BBG. Instead you can disable libpruio control for pin P9_22 in file dts_universal.bas by adding a line
    M(P9_22) = "" '' right below the PIN_DEL(...) lines.
    in order to release this pin from the libpruio overlay. Also, you can free the HDMI pins by removing the line
    PIN_DEL(HDMI_Pins)
    Adapt before running the command fbc -w all dts_universal.bas.
  2. You described a manual installation of the FreeBASIC compiler. Meanwhile I made a Debian package, which is less painful to install/uninstall, since it gets handled by the package manager. See description pages in (en) and (de) and this download link.
Thanks for sharing your experience!

Arend Lammertink

unread,
Jul 9, 2016, 2:13:59 PM7/9/16
to BeagleBoard
Hi Thomas,

Thanks for the tips. I have been working on making a build system and debian packages for fb_prussdrv and libpruiio, etc.

First of all, I patched the original pru assembler with your changes, whereby I exchanged your '-y' switch to a '-f' switch, because '-y' suggest something like 'assume yes' and -f was not used. I forked the beagleboard/am335x_pru_package for this:

https://github.com/l4m4re/am335x_pru_package

And I sent a pull request to the beagleboard package, which has been accepted and merged. According to Jason,  it will take a while before the patch will be included in the upstream beaglebone debian repository, but it should become available at some point. The new version number for pasm with the freebasic output patch is 0.87.

Secondly, I setup my own debian repository, which includes both freebasic as well as the pru packages:

http://beagle.tuks.nl/

Thirdly, I have been working on a generic build system for a/o C(++), pasm, overlay files and freebasic, LaMake, with which I can now build the fb_prussdrv package and build a debian package, although it is still a bit rough around the edges. I am now working on building the libpruio package, with the goal of also making a debian package for that.  At this moment, only the "config" directory builds. "make install DESTDIR=/tmp/test PREFIX=/usr"  works for that, which builds&installs the overlay binary.

LaMake, fb_prussdrv as well as libpruio can be found at my giithub repository:

https://github.com/l4m4re

If anyone wishes to play around with these, you will have to make a symlink from your git copy of LaMake to /usr/local/include for gmake to be able to find LaMake.

I will continue working on building&packaging libpruio and when I'm finished, I will release debian packages on my repository for all three.

Best regards,

Arend.


TJF

unread,
Jul 9, 2016, 4:13:11 PM7/9/16
to BeagleBoard
Hi Arend!


Am Samstag, 9. Juli 2016 20:13:59 UTC+2 schrieb Arend Lammertink:
I have been working on making a build system and debian packages for fb_prussdrv and libpruiio, etc.

First of all, I patched the original pru assembler with your changes, whereby I exchanged your '-y' switch to a '-f' switch, because '-y' suggest something like 'assume yes' and -f was not used. I forked the beagleboard/am335x_pru_package for this:

https://github.com/l4m4re/am335x_pru_package

And I sent a pull request to the beagleboard package, which has been accepted and merged. According to Jason,  it will take a while before the patch will be included in the upstream beaglebone debian repository, but it should become available at some point. The new version number for pasm with the freebasic output patch is 0.87.

Sounds very good! Thanks for your support.
 
Secondly, I setup my own debian repository, which includes both freebasic as well as the pru packages:

http://beagle.tuks.nl/

Also thanks for adding my packages to your repository. I hope, users will find it. I prefer your third idea:
 
Thirdly, I have been working on a generic build system for a/o C(++), pasm, overlay files and freebasic, LaMake, with which I can now build the fb_prussdrv package and build a debian package, although it is still a bit rough around the edges. I am now working on building the libpruio package, with the goal of also making a debian package for that.  At this moment, only the "config" directory builds. "make install DESTDIR=/tmp/test PREFIX=/usr"  works for that, which builds&installs the overlay binary.

I don't know LaMake. And I have already a build system for the next libpruio release based on CMake. It provides building/installing the libraries binary/headers, building documentations (html and/or pdf) and examples (fb and/or C). The config part is missing, yet. A Debian package can get build by CPack. Unfortunately I'm not keen on building packages and didn't have time for learning, yet.
 
I will continue working on building&packaging libpruio and when I'm finished, I will release debian packages on my repository for all three.

I'd like to get in private email contact, in order to cooperate on that issue. Ie. after some final testing, I could provide the current development source (libpruio-0.4: further pins for GPIO, CAP and PWM; QEP feature; timer feature; running also under kernel 4.x; bugfixes ...) for your package and we could find a solution for the config part together (no BBW nor BBG for testing here).

If you agree, just send your response to either the email adress here, or (prefered) the one in the documentation.

Have a nice weekend!

mesquita....@gmail.com

unread,
Feb 6, 2017, 8:10:52 AM2/6/17
to BeagleBoard
Hello Mr. TJF

First of All, thank you so much for providing support on real-time tasks using a low cost plataform.
I'm trying to apply the libary "libpruio" to make a system for energy meansurement using the beaglebone black. To do this,  I need to enable 2 ADC channels, set a sample time, fil a buffer with the samples and make some calculation that includes the FFT. I'm really newbie on microprocessors, but i wrote a simple C code. The idea of this code is just to make 128 samples os the two channels and print the values. Just it:

#include "unistd.h"
#include "../c_wrapper/pruio.h" // include header
#include "time.h"


//! The main function.
int main(/*int argc, char **argv*/)
{
 
float n[256];
 
int a[256];
 
int i=0;


  pruIo
*io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new driver structure
  pruio_adc_setStep
(io, 9, 1, 0, 0, 0);                                                                  // step 9, AIN-0
  pruio_adc_setStep
(io, 10, 2, 0, 0, 0);


 
if (pruio_config(io, 128, 9<<10 , 156250, 4)){ // upload (default) settings, start IO mode
                              printf
("config failed (%s)\n", io->Errr);}
 
else {


 
if (pruio_rb_start(io)) printf("rb_start failed (%s)\n", io->Errr); // start measurement


 
else{
        sleep
(1);


        i
=io->DRam[0];
        a
[i] = i;
        n
[i] = io->Adc->Value[i];
       
do{
               
if(i != io->DRam[0]){
                        i
=io->DRam[0];
                        a
[i] = i;
                        n
[i] = io->Adc->Value[i];
               
}
       
}while(io->DRam[0] < 126);
        a[io->DRam[0]] = io->DRam[0];
        n[io->DRam[0]] = io->Adc->Value[io->DRam[0]];

        for(i = 0; i<=127; i++ ){
            printf("amostra %d            -----               %f \n", a[i],  (n[i]/65536)*1.8);
        }

}
/* we're done */
}
  pruio_destroy(io);        /* destroy driver structure */
        return 0;
}

 as result, I receive this:

amostra 1            -----               0.000000
amostra
0            -----               -0.000012
amostra
2            -----               1.799561
amostra
3            -----               1.799561
amostra
-1092378024            -----               -0.000012
amostra
5            -----               1.799561
amostra
6            -----               1.799561
amostra
7            -----               1.799561
amostra
-1092377860            -----               0.000000
amostra
9            -----               1.799561
amostra
10            -----               1.799561
amostra
11            -----               1.799561
amostra
12            -----               1.799561
amostra
466005475            -----               0.000000
amostra
14            -----               1.799561
amostra
15            -----               1.799561
amostra
1            -----               0.000000
amostra
-1225151312            -----               -0.000012
amostra
18            -----               1.799561
amostra
19            -----               1.799561
amostra
3            -----               -0.000000
amostra
21            -----               1.799561
amostra
22            -----               1.799561
amostra
23            -----               1.799561
amostra
-1225186212            -----               0.000000
amostra
25            -----               1.799561
amostra
26            -----               1.799561
amostra
27            -----               1.799561
amostra
1            -----               0.000000
amostra
29            -----               1.799561
amostra
30            -----               1.799561
amostra
31            -----               1.799561
amostra
0            -----               -0.000012
amostra
33            -----               1.799561
amostra
34            -----               1.799561
amostra
35            -----               1.799561
amostra
-1092377728            -----               0.000000
amostra
37            -----               1.799561
amostra
38            -----               1.799561
amostra
39            -----               1.799561
amostra
0            -----               -0.000000
amostra
41            -----               1.799561
amostra
42            -----               1.799561
amostra
43            -----               1.799561
amostra
0            -----               0.000000
amostra
45            -----               1.799561
amostra
46            -----               1.799561
amostra
47            -----               1.799561
amostra
0            -----               0.000000
amostra
49            -----               1.799561
amostra
50            -----               1.799561
amostra
51            -----               1.799561
amostra
0            -----               0.000000
amostra
53            -----               1.799561
amostra
54            -----               1.799561
amostra
55            -----               1.799561
amostra
-1225159968            -----               0.000000
amostra
57            -----               1.799561
amostra
58            -----               1.799561
amostra
59            -----               1.799561
amostra
-1092376444            -----               0.000000
amostra
61            -----               1.799561
amostra
62            -----               1.799561
amostra
63            -----               1.799561
amostra
0            -----               0.000000
amostra
65            -----               1.799561
amostra
66            -----               1.799561
amostra
67            -----               1.799561
amostra
6            -----               0.000000
amostra
69            -----               1.799561
amostra
70            -----               1.799561
amostra
71            -----               1.799561
amostra
0            -----               0.000000
amostra
73            -----               1.799561
amostra
74            -----               1.799561
amostra
75            -----               1.799561
amostra
0            -----               0.000000
amostra
77            -----               1.799561
amostra
78            -----               1.799561
amostra
79            -----               1.799561
amostra
0            -----               0.000000
amostra
81            -----               1.799561
amostra
82            -----               1.799561
amostra
83            -----               1.799561
amostra
0            -----               -0.000000
amostra
85            -----               1.799561
amostra
86            -----               1.799561
amostra
87            -----               1.799561
amostra
0            -----               0.000000
amostra
89            -----               1.799561
amostra
90            -----               1.799561
amostra
91            -----               1.799561
amostra
-1225160672            -----               -0.000000
amostra
93            -----               1.799561
amostra
94            -----               1.799561
amostra
95            -----               1.799561
amostra
96            -----               1.799561
amostra
0            -----               -0.000000
amostra
98            -----               1.799561
amostra
99            -----               1.799561
amostra
0            -----               0.000000
amostra
101            -----               1.799561
amostra
102            -----               1.799561
amostra
103            -----               1.799561
amostra
-1225162752            -----               0.000000
amostra
105            -----               1.799561
amostra
106            -----               1.799561
amostra
107            -----               1.799561
amostra
-1092377440            -----               0.000000
amostra
109            -----               1.799561
amostra
110            -----               1.799561
amostra
111            -----               1.799561
amostra
0            -----               -0.000000
amostra
113            -----               1.799561
amostra
114            -----               1.799561
amostra
115            -----               1.799561
amostra
0            -----               -0.000012
amostra
0            -----               0.000000
amostra
118            -----               1.799561
amostra
119            -----               1.799561
amostra
0            -----               -0.000012
amostra
121            -----               1.799561
amostra
122            -----               1.799561
amostra
123            -----               1.799561
amostra
0            -----               0.000000
amostra
125            -----               1.799561
amostra
126            -----               1.799561
amostra
-1092376512            -----               0.000000

As you can see, the index does not obey the right sequency... do you have any idea why doe it happen??

William Hermans

unread,
Feb 6, 2017, 10:51:02 AM2/6/17
to beagl...@googlegroups.com
  Right from the start I see several problems with your code.

125 zero based indexes. Or is it 128 ? Or do you really want 127 indexes ? It's impossible for us to know.

do{
. . .
}while(io->DRam[0] < 126);


This is inconsistent with:

for(i = 0; i<=127; i++ ){
. . .
}


So, I have no clue what io-DRam[] *is*, but I can assume, somehow, you're storing ADC values in DRAM *somehow* Based on your comments. However, first off,  your indexes to not match one another from buffer "packaging" to buffer "unpacking". Secondly, you're not clearing your buffers(arrays) before using them. This is what the "garbage" numbers are coming from. It's just random values in memory, which by the way is very bad from a couple perspectives. But this also leaves these arrays without a NULL termination at the end. Which is very unsafe, as a potential stack overflow. At least this applies for type char[], I'd have to double check the C standard that you're using for your particular case to make sure. Which you can do more easily than I.

Additionally, your code is hard to follow. With variable names such as a, n, and i, and zero helpful comments. The code is not exactly self documenting. But here is what seems to be happening. You're only storing one ADC channel value into the first half of your array. Or maybe the conditional if statement is testing for this somehow( unclear ), and taking care of that ?

Assuming what you really want is 128 samples of the two ADC channels you mention, your code needs to change. You need to check and make sure you're never going to overflow from your arrays. Which may mean your arrays need be of size 256 + 1 for each given type. Secondly, your loops need to be consistent at whichever number of values you wish to store. Thirdly, you need to clear your arrays before you use them, which can be done at array initialization, or by using memset(), after initialization.

A couple of things worth mentioning. In your printf() statement I'm not sure of libpruio's implementation, but from my experience with the beaglebone's ADC, this does not seem right ---> (n[i]/65536)*1.8) Values output from the ADC are in range 0-4095, I'd double check to make sure that is correct. It could be that libpruio's values are different in implementation through some sort of conversation. Secondly, for some reason, it may become readily apparent that your index value may contain a lot of zero's in the middle indexes. You're going to need to look into why that it happening after you clean your code up some. As I said above. I am not familiar with libpruio's implementation, and the rest of your code is not clear enough to make a determination at a glance.
 



mesquita....@gmail.com

unread,
Feb 6, 2017, 11:55:09 AM2/6/17
to BeagleBoard
thank you so much for the answer, Mr. William.

According do the documentation of the libpruio, the variable io->DRam[0] stores the index of the last data read. This data, is stored in the vector io->Adc->Value[].
I Just want 128 samples of each chanel.

In fact, I completely agree with you: there is garbage in the resoults, and this is why it look so strange..

William Hermans

unread,
Feb 6, 2017, 12:06:49 PM2/6/17