LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

varible sine wave using fixed lut

in user interface i will enter any any amplitude ,freq . and I am passing this data to 12 bit Dac...i need variable sine analog out.

 

user can enter any freq from 0-100hz,I am new to programming please help me

0 Kudos
Message 1 of 5
(3,628 Views)

SinePattern () can help you to generate the data array to pass to the DAC. Take a look at the examples that ship with CVI to understand how it works.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,597 Views)
0 Kudos
Message 3 of 5
(3,583 Views)

SinePattern does not contain the frequency information: actual output frequency depends on the number of samples, number of cycles and the sampling rate of the DA converter.

E.g. a 1-cycle signal of 500 samples output at 1000 samples/sec means a frequency of 2 hz. To obtain a continuous signal, the DAC must be setup to regenerate the same pattern continuously.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,551 Views)

hello... i saw that you have problem yet...

in your user interface, put 2 or 3 numeric slider (amplitude, frequency and noise)... put a timer and strip chart too.. then use the following:

 

int CVICALLBACK timerCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int fDesired=1000; //signals freq
float phase=0;
float pi=3.1415927;
float phaseIncrement; //increment phase
int i, numTraces, fs=18000; //sample freq
double MyNoise1;

switch (event)
{
case EVENT_TIMER_TICK:
amp=5; //signals amplitude

//algorithm begins here:
for(i=0;i<100;++i){
GetCtrlVal (panel, PANEL_NUMERICSLIDE_2, &amp);
GetCtrlVal (panel, PANEL_NUMERICSLIDE, &fDesired);
phaseIncrement=2*pi*fDesired/fs;
phase += phaseIncrement; //calculate the next phase
if(phase>2*pi)
phase-=2*pi; //modulus 2*pi operation
sine[i]=amp*sin(phase);
} //algorithm ends here
GetCtrlVal (panel, PANEL_NUMERICSLIDE_3, &MyNoise1);
if(MyNoise1>0){
WhiteNoise (100, 5.0, -1, MyNoise);
Add1D (sine, MyNoise, 100, sine);
}

DeleteGraphPlot (panel, PANEL_GRAPH, -1, VAL_DELAYED_DRAW);
PlotY (panel, PANEL_GRAPH, sine, 100, VAL_DOUBLE, VAL_BASE_ZERO_VERTICAL_BAR, VAL_SIMPLE_DOT, VAL_SOLID, 1, VAL_RED);

PlotStripChart (panel, PANEL_STRIPCHART, sine, 100, 0, 0, VAL_DOUBLE);
GetCtrlAttribute (panelHandle, PANEL_STRIPCHART, ATTR_NUM_TRACES, &numTraces);
for (i=1; i <=numTraces; i++) //trace is the items of graph, therefore trace legend shows 1 trace
SetTraceAttribute (panelHandle, PANEL_STRIPCHART, i, ATTR_TRACE_LG_VISIBLE, 1);

break;
}

return 0;
}

 

 good luck

0 Kudos
Message 5 of 5
(3,544 Views)