I am trying to read the analog inputs of a BegaleBoneBlack. So, I have taken the obvious route: to use BoneScript (as it gives me a read function straight away). My code is:
var b = require(‘bonescript’);
var myReadTask;
var myStoreBuffer = [];
function readVoltage(){
b.analogRead(“P9_36”, saveValue)
}
function saveValue(reading){
var vv = reading.value*1.8;
myStoreBuffer[myStoreBuffer.length] = vv;
}
function startMyTasks(){
myReadTask = setInterval(readVoltage,1);
}
function stopMyTasks(){
clearInterval(myReadTask);
}
function finalStage(){
console.log("Number of elements logged = " + myStoreBuffer.length);
}
libpruio is designed to sample ADC at full speed (200 kHz). Accurate timing is available in measurement mode (MM, predefined number of samples) or ring buffer mode (RB, continous sampling).
The library is coded in FreeBASIC. Somebody worked on a JavaScript binding, but I don’t know the current state.
C / C++ bindings and examples are included in the package.
I have installed the package successfully and am now looking at the code (examples) to figure out the usage. I find this very hard… now I am looking at example io_input.c, but there is very little comments included and I do not understand most of the code (e.g., commands like FD_ZERO(&set);
FD_SET(STDIN_FILENO, &set); – or why pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1) has these arguments, etc… ).
Is there any description for more naive users? I mean something to explain how to use this library?
Tasks I would like to do:
–switch to MM or RB,
– read analog values (how to access buffer?) – theoretically 3 functions…
I have installed the package successfully and am now looking at the code (examples) to figure out the usage. I find this very hard… now I am looking at example io_input.c, but there is very little comments included and I do not understand most of the code (e.g., commands like FD_ZERO(&set);
FD_SET(STDIN_FILENO, &set);
FD_… function family is C stuff (I’m no C expert). Look them up in C documentation.
– or why pruio_new(PRUIO_DEF_ACTIVE, 0x98, 0, 1) has these arguments, etc… ).
Sorry, this is a bug (wrong parameter order). For full speed us
pruio_new(PRUIO_DEF_ACTIVE, 0, 0, 0)
Is there any description for more naive users? I mean something to explain how to use this library?
– read analog values (how to access buffer?) – theoretically 3 functions…
MM mode is used in example triggers.bas (FreeBASIC only since it uses graphics).
RB mode example isn’t included in version 0.2. You can find pre-published code by searching this forum for “rb_file”. Find also information on how to re-compile version 0.2 in order to use rb_file (and trigger.bas) at full speed.
The problem is that I do not know any FreeBasic whatsoever … so I am trying hard to figure out the C equivalent.
I think I got it to work now, I can sample at 7us for a single channel in RB mode.
I would like to ask about the parameters of pruio_new(ACT, Av, OpD, SaD) :
Av: documentation says it is averaging. Say, if I set this to 4, does it mean that -during one sampling time- each AINx gives one output (each), but this output is the mean of 4 samples taken from the same AIN? E.g. for Av=4: AIN0_out = (AIN0_sample1+ …+AIN0_sample4)/4 and: AIN1_out = (AIN1_sample1+ …+AIN1_sample4)/4 and …… ?
OpD: open delay : “number of clock cycles the ADC waits between setting the step configuration and sending the start of conversion signal” — Is this the so called ‘settling time’ of a DAQ device, i.e., the time we wait for the internal capacitor to charge/for the voltage signal to settle before we actually make a measurement?
SaD : “sets the sample delay, which is the number of clock cycles the ADC waits before starting (the width of the start of conversion signal). It specifies the number of clock cycles between the single conversion processes” – I do not see why this should not be always 0…. Is there a reason for it, maybe it defines how far in time the measurements will be made if averaging ‘Av’ is used?
Sorry if the questions are somewhat stupid – if you had some good sources where these are taken from/understood/explained, I’d appreciate.
I think your understanding of Av, OpD and SaD is pretty much right. For detailed information check the TI ARM335x Technical Reference Manual, chapter 12 (TSC_ADC_SS).
Note: the parameters of pruio_new() are used to pre-configure steps 1 to 8 (for AIN-0 to AIN-7).