Example code | 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 4 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Example code
April 28, 2015
5:13 pm
Avatar
John
Member
Forum Posts: 18
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

This topic is started to post example code.

The code posted here is not tested and has an AS-IS status.

Comments to make the code better or a suggestion on a different approach is always welcome, this is how we can learn from each other.

Thanks, John

Ps, please state versions used:

Compiler, Arduino, LabView, and target used

April 29, 2015
4:33 am
Avatar
John
Member
Forum Posts: 18
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

Timed interrupt feature inspired me to make a very small task manager.

The task example name is Interrupt_Timer_main.vi but because it needs several vi's, i've made a installer like vi.
The installer VI with a zipped project in a string control ;-) ,will ask u to select a folder to put the vi's inside.
It will start the UI and the example code of the interrupt routine with the tasks.

John

Compiler: 10.0.0.14, Arduino 1.6.3, LabView 14, Uno

May 14, 2015
8:21 am
Avatar
John
Member
Forum Posts: 18
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

8 Channels PWM example (Timed interrupt).

This example shows the use of timed interrupt to generate 8 PWM signals.

The frequency for this software PWM generation with 8 channels is ~200Hz

All PWM channels have the same phase and have a resolution of ~1% (range 1-99).

Compiler: 10.0.0.15, Arduino 1.6.3, LabView 14, Uno

June 22, 2015
8:05 pm
Avatar
viwoi
Member
Forum Posts: 16
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

Hello!

 

I intended to create a continuous AI-daq using the timer interrupt. Therefore, there is a main.vi, which I download with the compiler on my UNO-board. In this VI a buffer is beeing sent to a COM-port. The timer is referenced on the GetAI.vi. In this VI the buffer is filled.

There is also the reciever.vi, which is getting data from the COM-port while running on the PC.

My problem is not the interrupt itself, but the communication between UNO-board and PC. There is nothing on the serial port! even if I place a dummy sign to be sent in the while loop.

Why?

 

Another question: could a forum be created especially for code-problems?

June 25, 2015
4:23 am
Avatar
Steffan
Admin
Forum Posts: 305
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Hi there.  There are a couple problems here.  Mainly, you have setup a global U16 buffer of size 1024 and a constant on the main block diagram of another 1024 elements.  Thats 4k of RAM right there and the UNO only has 2k!  So you are killing your program for sure.  The other issue is that the concatenate option of auto-indexed loops is not supported (its a little hard to find) but this is a known issue.   I changed a few other things in your code to simplify things and it now works (with a very small buffer to test).  I also slowed the interrupt down so that the samples can be read out of the buffer faster than they are getting loaded by the interrupt for testing purposes.  I just used the Serial Monitor to verify the output.

Another thing to keep in mind is that you are running your timer interrupt at 1000us.  As documented here and in the VI documentation an analog read takes about 100us.  With the other array manipulation in the interrupt handler timing could be a concern.  Youd have to run some benchmarking to make sure there is enough time in the interrupt to finish before the next one fires.

June 25, 2015
10:19 am
Avatar
viwoi
Member
Forum Posts: 16
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

Steffan said
Hi there.  There are a couple problems here.  Mainly, you have setup a global U16 buffer of size 1024 and a constant on the main block diagram of another 1024 elements.  Thats 4k of RAM right there and the UNO only has 2k!  So you are killing your program for sure.  The other issue is that the concatenate option of auto-indexed loops is not supported (its a little hard to find) but this is a known issue.   I changed a few other things in your code to simplify things and it now works (with a very small buffer to test).  I also slowed the interrupt down so that the samples can be read out of the buffer faster than they are getting loaded by the interrupt for testing purposes.  I just used the Serial Monitor to verify the output.

Another thing to keep in mind is that you are running your timer interrupt at 1000us.  As documented here and in the VI documentation an analog read takes about 100us.  With the other array manipulation in the interrupt handler timing could be a concern.  Youd have to run some benchmarking to make sure there is enough time in the interrupt to finish before the next one fires.

Thank a lot Steffan, I will try it

June 25, 2015
9:03 pm
Avatar
viwoi
Member
Forum Posts: 16
Member Since:
March 19, 2015
sp_UserOfflineSmall Offline

Steffan said
Hi there.  There are a couple problems here.  Mainly, you have setup a global U16 buffer of size 1024 and a constant on the main block diagram of another 1024 elements.  Thats 4k of RAM right there and the UNO only has 2k!  So you are killing your program for sure.  The other issue is that the concatenate option of auto-indexed loops is not supported (its a little hard to find) but this is a known issue.   I changed a few other things in your code to simplify things and it now works (with a very small buffer to test).  I also slowed the interrupt down so that the samples can be read out of the buffer faster than they are getting loaded by the interrupt for testing purposes.  I just used the Serial Monitor to verify the output.

Another thing to keep in mind is that you are running your timer interrupt at 1000us.  As documented here and in the VI documentation an analog read takes about 100us.  With the other array manipulation in the interrupt handler timing could be a concern.  Youd have to run some benchmarking to make sure there is enough time in the interrupt to finish before the next one fires.

Hello Stefan,

 

thanx again for your tips. I tried to do it like you advised (empty array in the global variable, initialization of 128[], instead of 1024[], work-around on tunneling and auto-indexing in the for-loop), but it's still not talking with me. Could you please attach your code, which worked?

How about a new topic like "best practices", where is described why the "usual" way of LV-programming is not working here. My "bad" code could be a topic there... I think it would be helpful for those of us, who are not coming from embedded programming, (like me: application development on OS)

June 26, 2015
3:08 pm
Avatar
Steffan
Admin
Forum Posts: 305
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Sorry, for some reason the edited code did not get attached to my earlier post.  I just added it there called "AI_modified.zip".  It has a 128 byte buffer now and seems to work.

As far as best practices, have you taken a look at the user manual?  There is an "Important Considerations" section that describes exactly what things to be aware of with these limited memory targets.  In fact, in many places in the documentation it tells you to be aware of dynamic memory usage on small targets like the Uno with arrays and string usage.  So please do read the documentation.

December 24, 2015
5:13 am
Avatar
Usufzai
New Member
Forum Posts: 1
Member Since:
December 20, 2015
sp_UserOfflineSmall Offline

Can someone post code for 4-bit interface of alpha numeric LCD? Will highly appreciate..

 

Warm regards

January 27, 2016
8:39 pm
Avatar
pboughner
New Member
Forum Posts: 2
Member Since:
December 4, 2015
sp_UserOfflineSmall Offline

Having a one shot is really useful!

Since I can't get the LabView functions needed to replicate one. I found that this loop gives me a pretty good approximation of one.Light-Duty-oneshot.pngImage Enlarger

I'm sure there is a better way. But three of these on pushbuttons with a trap behind it works pretty good for a tiny HMI.

Attachments
Forum Timezone: UTC 0

Most Users Ever Online: 33

Currently Online:
1 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

John: 18

RTSLVU: 15

Dan6077: 11

Member Stats:

Guest Posters: 0

Members: 80

Moderators: 0

Admins: 3

Forum Stats:

Groups: 1

Forums: 2

Topics: 58

Posts: 289

Newest Members: Travlissah, viktorIcera, HowardClouG, Dianecet, Produktnaodchudzaniex

Administrators: geadmin: 5, filipealtoe: 35, Steffan: 89