LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Motor Control Problems

Solved!
Go to solution

I am using the code below to try to control one motor with a victor 884 motor controller. When I run the program, the motor knocks, but doesn't move. At first we thought it was a power issue, but we've been troubleshooting it and we don't think that's it. We're still looking into it.

Is there something wrong with our code? Also, it updates very slowly...is there a way to make it update faster?

Drive Debug 2.JPG

0 Kudos
Message 1 of 10
(7,721 Views)

Update: we used a multimeter to measure the voltage coming from the Arduino and the voltage is good...255 gives us 4.97 Volts and 0 gives us 0 Volts. When we measure the voltage coming out of the victor, we get a max of about 0.3 Volts...we also don't see any current on the Arduino or the victors (should we?).

Our theory is that we don't have a strong enough battery to send the pwm through the victor. Our strongest battery is 12V/2.9Ah. We think the battery simply doesn't have the current, so we're going to try to find a strong power supply to test our theory.

Does anyone have any suggestions? On this power issue or on how to make the loop update faster?

0 Kudos
Message 2 of 10
(4,447 Views)

Update #2: We now are very confident that the issue is that we aren't sending a constant pwm...the way our code is written, it's only sending the pwm once and it's not enough to get the motor to move.

How do we send a constant pwm?

0 Kudos
Message 3 of 10
(4,447 Views)

Ok so I am not too sure if what i did was proper but I got my motors to turn. First off you need to setup the port, so drop in the "configure PWM port" block into the workspace but put it outside of the while loop.

Setup  your pins (the pins the motors will plug into on the Arduino), you will be making these "outputs". I wired constants into the inputs so i dont have to keep changing them when i reset the VI. Also, you want to send the byte (00000000) to zero out the ports. DO this also at the end so you dont have the motors spinning when you stop the VI.

Here is a link that will tell you all about arduino ports and why you would want to write to those instead of the pin directly:

http://www.arduino.cc/en/Reference/PortManipulation

**writing to the ports on arduino does low level register status switching (Assembly style on the stack) which saves clock cylcles** Arduino has a clock rate of 16MHz.

Also in your "Write PWM" block you need to send it "unsigned byte" values from 0-255. So change your input into the "Write PWM" block to send unsigned bytes from 0-255. I do not have LabView on this computer or i would have uploaded my VI.

As of the continuous question, you already are making it continuous by putting it inside of a while loop. All you have to do next is like i said above feed it unsigned_byte value, if you want the bugger to spin continuously then send it 255 (11111111  -  128+64+32+16+8+4+2+1=255)

Message 4 of 10
(4,447 Views)

Thank you! I just don't know how to use the port vis. What values go into each terminal of the pwm write and configure port vis?

How do you configure a specific pin and set it as an output?

And the pwm terminal that's on the right side of the configure vi and on the top and right side of the write vi...how do I use those?

Also how do you make the pwm signals labeled 0, 1, and 2 correspond to the specific pins?

0 Kudos
Message 5 of 10
(4,447 Views)

So I looked in the pwm configure port vi and it already has the pins set as outputs? Anyway, I edited my code, but of course it doesn't work...error 5001

Drive Debug 3.JPG

0 Kudos
Message 6 of 10
(4,447 Views)
Solution
Accepted by topic author aks.cristion.filwr

Here is an example I made to give you a better idea. I have not tested it so i am not sure it works.

Make sure you match all the settings from Device Manager (COM#,Baud Rate, etc..). I also noticed on your VI you are not using the VISA resource. If you are tethering your Arduino to the computer through the USB cable, you need to use this Resource to synch your Arduino with LabView.

the two write block before and after the while loop are "Write to Port" blocks. The two inside of the while loop are "write to pin" blocks.

Capture.JPG

0 Kudos
Message 7 of 10
(4,447 Views)

Awesome! My code works now...the Arduino is outputing the correct pwm

0 Kudos
Message 8 of 10
(4,447 Views)

I know this post is quite a bit old, but hopefully I can still get some help.  My group is wanting to run our motor multiple times but after the first time it runs, it does the same knocking thing.  We are using code similar to yours and we want to replace the while loop with a for loop.  The goal is to add a timing mechanism within the loop to only run the motor in one direction for a certain amount of time, stop, and then repeat that timed movement for a set number of times.  We want to run the attached subVI in a loop only passing the Arduino resource and error into and out of the loop.

this is the motor shield we are using

this is the motor we are using

0 Kudos
Message 9 of 10
(4,447 Views)

How long do you want the motor to run each time it runs?  How many times do you want the motor to run?  What speed do you want the motor to run at?    How frequently will you need to change the run time, number of runs, and speed?

hrh1818

0 Kudos
Message 10 of 10
(4,447 Views)