Digital Write on Arduino Due Very Slow | 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
Digital Write on Arduino Due Very Slow
November 29, 2016
11:38 pm
Avatar
Cris
New Member
Members
Forum Posts: 2
Member Since:
November 29, 2016
sp_UserOfflineSmall Offline

I just started playing with the LabView compiler using an Arduino Due.  The Arduino Due has a clock speed of 84 MHz.  I wrote a simple routine that writes a high then a low using Digital Write to a single pin.  I tried several versions of this routine.  The last was just a sequence structure sending an alternating high and low.  It takes approximately 2 uSec or well over 100 clock cycles for the bit to toggle.  (All the test routines, regardless of structure (loop, etc) gave me the same 2uSec time.)

I am aware that the digital write is a slow routine in the Arduino, but this is REALLY SLOW.  Is there a work around?  I need to quickly change a 16 bit parallel word.  If I do that pin by pin, it will take a very long time.  There is a port write command.  Would it be faster to write to two (8 bit) ports?

Thanks, Cris

November 30, 2016
12:23 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

This is as expected.  As referenced in the Compilers documentation, this VI uses the DigitalWrite Arduino function which has a lot of overhead for pin mapping.  Refer here for more info.  You can most certainly create your own LabVIEW wrapper around a custom Arduino library or just bare C code and can implement a faster routine as shown in the above link.  Refer also to the porting an Arduino library section in the Compilers help manual for more information on how to do this.  Also, there is an included Digital Write Port.vi you can try.  This will access the whole port simultaneously.  Although, under the hood uses similar pin/port mapping functions that make interfacing easier, so that may add some overhead still.

November 30, 2016
1:25 am
Avatar
Cris
New Member
Members
Forum Posts: 2
Member Since:
November 29, 2016
sp_UserOfflineSmall Offline

Steffan:

I saw that article in my searches regarding the DigitalWrite limitations.  I was a little disappointed that the Arduino Due, which has a clock speed of 84MHz is not much faster than the 16MHz Arduino's for this operation.

This is a bit of a Catch 22 for me.  I am an analog designer and have been using LabView for instrument control for several years.  I was hoping your compiler would give me easy access to programming micro-controllers without having to get my hands dirty with C.  I have already run into my first hurdle!

The Digital Write Port VI is a little confusing for the Arduino Due as it is a 32 bit chip, with ports that are 32 bits wide.  (That is PB goes from PB0 to PB31  I am guessing that once I specifiy the starting pin number it will write to the next consecutive 7 bits of the 32 bit port?

Regards, Cris 

November 30, 2016
5:49 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

The Compiler does abstract away the complexities of the Arduino language and allows you to use LabVIEW but you are still limited to the constraints of thew Arduino language.  Therefore the limiting factor here is the Arduino DigitalWrite implementation, not the Compiler.  But the Compiler does allow you to wrap simple C code with LabVIEW VIs so that may be your only option here, or look around for an existing Arduino library that already implements a higher performance digital write.  If you are looking for higher performance, you will likely have to get your hands dirty.  The Arduino functionality is more tailored for ease of use with the trade off of performance.  As for the Digital Write Port.vi, I just took a look and that will only support AVR based micros, not the Due.  The fundamental problem is that it uses the port manipulation Arduino functions, which are only supported on AVR.  See here for more details.  So your best bet is to look for or write a simple wrapper around direct access to a Due I/O port.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
5
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