03-28-2018 01:15 PM
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
03-29-2018 02:50 AM
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.
03-29-2018 12:36 PM
how to change frequency in SinePattern () ??/
04-03-2018 03:30 AM - edited 04-03-2018 03:30 AM
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.
04-03-2018 01:06 PM
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, &);
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