From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Controling a DC motor with encoder on back

Dear all

I am starting wok with arduino uno and labview and a DC motor with encoder on back.

Now I'm trying to work with an encoder  http://www.dfrobot.com/index.php?route=product/product&path=47_110&product_id=634#.UKFvEuTtRgg

Now I can control the motor with http://www.dfrobot.com/index.php?route=product/product&product_id=69#.UKFv1-TtRgg.

My problem now is the encoder, I can read the pulses, but seems something is rong. When motor turns on and with a very slow speed the pules are not constants, seems the arduino don have speed enought to get the pules in right time (or the connection between the pc and arduino).

The signals from A and B encoder output aren't always in oposite sides even the wave of each one are not regular with motor working, I expect a typical sequare wave. 

Please see the example below.

Can some one help me? I put in attach my first program to control a Dc motor with encoder.

Best regards

CPalha

0 Kudos
Message 1 of 46
(39,508 Views)

I recommend you not use the LIFA toolkit when buiding a closed loop position control system when the feedback sensor is a quarrature encoder.   The serial interface between Labview and Arduino is to slow for this type of system.  Instead  the Arduino Uno should be used for all of your controller and encoder electronics.  Labview should just be used as a graphical user interface for sending position commands to Arduino and displaying the actual positon.

The following web page will help you with the encoder electronics.

<http://www.pjrc.com/teensy/td_libs_Encoder.html>

Notice for best performance the encoder must be connected to piins with interrrupt capability and these are pins 2 and 3 on an Arduino Uno.   Next use the link shown there to download Encoder.zip.   Encoder.zip conatins Basic.pde. This sketch will help you with the encoder electronics.

For help with the controller see:

<http://www.arduino.cc/playground/Code/PIDLibrary>

I recommend at the beginning you just use proportional control .  The integral and derivative stuff can be pretty intimadating to a novice.  Stick with the basics until you get more experience.

hrh1818

0 Kudos
Message 2 of 46
(8,607 Views)

Dear hrh1818

Thanks for the reply.

The problem that for my project It will be important a graphical display. I trying to do a 3m long ruler with a rail that this rail will have a IR distance meter.

The motor dc will carry the rail to front and back, the encoder will give me the position of the rail. Then I will see this movements in a graph and the distance from the IR sensor and I will save it in a file (distance, rail position). For me doing this in labview it's quit easy and with NI boards.

Now I have a very cheap board, arduino uno, and I am wondered with this board. I am thinking to change the encoder, only to count one pulse per revolution, do you think this way the connection between the pc and arduino will be fast enought?

In 3m long it is good for me a position each 1cm or greater and for that the motor tunrs many times.

Best

cpalha

0 Kudos
Message 3 of 46
(8,607 Views)

Hi

I think that what you like to do (display the graph in LV) is compatible with hrh1818 proposal.

However, it requires indeed more programming, especially on the arduino side as shown in the examples, and will not be feasible with the  stock .pde provided in LIFA toolkit.

If your target is only to replace the NI hardware with the arduino and modify LV code accordingly, I also fear that you are in a dead end...

Only If the speed  is very slow and accuracy not so issue, then it might work, even in open loop mode...

If you manage to do something, let us know !

question for hrh1818 : you mentioned that a real close loop position regulation is not recommended with a quadrature encoder and LIFA, wich I agree.

But do you think it is more feasible with an analog input instead of the encoder? I don't think so, but I would be happy to be wrong..

regards

antoine

0 Kudos
Message 4 of 46
(8,607 Views)

Dear Antoine

Thanks any way.

I will see better what hrh1818 said.

King regards

CPalha

0 Kudos
Message 5 of 46
(8,607 Views)

A few questions that will help me with my next recommendation.

What is the resoution of your encoder in pulses per revolution?

Does your encode prduce an Index pulse, one puse per revolution?

What is the RPM raring of your DC motor?

Are you using feedback from the encoder to control  speed or angular position?

hrh1818

0 Kudos
Message 6 of 46
(8,607 Views)

Dear hrh1818

What is the resoution of your encoder in pulses per revolution?

Encoder Resolution: 64CPR(motor shaft)/2797CPR(gearbox shaft)

Does your encode prduce an Index pulse, one puse per revolution?

I don´t know?

What is the RPM raring of your DC motor?

Free-run speed @ 12V: 251 rpm

This is maximum, but I will see if it will be fast for my project, for now I am studying everything before mounting.

Are you using feedback from the encoder to control  speed or angular position?

I am trying to get the linear position of a moving "car" in a ruler of 3m long, the precision can be 10cm or less (1cm will be good)

The IR sensor (Sharp) must be accurate but it will be connected to the analog in and I expect there is no problem for that.

Now it will be fine for me starting the acquisition by pressing a software button, the motor starts running (cosntant speed), the encoder gives de linear position and the IR sensor gives the distance beteween the ruler and the ground. When the "car" arrives at the end of ruler (by counting a number of pulses) it came back to the start position.

At the first time my problem was controling the speed and turn mode of the motor with labview, it is resolved, now is the encoder, next the IR sensor:

Thats it!

Thanks for help me

CPalha

0 Kudos
Message 7 of 46
(8,607 Views)

Unfortunately there is no convenient way to use an Arduino Uno to produce one pulse per revolution from an incremental encoder when using LIFA firmare.  However, if you are willing to use an external IC like an uPD4702 it will be fairly easy to use your encoder with Labview and the LIFA firmware, 

<http://documentation.renesas.com/doc/DocumentServer/S14940EJ3V0DS00.pdf>

This chip is an incremental encoder 8 bit up/down counter.  This chip increments or decrements its count with every transition of its A or B signal.  This means when the encoder is rotating in only one direction your 64 pulses per revolution encoder will count up to 256 in one revolution.  There for if we connect the most significant bit to one of the digital pins we can than use Labview and the LIFA firmware to determine when the status of the most significant bit changes from 1 to 0.  This transistion happens once per revolution.  You said the maximum rotational speed of the encoder is 250 RPM or 4.2 revoutions per second.   Hence there is only a maximumm of 4.2 transistions per scond.  Providing you don't do any lengthy computations in your Labview program yuou can sample the status of the most significant bit at least 15 times per second.

One small drawback this chip is no longer in production and about the only source is Ebay.  An alternate approach uses 2 ICs. They are a LS7184 and an 8 bit up/down counter.

hrh1818

0 Kudos
Message 8 of 46
(8,607 Views)

Dear hrh1818

I think it starts complicating....

For me (beginner) I think it more easy to change/replace the encoder to another place (after gear box) and here the pulse are a very slow frequecie.

At this time I only need to count pulses and at this time I don´t care the direction.....

It is dificult to develop a library for LIFA in labview to read one encoder?

I search a lot and many people wants the same, read an encoder with arduino.

Best regards

CPalha

0 Kudos
Message 9 of 46
(8,607 Views)

You said:

"At this time I only need to count pulses and at this time I don´t care the direction.."

How will you count the pulses using LIFA?

You said:

"It is dificult to develop a library for LIFA in labview to read one encoder?"

I can't answer this question because I have never tried to extend the capabilities of LIFA.   Further more I am biased.  If LIFA doesn't have the capability I need to do a task then I would just use Labview and Arduino.  There is lot more Arduino code available that will work with Labview than there is code that will work with LIFA.

hrh1818

0 Kudos
Message 10 of 46
(8,607 Views)