Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication to run a DC motor and to get the (2) sensor outputs, I am in need of URGENT HELP!..

Hello, i am in need of URGENT help with my LabVIEW code, please help me!

In my application, i need to control the speed of a DC motor using a Motorola kind microcontroller (MC). In the mean time, i also need to read the output data of 2 sensors (force and displacement) from an Analog to Digital Conv. ADC - data from the displacement sensor will be used for the feedback control of DC speed.

In order to stimulate the sensors and collect the data out in a PC using LabVIEW by a serial communication, i need to start running the DC first. The way i programmed the microcontroller is as follows;

The "SerialMC VI" sends the following characters to the MC:

"\s" when the "Forward DC motion start button" is pressed, followed subsequently by
"\r" at a rate sufficient to download data as it is collected until the motor stops.
When we want to motor to rewind;
"\b" at the time the "Reverse DC motion start button" is pressed.

Upon recieving "\s", my code will clear memory, make the carriage start moving forward and collecting data.
Everytime an "\r" is recieved, it will send a block of data points to the PC
Upon recieving a "\b", no sensor data collection will be done but just the carriage will move back to its starting place.

As you can see in my "SerialMC VI", in the frame 0, i want to write the 3 different commands in the order specified above by using 3 input strings. Also, as you can see my 2 push buttons ("Forward DC motion start button" and "Reverse DC motion start button") are in frame 1 in while loop. Do i need to use an "Event Structure" to put the push buttons in an order? If yes how? If not, what should i do? And how should i set the 2 push buttons and 3 write strings? Could you please guide me or make the changes in my code?

For the second part of the VI; I know that i'll get the data in ASCII characters. Therefore, i used a "Type Cast" function to have the data in integer format. Then, i want to write the data in two columns in a text file, using "Write to Spreadsheet File" function but i couldn't do that.

And the last two things i want to do is;
Plot the graph of "Force vs. Displacement" and the chart of Force vs. time" after getting the force and displacement data in a 2D array. How can i do these?

I have to get this communication by the end of this week, i am new to LabVIEW and have spent so much time to understand it but i cannot go on any further, i am stuck at this point. Please help me. I have the LabVIEW 6.1 version, in case you make any changes. I really appreciate your help.

Regards...
0 Kudos
Message 1 of 8
(4,955 Views)
Is there anyone that can help me?
0 Kudos
Message 2 of 8
(4,946 Views)
Lizzy,

I read your posting this morning, but it confused me. So I ognored it. Finally I took the time...

> As you can see in my "SerialMC VI", in the frame 0, i want to write the 3 different commands in the order specified above by using 3 input strings.

Well, those controls contain a sample string at this time. You have to replace it by your exact command string. Depending on what you mean with "\r", you might have to right-click the control to switch to '\-code' display mode. If you, however, really mean the two characters '\' and 'r', than write them into the control. Afterwards select the menu '/operate/make current value default'. You may as well change these controls to constants...
What you do then in frame 0 is sending all those commands one after the other to your microcontroller µC.

>Also, as you can see my 2 push buttons ("Forward DC motion start button" and "Reverse DC motion start button") are in frame 1 in while loop. Do i need to use an "Event Structure" to put the push buttons in an order? If yes how? If not, what should i do? And how should i set the 2 push buttons and 3 write strings? Could you please guide me or make the changes in my code?

Several points:
1. An event structure is just for the purpose of reacting on an event (in your case: a button has been pressed or released or whatever). You have to take care of any 'order' by yourself. So first activate just the 'Forward' and deactivate the others. When 'Forward' has been pressed, activate the others and deactivate 'Forward'.
2. This can be done in an event structure, but as well in a while loop (polling).
3. When you use an event structure, put it into a while loop in order to let it react on several events.
4. Search the examples on event structures!

> For the second part of the VI; I know that i'll get the data in ASCII characters. Therefore, i used a "Type Cast" function to have the data in integer format. Then, i want to write the data in two columns in a text file, using "Write to Spreadsheet File" function but i couldn't do that.

Well, in order to explain how to do that you must provide the data foramt of your readings, accompanied with some example data.
What you attempted might be OK, but as you did not achieve what you wanted you probably did something wrong...

> And the last two things i want to do is;
Plot the graph of "Force vs. Displacement" and the chart of Force vs. time" after getting the force and displacement data in a 2D array. How can i do these?

Search the examples on graphing!

> I have to get this communication by the end of this week, ...

This might be a tight schedule for a beginner...

Greetings from Germany!
--
Uwe
0 Kudos
Message 3 of 8
(4,936 Views)
Lizzy, I'm sorry that I don't have much time today to look at this, but here's a quick analysis of your code:
1) you start by configuring the serial port - looks good
2) enter the sequence struture and send all three strings from the front panel controls to the serial port (from your description, it didn't seem like this is what you wanted to do). At the same time, you go into the event structure, but there are no events defined, so your program will hang at this point - obviously a problem here
3) if we pretend the event structure isn't present, you will go the the second frame of the sequence structure and enter the while loop - okay
4) in the while loop, you read the contents of the serial buffer (which, if the \r command stimulates a response, should contain something for the first iteration). You'll get a prompt for a file name from your write to spreadsheet file vi (but nothing is wired to it), and then the process will repeat as quickly as you can hit the cancel button in the file dialog (unless you never depressed the Forward DC motion start button, in which case the program will end). To end the program, you'll have to turn off the Forward DC.. button (which will be tricky with that file dialog popping up as quickly as possible)

So, it looks like you've got the right stuff in here, but not necessarily in the right order, or the best way. To keep things really simple, I'd use three frames in the sequence structure. The first frame would just send the \s command (and no event structure), the second frame will have your while loop, and the third frame will send the \b command. In the while loop, I'd just have a stop button to stop the acquisition (you don't need the forward and reverse buttons - the machine starts when you hit the run button on the vi) and a wait function to time the acquisition. Every iteration of the loop will send a \r command, and then look for a response on the serial port. Take the data and build an array using the shift registers. You can put the write to spreadsheet vi outside of the loop so it only executes at the end (when you click the stop button) assuming you don't run this program so long that it eats up all your memory. If Force and Displacement are coming in from the serial port, you can use a waveform chart to plot them both versus time. If you need to plot Force vs. Displacement, you will have to get a little more creative, but it really depends on what the data coming in is.

Sorry, I don't have more time right now, and I can't post code in 6.1. Work on it for a little while and post back. I might be able to help more later. Hopefully I understood what you were trying to do.

Chris
Message 4 of 8
(4,933 Views)
Hi Lul,

Thanks for your reply. I'm working on the code.

Lizzy
0 Kudos
Message 5 of 8
(4,912 Views)
Hi Chris,

Thanks alot for your response and the suggestions. I have changed my LabVIEW code according to what you have said to make the code simpler. I'll try to have the interface with the microcontroller today. If it doesn't work, i'll post the code and ask my questions about it.

Lizzy
0 Kudos
Message 6 of 8
(4,907 Views)

dear sir

      

           i need your help to create a dual channel data acquation code using labveiw and ni daq6221. i hav created a single channel data acquation code and it is as follows...

 

 so please kindly help me

Download All
0 Kudos
Message 7 of 8
(4,174 Views)
You've hijacked a very old and unrelated thread. Please start a new thread.
0 Kudos
Message 8 of 8
(4,169 Views)