Email Subscription

The objective of this tutorial is to control 5 servo motors interfaced with PIC16F877A by sending commands serially using Labview.. This whole thing will be simulated on proteus which is an excellent simulation tool.As far as controlling the motor goes , it is explained clearly in my tutorial on servo motor.Now next task is to prepare labview for serial communication and then create the link between labview and proteus .

Labview is graphic programming language and is really easy to use as everything is already done by folks at national instruments.

So for serial communication there is already a built in VI in labview and we will be using that only and also some general string and integer functions.For serial communication VISA driver has to be installed .Below is the image of labview front panel.

The front panel includes control for serial communication like selecting the COM port , parity bits and some other controls. There is a knob for selecting the motor and a slider to select value to be sent to motor and it varies from -9 to +9. There is a button to control the flow of data . But the whole magic happens in block diagram so here is the image of that.

In block diagram as you can see everything is enclosed in a while loop. Flowchart for this piece of code is that a motor switch selects the motor and accordingly a case is selected therefore in all there are 5 cases one for each motor. In each case same thing happens i.e input from slider is checked whether it is greater or equal to 0 if yes then ‘+’ is sent or else a ‘-‘ is sent(the other case selector). Now only string can be sent through serial communication so everything has to be converted into string which includes motor no. , the value to be sent and also the sign of value and string terminator”/”. So if you select motor 3 and value 7 using the slider then data that is sent is ‘3+7/’.Instead of sending the string together , I’ll send it character by character which makes the handling of string easier on controller side.So for this task I’ll use “String Subset vi” to take out the characters from the string and then send it. Now whenever the switch is pressed then data is sent to controller. There is a delay in serial communication case so as to smooth the things a little bit because controller is already busy with controlling motor and if you poke it by sending data continuously it gets pissed and stops working properly.

Now after this next thing is to download ” virtual serial port driver” . Since there is no physical connection between labview and proteus , using the above mentioned tool a pair of virtual serial ports are created which both labview and proteus can read . In the software just click add pair and a pair will be created . I have used COM4 for labview and COM3 for proteus.

Now we come to proteus and below is the image showing the connections.

.There is PIC16F877A connected to DB9 connector (COMPIN in proteus library). It has to be configured by editing its properties (Right click on the symbol), COM3 is selected and baud rate is set 9600. Now to burn the code ,by loading the hex file by right clicking on controller selecting the program file and also change the controller frequency to 2OMhz. Now everything is configured and here is the code which is compiled in MikroC.

The above code is similar to code mentioned in servo controller tutorial with 2 changes. First is the UART function and second is the Delay function.In UART function each character received is stored in an array like “output[0] stores the motor no.” . When string terminator character is received then the increment value “output[2]” is converted to int because the value received through is string type . Now the value is in ASCII format so if data sent is 2 then value we have is 50 ,ASCII for 2 and to get original value 48 is subtracted. Now a case structure is used to select different motor (value in output[0]) and in each case value of delay is updated and the second case structure is for sign of value(output[1]).

The reason I chose to use my own delay function is that Mikroc predefined delay function “delay_us” will only accept constant value and our delay value is variable.

The above mentioned code works fine for me and below is the download link for every file and if you have any doubt or any suggestion just leave a comment.