Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I get erroneous voltage readings from scope

I wrote this program (mentioned below) to get a voltage reading (amplitude) from a TDS 540 scope.
But i only get an erroneous result ie the reading returned to me is a ridiculous 9.3e+37 or something to that effect.
I tried changing the type to RMS instead of AMPLITUDE but the result was still the same.
Infact the result is still 9.3e+37 even if I don't give an input to the concerned channel.
This has been vexing me for quite some time and I'd appreciate any help on the matter.

Here's the program:

#include
#include
#include


#include
#include

#define ARRAYSIZE 1024 // Size of read buffer

#define BDINDEX 0 // Board Index
#define PRIMARY_ADDR_OF_SCOPE 3 // Primary address of device
#define NO_SECONDARY_ADDR 0 // Secondary address of device
#define TIMEOUT T1s // Timeout value = 1 seconds
#define EOTMODE 1 // Enable the END message
#define EOSMODE 0 // Disable the EOS mode
FILE *f1;
int Dev,i;
char ValueStr[ARRAYSIZE + 1];
char ErrorMnemonic[21][5] = {"EDVR", "ECIC", "ENOL", "EADR", "EARG",
"ESAC", "EABO", "ENEB", "EDMA", "",
"EOIP", "ECAP", "EFSO", "", "EBUS",
"ESTB", "ESRQ", "", "", "", "ETAB"};

void GPIBCleanup(int Dev, char* ErrorMsg);


int main()
{


Dev = ibdev(BDINDEX, PRIMARY_ADDR_OF_SCOPE, NO_SECONDARY_ADDR,
TIMEOUT, EOTMODE, EOSMODE);
if (ibsta & ERR)
{
printf("Unable to open device\nibsta = 0x%x iberr = %d\n",
ibsta, iberr);
return 1;
}

ibclr (Dev);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to clear device");
return 1;
}


ibwrt (Dev, "*IDN?\n", 6L);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to set oscilloscope");
return 1;
}


ibtmo(Dev,13);
ibwrt(Dev,":MEASUREMENT:MEAS1:SOURCE CH1;TYPE AMPLITUDE", 43);
if(ibsta&ERR)
GPIBCleanup(Dev, "Could not trigger Osc");

ibtmo(Dev,13);
ibwrt(Dev, "MEASUrement:MEAS1:VALue?",24);
if(ibsta&ERR)
GPIBCleanup(Dev, "Could not trigger Osc");

ibtmo(Dev,13);
ibrd (Dev, ValueStr, ARRAYSIZE);
if (ibsta & ERR)
{
GPIBCleanup(Dev, "Unable to read data from oscilloscope");
return 1;
}

ValueStr[ibcntl - 1] = '\0';

printf("Data read: %s\n", ValueStr);


ibonl(Dev, 0);
getch();
return 0;
}

void GPIBCleanup(int Dev, char* ErrorMsg)
{
printf("Error : %s\nibsta = 0x%x iberr = %d (%s)\n",
ErrorMsg, ibsta, iberr, ErrorMnemonic[iberr]);
if (Dev != -1)
{
printf("Cleanup: Taking device offline\n");
ibonl (Dev, 0);
}
}


Thanx.
0 Kudos
Message 1 of 2
(2,906 Views)
Hello,

I see you write 2 strings to the instrument:
":MEASUREMENT:MEAS1:SOURCE CH1;TYPE AMPLITUDE"
and
"MEASUrement:MEAS1:VALue"

I'm counting 44 characters in your first string, not 43, so doublecheck that. Also, I see that you're calling IBTMO multiple times with the same value (10s). I'm not sure what you're trying to do with it, but these calls seem superfluous, since all they do is set the timeout value over and over again. For example, if you're trying to delay between calls, then you'll need to use another function.

Other than that, it seems that this is an instrument-specific error. Be sure that the scope expects these commands to take the measurement that you're looking for. If the scope itself is returning the odd value that you mention,
check the programmer's manual for hints on how to use the scope's commands.

Hope this helps. Perhaps other people who have direct experience with this instrument could lend a hand on that side of things.

Scott B.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 2
(2,906 Views)