11-16-2011 10:33 AM
Our goal is to generate one 5MHz sine wave during 120 µs, then a 0V DC during 750 µs, and then another 5 MHz sine wave during 150 µs, and to do the whole sequence every 20 ms with an external trigger, using an NI-PCI-5406 signal generator.
I have tried to do the job with the following code, using differnts trigger modes and doing some modifications, some ef them seem to work but there is always gap in the génération. That is i don't always have the two pulses for each trigger pulse. (i've tried some other solutions : stepped, single and loop, ...)
#include "nifgen.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <windows.h>
int main(int argc, char *argv[]) {
ViReal64 freqArray[]={5000000.0,0.0,5000000.0,0.0},durationArray[]={.000120,.000730,.000150,.001};
ViInt32 frequencyListHandle;
ViStatus error = VI_SUCCESS;
ViSession vi=VI_NULL;
ViReal64 amplitude=3.0,dcOffset=0.0;
/*- Initialize the session ----------------------------------------------*/
checkErr(niFgen_init("Dev2", VI_TRUE, VI_TRUE, &vi));
/*- Configure output for sequence mode ----------------------------------*/
checkErr(niFgen_ConfigureOutputMode(vi, NIFGEN_VAL_OUTPUT_FREQ_LIST));
/*- Enable External trigger on PFI_1 input ------------------------------*/
checkErr(niFgen_ConfigureTriggerSource(vi, VI_NULL, NIFGEN_VAL_PFI_1));
/*- Enable burst mode trigger -------------------------------------------*/
checkErr(niFgen_ConfigureTriggerMode (vi, VI_NULL, NIFGEN_VAL_BURST));
/*- Create the frequency list from the defined arrays--------------------*/
niFgen_CreateFreqList(vi, NIFGEN_VAL_WFM_SINE, 4, freqArray, durationArray, &frequencyListHandle);
/*- Configure the frequency list from the defined values ----------------*/
niFgen_ConfigureFreqList(vi, VI_NULL,frequencyListHandle, amplitude,dcOffset,0);
/*- Enable output and start generating ----------------------------------*/
checkErr(niFgen_ConfigureOutputEnabled(vi, "0", VI_TRUE));
//while(1)
//{
niFgen_InitiateGeneration(vi);
//niFgen_WaitUntilDone(vi, 5);
//Sleep(19);
//niFgen_AbortGeneration(vi);
//}
// clear the input buffer, then wait for user input before closing the session.
// (DAQmx devices will quit generating the output when the session is closed).
fflush( stdin );
printf("Press Enter to continue...\n");
getchar();
Error:
/*- Process any errors ---------------------------------------------------*/
if(error != VI_SUCCESS) {
ViChar errMsg[256];
niFgen_ErrorHandler(vi, error, errMsg);
printf("Error %x: %s\n", error, errMsg);
}
/*- Close the session ----------------------------------------------------*/
if (vi) niFgen_close (vi);
return 0;
}
12-06-2011 05:47 AM
Hello,
In order to produce a such signal you have to create a digital pattern and edit a script:
script myScript1
Repeat forever
Generate my Waveform
end repeat
end script
You will find more informations in the following link:
http://zone.ni.com/reference/en-XX/help/370524L-01/nisignal_generators_help/programming_script_mode/
Regards
Jean-Baptiste C.
National Instruments France
>> Téléchargez dès maintenant toutes les présentations techniques !