SPRING :: NOTE

[Agilent] N9320B Spectrum Analizer Source ( Marker Peak Search and Peak Excursion) 본문

Development Tools/Keysight · National Instruments

[Agilent] N9320B Spectrum Analizer Source ( Marker Peak Search and Peak Excursion)

RAYZIE 2016. 2. 29. 19:00
반응형


/************************************************************/
/* Using Marker Peak Search and Peak Excursion */
/* */
/* This example is for the N9320B Spectrum Analyzer. */
/* */
/* This C programming example does the following. */
/* The SCPI instrument commands used are given as reference. */
/* */
/* - Opens a USB session */
/* - Clears the Analyzer */
/* *CLS */
/* - Resets the Analyzer */
/* *RST */
/* - Sets the analyzer center frequency, span and units */
/* SENS:FREQ:CENT freq */
/* SENS:FREQ:SPAN freq */
/* UNIT:POW DBM */
/* - Set the input port to the 50 MHz amplitude reference */
/* CAL:SOUR:STAT ON */
/* - Set the analyzer to single sweep mode */
/* INIT:CONT 0 */
/* - Prompt the user for peak excursion and set them */
/* CALC:MARK:PEAK:EXC dB */
/* - Set the peak threshold to -90 dBm */
/* CALC:MARK:PEAK:THR:STAT ON */
/* CALC:MARK:PEAK:THR  */
/* - Trigger a sweep and delay for sweep to complete */
/* INIT:IMM */
/* - Set the marker to the maximum peak */
/* CALC:MARK:MAX */
/* - Query and read the marker frequency and amplitude */
/* CALC:MARK:X? */
/* CALC:MARK:Y? */
/* - Close the session */
/************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include "visa.h"

ViSession defaultRM, viN9320B;
ViStatus errStatus;
ViChar cIdBuff[256]= {0};
char cEnter = 0;
int iResult = 0;
/*Set the input port to 50MHz amplitude reference*/
void Route50MHzSignal()
{
	viQueryf(viN9320B, "*IDN?\n", "%t", &cIdBuff);
	/* prompt the user*/
	/* to connect the amplitude reference output to the input*/
	printf ("Connect CAL OUT to the RF IN \n");
	printf ("......Press Return to continue \n");
	scanf( "%c",&cEnter);
	/*Externally route the 50MHz Signal*/
	viPrintf(viN9320B,"CAL:SOUR:STAT ON \n");
}
void main()
{
	/*Program Variables*/
	ViStatus viStatus = 0;
	double dMarkerFreq = 0;
	double dMarkerAmpl = 0;
	float fPeakExcursion =0;
	/*Open a USB session.*/
	viStatus=viOpenDefaultRM(&defaultRM);
	viStatus=viOpen(defaultRM,"USB0::0x0957::0xFFEF::CN03229432::0::INSTR",VI_NULL,VI_NULL,&viN9320B);
	if(viStatus)
	{
		printf("Could not open a session to USB device\n");
		exit(0);
	}
	/*Clear the instrument*/
	viClear(viN9320B);
	/*Reset the instrument*/
	viPrintf(viN9320B,"*RST\n");
	/*Set Y-Axis units to dBm*/
	viPrintf(viN9320B,"UNIT:POW DBM\n");
	/*Set the analyzer center frequency to 50MHZ*/
	viPrintf(viN9320B,"SENS:FREQ:CENT 50e6\n");
	/*Set the analyzer span to 50MHZ*/
	viPrintf(viN9320B,"SENS:FREQ:SPAN 50e6\n");
	/*Display the program heading */
	printf("\n\t\t Marker Program \n\n" );
	/* Check for the instrument model number and route the 50MHz signal
	accordingly*/
	Route50MHzSignal();
	/*Set analyzer to single sweep mode*/
	viPrintf(viN9320B,"INIT:CONT 0 \n ");
	/*User enters the peak excursion value*/
	printf("\t Enter PEAK EXCURSION in dB: ");
	scanf( "%f",&fPeakExcursion);
	/*Set the peak excursion*/
	viPrintf(viN9320B,"CALC:MARK:PEAK:EXC %1fDB \n",fPeakExcursion);
	/*Set the peak thresold */
	viPrintf(viN9320B,"CALC:MARK:PEAK:THR -90 \n");
	/*Trigger a sweep and wait for completion*/
	viPrintf(viN9320B,"INIT:IMM \n");
	/*Set the marker to the maximum peak*/
	viPrintf(viN9320B,"CALC:MARK:MAX \n");
	/*Query and read the marker frequency*/
	viQueryf(viN9320B,"CALC:MARK:X? \n","%lf",&dMarkerFreq);
	printf("\n\t RESULT: Marker Frequency is: %lf MHZ \n\
	n",dMarkerFreq/10e5);
	/*Query and read the marker amplitude*/
	viQueryf(viN9320B,"CALC:MARK:Y?\n","%lf",&dMarkerAmpl);
	printf("\t RESULT: Marker Amplitude is: %lf dBm \n\n",dMarkerAmpl);
	/*Close the session*/
	viClose(viN9320B);
	viClose(defaultRM);
}


반응형
Comments