LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two loops and questions about arduino

Good night, I'm new in the forum and I'm new in LabVIEW so I'll try to expose my point as clearly as I can.

 

I'm reading the value of a potenciometer with Arduino. I take this value and do some math for convenience. Then, I send the result to the duty cicle parameter of a PWM Write Pin block. I also have a few comparisons which send to two digital pin of arduino high or low to control an H-bridge to drive the motor clockwise and anticlockwise. Until here all is working fine.

 

Next, I need to be able to see the velocity of my motor in LabView. So I decided to make an encoder with an infrared sensor. So, I'm reading the sensor with an Analog Read Pin block and here is when I'm having some troubles..the fact is that my motor reach like 1000 RPM so I need that the while on the left run with a good speed. If I divide the two while loop in to two diferent VI there is not problem at all but if I combine the two loops in one VI..well in a few words, the count starts to be very very slow...and that is not good for me.

 

Regards.  

0 Kudos
Message 1 of 5
(4,095 Views)

I've never used the arduino with LabVIEW but I did see a few problems.  You have race conditions, you're using local variables (something you should do only when absolutely necessary), and you open and close the same arduino interface while it is already open/closed.  I spent a little time cleaning it up.  It still has a problem as it will show an error when exiting but you should be able to fix that by just ignoring that particular error.  I just didn't know what the error would be.

 

Arduino.png

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
Message 2 of 5
(4,043 Views)

Thanks for your help, I really appreciate it. I did what you are mentioning but It seems to be that is the same. My count still very slow.

 

Regards.  

0 Kudos
Message 3 of 5
(4,029 Views)

A couple of optimization thoughts, which the compiler might already be doing (dont know about that): Precalculate the multiplication and divisions to a single multiplication. From what i understand the Arduino isn't very powerful so it can help.

The top div/mult-combo = multiply by 110,86956521739130434782608695652

The top right; mult by 0,01960784313725490196078431372549

lower left; mult by -586,5

 

Also, the bool ==> select is the same as a bool to num-primitive.

I'd also change the mult by 0 or 1 to a case with wire through or send out 0. Actually you could place all dependant caluclations in the case so they're only done when needed.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 5
(3,992 Views)

Hello ChuyOsuna93,

 

Thanks for using NI forums! In addition to what kbbersch is suggesting I recommend you to implement a Simple State Machine software architecture. This is recommended when you want to follow a defined structure path (states), each state can lead to one or multiple states and can end the process flow. Here's a link on how to implement a state machine to your project:

 

http://www.ni.com/white-paper/7595/en/

 

I'm pretty sure that if you implement a defined software architecture you will get rid of those kind of issues that you're currently facing.

 

Hope this information works for you.

 

Regards!

Luis CT
0 Kudos
Message 5 of 5
(3,956 Views)