analog read time | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
analog read time
November 27, 2016
4:24 pm
Avatar
miche91
Member
Members
Forum Posts: 35
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

Hi everybody,

I’m developing a kind of engine control unit for control an 4 cyl gasoline engine

Now I’m simply using an hall sensor as interrupt input and a high voltage coil as output

I read a phonic wheel by hall sensor up to 10.000 interrupt/sec, do a lot of math and interpolation and control the coil for generate the spark in a exactly shaft position.

All it’s working very well

Every things must be very very quickly because the time between two interrupt is only 100microseconds and I found out that “serial write” and “analog read” is very slow instances.

My question is: can I write on serial or read from analog pin without stopping my VI for a long time?

I can’t miss an interrupt or an spark

 

Thanks in advance

November 28, 2016
9:00 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

You mentioned 10 interrupts/sec but time between interrupts is 100us.  Do you mean 100ms?  The speed of AnalogRead is fairly slow because of the overhead added to simply the pin mapping process used under the hood by the Arduino library.  Refer to the Arduino documentation here which states it takes 100us for AnalogRead.  You could explore direct access of the analog pin by creating a custom library or wrapping some lower level Arduino code to speed this up.  It may also be faster on higher power Arduino boards or you could look into shields that do faster analog reads too.  For serial write it typically should not take long to execute.  If you are using the hardware serial, then the data should just be placed in a buffer and the interrupt handles sending out.  Unless the buffer is full, it will block.  You may want to investigate where your bottleneck is.  But probably not something you want to do in your interrupt if thats what you are doing and you would not want to use software serial.

November 29, 2016
12:21 pm
Avatar
miche91
Member
Members
Forum Posts: 35
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

thanks Steffan!

I have 10000 interrupt/sec, not 10 than the time between two interrupt is 100uS.

I don't care about the time that Arduino needs to read a value from analog pin, for me it's ok to read 1 value every 5 seconds but I can't accept the my loop remains stationary for 100uS.

It is possible to read analog "On background" or spare the istruction in many loops for not stopping my loop

 

About serial, I have similar problem, when the buffer it is full, serial speed needs about 140uS and it stops the loop

 

thanks

Michele

November 29, 2016
3:11 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Where are you doing the AnalogRead?  If you do it in the main loop (main VI), then your interrupt VI will always interrupt the process and the interrupt wont get blocked.  Same thing for the serial.  Best is to do your analog reads and serial writes in the main loop that is non deterministic, then handle your deterministic interrupts in the interrupt handler.  You can also setup a timer interrupt for any high priority processing that needs to be periodic and deterministic.  This would allow you to execute something at a higher priority at a well defined interval that will not get blocked by the main VI execution.

November 29, 2016
7:57 pm
Avatar
miche91
Member
Members
Forum Posts: 35
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

thanks again Steffan!!!

I've just create a very simple VI, it is similar to my project mean.

I would like, for example, to write on serial the value of SR "time between interrupt" every 1 or 2 or 5 seconds WITHOUT stop the loop

 

what can I do for setup a interrupt timer for take give high priority at my main loop and write on serial with low priority?

 

thanks

November 29, 2016
9:38 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

As I said, anything with low priority should be done in your main loop.  So you would write your time over serial in the main loop.  Then your interrupts should be used to handle anything that is time critical.  You can refer to the Interrupt - Timer.vi example for setting up timer interrupts.  The interrupt handlers will interrupt your main loop whenever they are triggered (ether by a digital input or a timer).

November 30, 2016
12:26 pm
Avatar
miche91
Member
Members
Forum Posts: 35
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

thanks, understood!

Last question: If i put inside main loop a serial write instruction, and an interrupt occurs, when the interrupt VI will be ends and the system come back to main loop, the serial write instruction starts again from scratch or continue from where it left off?

If it have to starts again from scratch, I think I never can't write over serial because time between 2 interrupts is lower than the time necessary to write over serial.

thanks

Michele

November 30, 2016
7:54 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Normally the serial write wont block.  It only copies your data to a buffer in which the serial transmit interrupt handles.  But this is very quick and the hardware peripheral handles clocking the data out.  To answer your question, if the copying of serial data to the transmit buffer got interrupted in the middle during the Serial Write call, after the interrupt completes, it will continue where it left off, it would not start again.

In your case, it sounds like you are maybe overflowing your transmit buffer, so the serial write will block until there is room in the buffer.  In this case your main VI will block but if any of your interrupts go off it will interrupt the main VI and process the interrupt, then go back to waiting for the buffer to empty.

December 10, 2016
4:28 pm
Avatar
hib
Member
Members
Forum Posts: 5
Member Since:
December 10, 2016
sp_UserOfflineSmall Offline

I am also in need of faster read times for a singe analog input channel.  in ardunio IDE there are several way to speedup such as changing the prescaler value of the a/d from 128 to values as low as 1, with proportional seed up of consecutive reads.  however the initialization in analog read is slow and cant be affected. so this speedup appears to be mainly for continuous reading of a stream of data.

>>> How can I insert  this into the compiler to initialize the ADC library  wiring.c  ?

 

ref: http://www.microsmart.co.za/te.....duino-adc/

"   If you are using the Arduino libraries, you can search the file wiring.c to find where the ADC is being configured. On my installation it appears starting on line 276. Here is the excerpt.

#if defined(ADCSRA)
    // set a2d prescaled factor to 128
    // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
    // XXX: this will not work properly for other clock speeds, and
    // this code should use F_CPU to determine the prescaled factor.
    sbi(ADCSRA, ADPS2);
    sbi(ADCSRA, ADPS1);
    sbi(ADCSRA, ADPS0);

    // enable a2d conversions
    sbi(ADCSRA, ADEN);
#endif
December 11, 2016
4:57 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

There are a couple ways you can do it.  The simplest would be to just modify the Arduino library itself at the code you referenced above (looks like this in in wiring.c per the link).  Since the Compiler uses the Arduino libraries directly, you can make the change there.  Although this of course affects all programs using the library.  Another way to do it is to modify the appropriate registers at the application layer after they have been initialized by the Arduino library, which is how the referenced article does it.  To do this you could create a custom LabVIEW wrapper around the C code.  You can refer to the help manual which explains how to port Arduino code and libraries to LabVIEW.  The first option would be quicker.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
21
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356