Dear Thomas, First of all, Thanks a lot for coming by and answering, I respect your efforts in developing in libpruio!! I cant imaging how much work you must have put in..! :-)
Well, second things is you mean to say if I use 8 ADCs I cant achieve 1.25Khz+ sample rate, Than should I use external ADC? would it be easier? and to be frank I have plenty of doubts in the pruio construct and pruio_config, I which are as follows: - You said I have 183 cycle open delay - but where is it? I have made everything 0 ( zero!!) you can have a look at option setting in line bellow!! - pruio_new(PRUIO_DEF_ACTIVE, 0, 0, 0) - And in my pruio_config, I have made averaging to 0 (you can see that as well). delay 0, - pruio_config(io, 1, PRUIO_DEF_STPMSK , 0, 4) So, is my configuration is wrong or the approach? few queries with respect to your new example - This is also for only 3 ADC channels, so if I extend it for 8, will this one also become slow? - I am going to "monitor" the inputs continuously, so I require continuous stream of input, will this approach work? - Its later part of my project but I saw u using system timer so asking that I also want to time stamp the data with system time, so can it be done here or should I do it later? Sorry if my queries sound novice but I am new to this & I am felling overwhelmed by the whole thing..!! :-) I have been reading the processor TRM and PRU reference manual and I petrified, its kind of ocean of information. ( it remind me of "The old man & the sea"!! ) Sincerely, Rathin PS: On Wednesday, September 30, 2015 at 11:35:25 PM UTC+5:30, TJF wrote: > > Hi Rathin! > > I didn't read all the stuff in the posts of this thread. But most of it > seams irrelevant. Forget it. > > You're using libpruio. That's the only way to reach your target --> That's > OK. > > You cannot reach 20 kHz sampling rate due to two reasons: > > - you're using default step configuration. This is 183 cycles open > delay and avaraging 4. That means 183 + 1 + 4 x 14 cycles for each sample > (@ 24 MHz) = 10 kHz per channel. Therefor maximum sampling rate for 8 > channels is 1.25 kHz. > - you're using IO mode. The ARM CPU determines the sampling speed and > your printf statement slows down the program execution, so you don't get > the previous mentioned 1.25 kHz. > > In order to reach 20 kHz sampling rate you have to do > > > 1. configure customized steps for fast sampling (ie. no open delay and > no avaraging) > 2. use either MM or RB mode to get accurate timing > > Either have a look at the triggers > <http://users.freebasic-portal.de/tjf/Projekte/libpruio/doc/html/_cha_examples.html#SubSecExaTriggers> > > example (to use MM mode) or check out the following code (comming from an > example named rb_file for next libpruio versions) > > > /** \file rb_file.c > \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-1 and AIN-2 get configured > for maximum speed, sampled in to the ring buffer and from there saved > as raw data to some files. > > Licence: GPLv3 > > Copyright 2014-2015 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net > > Thanks for C code translation: Nils Kohrs <nils[ dot ]kohrs{ AT }gmail[ > dOt ]com> > > Compile by: `gcc -Wall -o rb_file rb_file.c -lpruio -lprussdrv` > > \since 0.2.0.2 > */ > > #include "unistd.h" > #include "time.h" > #include "stdio.h" > #include "../c_include/pruio.h" > > //! The main function. > int main(int argc, char **argv) > { > const uint32 tSamp = 123401; //!< The number of samples in the files > (per step). > const uint32 tmr = 5000; //!< The sampling rate in ns (5000 -> 200 > kHz). > const uint32 NoStep = 3; //!< The number of active steps (must > match setStep calls and mask). > const uint32 NoFile = 2; //!< The number of files to write. > const char *NamFil = "output.%u"; //!< The output file names. > struct timespec mSec; > mSec.tv_nsec=1000000; > pruIo *io = pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1); //! create new > driver > if (io->Errr){ > printf("constructor failed (%s)\n", io->Errr); return 1;} > > do { > if (pruio_adc_setStep(io, 9, 0, 0, 0, 0)){ // step 9, AIN-0 > printf("step 9 configuration failed: (%s)\n", io->Errr); break;} > if (pruio_adc_setStep(io,10, 1, 0, 0, 0)){ // step 10, AIN-1 > printf("step 10 configuration failed: (%s)\n", io->Errr); break;} > if (pruio_adc_setStep(io,11, 2, 0, 0, 0)){ // step 11, AIN-2 > printf("step 11 configuration failed: (%s)\n", io->Errr); break;} > > uint32 mask = 7 << 9; //!< The active steps (9 to 11). > uint32 tInd = tSamp * NoStep; //!< The maximum total index. > uint32 half = ((io->ESize >> 2) / NoStep) * NoStep; //!< The maximum > index of the half ring buffer. > > if (half > tInd){ half = tInd;} // adapt size for small files > uint32 samp = (half << 1) / NoStep; //!< The number of samples (per > step). > > if (pruio_config(io, samp, mask, tmr, 0)){ // configure driver > printf("config failed (%s)\n", io->Errr); break;} > > if (pruio_rb_start(io)){ > printf("rb_start failed (%s)\n", io->Errr); break;} > > uint16 *p0 = io->Adc->Value; //!< A pointer to the start of the ring > buffer. > uint16 *p1 = p0 + half; //!< A pointer to the middle of the > ring buffer. > uint32 n; //!< File counter. > char fName[20]; > for(n = 0; n < NoFile; n++){ > sprintf(fName, NamFil, n); > printf("Creating file %s\n", fName); > FILE *oFile = fopen(fName, "wb"); > uint32 i = 0; //!< Start index. > while(i < tInd){ > i += half; > if(i > tInd){ // fetch the rest(no complete chunk) > uint32 rest = tInd + half - i; > uint32 iEnd = p1 >= p0 ? rest : rest + half; > while(io->DRam[0] < iEnd) nanosleep(&mSec, NULL); > printf(" writing samples %u-%u\n", tInd -rest, tInd-1); > fwrite(p0, sizeof(uint16), rest, oFile); > uint16 *swap = p0; > p0 = p1; > p1 = swap; > } > if(p1 > p0) while(io->DRam[0] < half) nanosleep(&mSec, NULL); > else while(io->DRam[0] > half) nanosleep(&mSec, NULL); > printf(" writing samples %u-%u\n", i-half, i-1); > fwrite(p0, sizeof(uint16), half, oFile); > uint16 *swap = p0; > p0 = p1; > p1 = swap; > } > fclose(oFile); > printf("Finished file %s\n", fName); > } > } while(0); > pruio_destroy(io); > return 0; > } > Desription > > rb_file {#SubSecExaRbFile} > ------- > > \Item{Description} > > This file contains an example on how to use the ring buffer mode of > libpruio. A fixed step mask of AIN-0, AIN-1 and AIN-2 get configured > for maximum speed, sampled in to the ring buffer and from there saved > as raw data to some files. > > \Item{Preparation} > > No preparation is required. Optionaly you can customize the number of > samples, the sampling rate or the number of samples in the source > code and recompile your version. > > \Item{Operation} > > Start the program by `./rb_file` and you'll see console output like > ~~~{.txt} > Creating file output.0 > writing samples 0-65534 > writing samples 65535-131069 > writing samples 131070-196604 > writing samples 196605-262139 > writing samples 262140-327674 > writing samples 327675-370202 > Finished file output.0 > Creating file output.1 > writing samples 0-65534 > writing samples 65535-131069 > writing samples 131070-196604 > writing samples 196605-262139 > writing samples 262140-327674 > writing samples 327675-370202 > Finished file output.1 > ~~~ > > The program created two new files in the current folder, named > output.0 and output.1. The files contain the raw data from the three > ADC channels AIN-0 to AIN-2. > > \Item{Source Code} > > src/examples/rb_file.bas > > src/c_examples/rb_file.c > > > BR > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.