LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Best Architecture For Custom Motion Controller

I am developing a motion controller card for motor control.
 
Hardware: PCI general purpose IO card (on a PCI slot) with a Xilinx Spartan 2-200 FPGA
 
Software:
 
I developed the GUI using LabWindows/CVI.   The GUI is supposed to display the current positiions and is also used to input new commands to the motor.
I have a ThreadFunction that has a TIME CRITICAL While loop (PID loop)
The FPGA provides a real time stamp along with all the motion parameters (eg position of encoders, status of limit switches etc).
On receiving this info the PC calculates the new value of the PID signal and downloads it to the FPGA.
 
Problem that I am facing:
I am communicating with the GUI by simply updating the value of the GUI controls, using a simple counter to space the GUI updates. I also read the relevant input values from the GUI at the same time.
This method is not working because any GUI activity disrupts the time critical loop, and the system becomes unstable.
 
 
cncgui.c
{
 
ThreadFuntion ()
{
    while
 
 
}
 
 
}
0 Kudos
Message 1 of 4
(3,308 Views)
Hello mjay,

I'm not sure if the code you posted was complete, but are you using the multithreading functions in your application?  In particular, are you spawning another thread in which to run your PID loop?  In order to pass data between the two threads, you might want to look into using thread safe queues/variables.  Maybe, if you could give us some more information on what multi-threading architecture you have already used, we can give a few more suggestions.

Thanks
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 2 of 4
(3,299 Views)
Thanks for your input. I am using multi threading.
I use CmtScheduleThreadPoolFunctionAdv (poolHandle, OpenPopup,
                                          NULL,
                                          THREAD_PRIORITY_REAL_TIME,
                                          NULL,
                                          EVENT_TP_THREAD_FUNCTION_BEGIN,
                                          0, CmtGetCurrentThreadID(), &fnID)
 
to schedule and set the priority of the PID loop thread to REAL_TIME.
 
However I find that even without any GUI updates the GUI is very unresponsive. It seems to queue up all the GUI requests, and the result is a very sluggish GUI response. My pid loop has very stringent time requirements. Requires a 100microseconds cycle time. Max jitter can go upto 500 micro seconds.
 
Any suggestions on how I can keep my PID cycle time and still have smooth GUI interactions, all with one processor. Is there any more tuning I can do. I first want this to work smoothly without my PID loop updating the GUI. I will then add the updates later.
 
Thanks
 
0 Kudos
Message 3 of 4
(3,282 Views)

If you can only stand 500 microseconds of jitter than you definitely cannot do this with Windows alone - you need real-time hardware/firmware support for this. (On my stringent real-time application I had a hardware buffer to allow up to 40ms of software (ie Windows) jitter - just about met this by running the data handling thread at the TIME_CRITICAL priority level. Then implemented another 4 seconds worth of software buffering to pass the data across to the (normal priority) GUI for display/filesystem storing etc.) Can you not have your FPGA do some of the more time-intensive tasks?

JR

0 Kudos
Message 4 of 4
(3,273 Views)