LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

motor control by serial port

So now I decided to move to a little hardware Smiley Very Happy

I have been controlling the speed and direction of a DC motor by passing a combination of ASCII values and HEX values.For eg:- P20 will give me some speed P50 will give me another.M1/0 will rotate the motor in both the directions.S will give me counts which has been converted to the respective RPM.

So I have no issues here. But now I have to implement a PID controller with it.

That means Set Point will be decided by user(That is me) and Process Variable(PV) will I think be the feedback from the output of RPM.And, I think output of PID will be given as HEX to VISA.I don't knowSmiley Sad.Am I correct over here? 

How to implement the motor control with the PID block?

Can anyone guide me in the right direction?

0 Kudos
Message 1 of 23
(4,318 Views)

Hi Sunny,

 

the output of the PID is a number used to set an actuator. In your case you have to send that number to your motor control board, which expects strings (not any kind of HEX)! As you already gave examples of the expected strings you would use a FormatIntoString function to form the proper commands.

 

VISA also only uses strings as in-/output, you have to create them anyway!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 23
(4,308 Views)

But with a format into string function don't you think that the appropriate command will not be given to controller.

I mean if ASCII P and HEX 20 gives me some speed then with the function I think it will not give me the expected result. If I give ASCII P and HEX 00 to stop a motor

it will definitely not perform the desired function with the format into string function.

0 Kudos
Message 3 of 23
(4,295 Views)

Hi Sunny,

 

it depends on what you mean by "HEX". There are numerous threads in this forum that deal with the definition of a "HEX" value! "P20" is all ASCII, with two digits representing a hexadecimal formatted number...

 

Given your description before I would use a format string link "P%02x" to form a command like "P20" or "P50"...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 23
(4,293 Views)

I am still not able to figure how to give the output of PID.vi which gives a number  to the VISA write function which expects a string.

Now my set point I have just given it as a complete HEX value and for the PV I have given the feedback of the number of counts. The area where I am stuck up is PID output and VISA input.

0 Kudos
Message 5 of 23
(4,285 Views)

Hi Sunny,

 

as told before: you have to define your "complete HEX value"! What do you understand by that term? Are there any uncomplete values???

 

Please give descriptive examples of a decimal number and the resulting (needed) string...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 23
(4,282 Views)

I am so sorry if  I misundersttod you.

The HEX values are already defined in the microcontroller by me. I am able to pass those values as it is through the VISA.

But when I use a PID block in my VI and give its output to the VISA that is where I am having problem.

0 Kudos
Message 7 of 23
(4,274 Views)

Hi Sunny,

 

it seems you don't want to understand what I wrote...

 

As noted several times before: you have a definition of "HEX values". Would you be so kind to share that definition with us?

When you know the commands needed for your device you could probably give some meaningful examples, as asked before!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 8 of 23
(4,271 Views)

Ok.So these are my HEX values which I give to the controller.

50H 00H is the zero speed command upto 50H FFH is for maximum speed of the motor.

4D30 for anticlockwise and 4D31 for clockwise.

and finally 53H which gives me the required rpm of the motor.

 

0 Kudos
Message 9 of 23
(4,262 Views)

Hi Sunny,

 

you still have to define your meaning of "HEX value"!

Do you send bytes containing 50h 00h (in ASCII you would read "P ") or do you send 4 ASCII chars "5000" (which would be 4 bytes containing 35h30h30h30h).

 

I asked for that definition several times before...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 10 of 23
(4,259 Views)