LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I run sample routine more quickly?

How can run sample routine more quickly?
Dear Sir or Madam:
I'm using LabWindows/CVI to build a project. I need to get some sample data and then show these data on the computer screen. The sample circuit is made by myself, and the sample IC was AD1674(A/D conversion circuit, 12 bits). One cycle takes 0.5s, and it must finish sampling 1024 points. That means one sample point should not spent more than (0.5/1024)s. Within this time, the sample routine and the drawing must be finished, meanwhile the user interrupt event must be monitor. I used ASM code in sample program, I make this sample program as DLL in VC++, and link it to the main program written by CVI.
The problem is that the drawing on the computer screen is not continuously, it stops one or more times within one cycle. The part of the program showing as following:
Extern short int YdCmpS(short int iCmpValue, short int iResValue);
// YdCmpS is the DLL which is linked to CVI.
int main (int argc, char *argv[])
{
double TestAngle;
int ButtonVal;
if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */
return -1; /* out of memory */
if ((ydypanel = LoadPanel (0, "ydydemo1.uir", YDYPANEL)) < 0)
return -1;
DisplayPanel (ydypanel);
SetIniMember();
RunUserInterface ();
}
int CVICALLBACK TimerCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int ButtonVal;
double show_r; //showing radius
Point Endpoint;

if (event==EVENT_TIMER_TICK)
{
GetCtrlVal (ydypanel, YDYPANEL_YDYBUTTON, &ButtonVal);
if(ButtonVal) {
GetCtrlAttribute (ydypanel, YDYPANEL_YDYRING, ATTR_CTRL_INDEX,
&AmpIndex);
GetCtrlVal (ydypanel, YDYPANEL_YDYRING, &AmpFactor );
Ydnoise[0]=YdCmpS(0,AmpFactor);
Show_r= Ydnoise[i] * ChkValue +ChkRadius;
if(show_r>=MaxShowRadius) show_r=MaxShowRadius;
if(show_r<=MinShowRadius) show_r=MinShowRadius;
show_x=show_r*CosAngle[0];
show_y=show_r*SinAngle[0];
DrawPoint[0]=MakePoint(show_x, show_y);
CanvasStartBatchDraw (ydypanel, YDYPANEL_YDYCANVAS);
CanvasSetPenPosition(ydypanel, YDYPANEL_YDYCANVAS,DrawPoint[0]);
for(i=1;i SetCtrlAttribute (ydypanel, YDYPANEL_YDYCANVAS, ATTR_PEN_COLOR,
PenColor);
CanvasDrawPoint(ydypanel, YDYPANEL_YDYCANVAS,DrawPoint[i-1]);
SetCtrlAttribute (ydypanel, YDYPANEL_YDYCANVAS, ATTR_PEN_COLOR,
VAL_RED);
Ydnoise[i]=YdCmpS(i,AmpFactor);
Show_r= Ydnoise[i] * ChkValue +ChkRadius;
if(show_r>=MaxShowRadius) show_r=MaxShowRadius;
if(show_r<=MinShowRadius) show_r=MinShowRadius;
show_x=show_r*CosAngle[i];
show_y=show_r*SinAngle[i];
Endpoint=MakePoint(show_x, show_y);
CanvasDrawPoint(ydypanel, YDYPANEL_YDYCANVAS, Endpoint);
DrawPoint[i-1]=Endpoint;
}
CanvasEndBatchDraw (ydypanel, YDYPANEL_YDYCANVAS);
}
}
return 0;
}

Thank you very much!
0 Kudos
Message 1 of 7
(3,340 Views)
I don't have a complete answer to your problem but I would like to offer a suggestion.

Instead of using a timer and handling the EVENT_TIMER_TICK message maybe you should use a thread. Threads give two advantages here.

One is you can continuously update your data knowing that you have resources assigned specifically to capturing the data within your sample time. You can also give priority to this operation making sure that all messages related to that operation are handled first thus increasing your chance of getting the job done in the time allowed.

Secondly, you remove the problem of not knowing exactly when your TIMER_TICK message is going to be handled. I've had a hard time trying to use timers for any kind of precision timing. They are grea
t for monitoring things during your test like error flags for instance, but for timing critical applications threads are much more capable.

I won't say anymore in case I'm completely not helping you so as to not waste more of your time. If you are interested in some simple thread application programs let me know. CVI 5.5 handles them really well so I hope you have upgraded to it.

Good luck to you.

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
Message 2 of 7
(3,340 Views)
Dear Grant:
I've read your answear.Thank you so much.But I'm not familiar with windows programming. I've no idea about using multi thread. Would you please give me some suggestion? Can I find some example in CVI 5.0? Thank you very much!
My e-mail is:zhongma@chinese.com
and my ICQ is :26098640
0 Kudos
Message 4 of 7
(3,340 Views)
MerryMay:

I agree with Grant; using a dedicated thread is the ideal solution for this. Since you are already using the batch drawing functions for the canvas control, your canvas drawing should already be pretty fast. You could also try changing the sleep policy under the Options menu in the Project Window. This option affects how much of the computer's time LabWindows/CVI will use to watch for and handle LabWindows/CVI events.

I hope this helps,

Chris Wood
Applications Engineer
National Instruments
0 Kudos
Message 3 of 7
(3,340 Views)
Dear Chris:
I've read your answer.I'll try your method. But I'm not familiar with windows programming.And I haven't got experience of multi thread.Would you pleas give me some suggestion? Can I find some example in CVI5.0 or anywhere else? Thank you so much!
my e-mail : zhongma@chinese.com
my OICQ: 26098640
0 Kudos
Message 5 of 7
(3,340 Views)
You can use a asynchronous timer because the function called is inside another thread.

Look at 'asynctmr.fp' and the sample cvi>>samples>>toolbox>>asyncdem.prj
0 Kudos
Message 6 of 7
(3,340 Views)
Dear Pierre:
Thank you very much! I'll try what you suggest.And I hope I can come over this problem.
0 Kudos
Message 7 of 7
(3,340 Views)