Re: [beagleboard] Reading analog inputs fast in beaglebone black

2014-05-24 Thread Christian Keck

I need to read all 7 analog pins in the BBB every 5 milliseconds. I'm
doing so with the following C code:


...


 while(1){
 fread(value_str, 6, 6, f0);
 value_int = strtol(value_str,NULL,0);
 printf(0 %li\n, value_int);
 fflush(stdout);

 usleep(5000);
 rewind(f0);
 }



Hoever, the cpu usage goes up really high (20%). Is there any way to
read the analog inputs differently so that it doesn't use as much CPU?


I would replace printf(0 %li\n, value_int); fflush(stdout); by 
saving the converted values into an array, and print the values only 
when the measurement ist finished.



Someone suggested DMA but I'm completely lost on that regard...


That would be for specialists

Christian

--
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.


Re: [beagleboard] Reading analog inputs fast in beaglebone black

2014-05-24 Thread Rafael Vega


 I would replace printf(0 %li\n, value_int); fflush(stdout); by 
 saving the converted values into an array, and print the values only 
 when the measurement ist finished. 


What do you mean when the measurement is finished? I need to read the 
inputs every 5 milliseconds forever. Is there a ready flag or a time to 
wait after reading the file?

Thanks.

-- 
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.


Re: [beagleboard] Reading analog inputs fast in beaglebone black

2014-05-24 Thread ZubairLK
Christian is correct. Don't use printf. It introduces a significant 
overhead.
remove printf, copy into a variable. Then check and see if you can meet 
timing. *fingers crossed*

Your email mentioned you wanted to acquire all 7 analog inputs for real 
time audio every 5ms.
Depending on your level of processing of the audio, you might face 
difficulty with that. Who knows, might just work.

Is there any correlation regarding timing between the channels? Can you 
acquire a sample from channel 1, sleep 500ms, acquire from channel 2, sleep 
500ms acquire from channel 3, 
Or do all samples have to be acquired simultaneously?

ZubairLK

On Saturday, May 24, 2014 3:23:53 PM UTC+1, Rafael Vega wrote:

 I would replace printf(0 %li\n, value_int); fflush(stdout); by 
 saving the converted values into an array, and print the values only 
 when the measurement ist finished. 


 What do you mean when the measurement is finished? I need to read the 
 inputs every 5 milliseconds forever. Is there a ready flag or a time to 
 wait after reading the file?

 Thanks.


-- 
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.


Re: [beagleboard] Reading analog inputs fast in beaglebone black

2014-05-24 Thread John Syn

From:  Rafael Vega email.r...@gmail.com
Reply-To:  beagleboard@googlegroups.com
Date:  Saturday, May 24, 2014 at 1:23 AM
To:  beagleboard@googlegroups.com
Subject:  [beagleboard] Reading analog inputs fast in beaglebone black

 
 
 I need to read all 7 analog pins in the BBB every 5 milliseconds. I'm doing so
 with the following C code:
 void main(){
 char value_str[7];
 long int value_int = 0;
 
 FILE* f0 = fopen(/sys/bus/iio/devices/iio:device0/in_voltage0_raw, r);
 
 while(1){
 fread(value_str, 6, 6, f0);
 value_int = strtol(value_str,NULL,0);
 printf(0 %li\n, value_int);
 fflush(stdout);
 
 usleep(5000);
 rewind(f0);
 }
 Hoever, the cpu usage goes up really high (20%). Is there any way to read the
 analog inputs differently so that it doesn't use as much CPU? Someone
 suggested DMA but I'm completely lost on that regard...
You should try the IIO driver which you will find under
/driver/IIO/adc/ti_am335x_adc.c. Samples are stored in a buffer which you
can read with a user space app.

Search github for IIO and you will find several user space examples on how
to use IIO.

Regards,
John
 Any help will be appreciated.
 -- 
 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.


-- 
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.


Re: [beagleboard] Reading analog inputs fast in beaglebone black

2014-05-24 Thread John Syn

From:  Rafael Vega email.r...@gmail.com
Reply-To:  beagleboard@googlegroups.com
Date:  Saturday, May 24, 2014 at 1:23 AM
To:  beagleboard@googlegroups.com
Subject:  [beagleboard] Reading analog inputs fast in beaglebone black

 
 
 I need to read all 7 analog pins in the BBB every 5 milliseconds. I'm doing so
 with the following C code:
 void main(){
 char value_str[7];
 long int value_int = 0;
 
 FILE* f0 = fopen(/sys/bus/iio/devices/iio:device0/in_voltage0_raw, r);
 
 while(1){
 fread(value_str, 6, 6, f0);
 value_int = strtol(value_str,NULL,0);
 printf(0 %li\n, value_int);
 fflush(stdout);
 
 usleep(5000);
 rewind(f0);
 }
 Hoever, the cpu usage goes up really high (20%). Is there any way to read the
 analog inputs differently so that it doesn't use as much CPU? Someone
 suggested DMA but I'm completely lost on that regard...
Here is some additional info on IIO that might be helpful:

http://processors.wiki.ti.com/index.php/AM335x_ADC_Driver%27s_Guide

Regards,
John
 Any help will be appreciated.
 -- 
 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.


-- 
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.