-
Notifications
You must be signed in to change notification settings - Fork 1
/
sim_lcr.c
executable file
·87 lines (68 loc) · 2.42 KB
/
sim_lcr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <stdlib.h>
#include "lxicontrol.h"
#include <time.h>
#include <unistd.h>
#define LCR "10.225.65.106"
#define OUTPUTFILE "out.csv"
#define LCRPORT 5025
#define RCVMSGLEN 4000000
#define SENDMSGLEN 5
char buffer[SENDMSGLEN];
char responseFromLCRMeter[RCVMSGLEN];
int e4980a;
void sample(int frequency){
char temp[] = ":FREQ ";
sprintf (buffer, "%d",1000+frequency);
strcat(temp,buffer);
printf("%s\n",temp);
IssueCommand(e4980a, temp);
// introduce a time delay, before taking the next reading.
usleep(50);
// sleep 50 mics, wait for oscillation to die.
IssueCommand(e4980a, "*WAI\n");
// Fetching the impedence.
IssueCommand(e4980a, "FETC:IMP:CORR?\n");
IssueCommand(e4980a, "*WAI\n");
strcat(responseFromLCRMeter,ReadResponse(e4980a,200));
IssueCommand(e4980a, "*WAI\n");
}
int main()
{
e4980a = CreateConnection(LCR, LCRPORT);
/*
The following commands were used: Pl refer to the Agilent E4980a precision LCR meter.
IssueCommand(e4980a,":SYST:PRES"); -> Preset
IssueCommand(e4980a,":SYST:REST"); -> Reset
IssueCommand(e4980a,":MEM:CLE"); -> Clear Memory buffer
IssueCommand(e4980a, "*IDN?\n"); -> Identity of Device
IssueCommand(e4980a, ":FUNC:IMP:TYPE CSRS\n"); -> Measurement type of impedence (Ls-Rs,Cs-Rs...)
IssueCommand(e4980a,":FREQ 1000"); -> Setting Frequency for measurment
IssueCommand(e4980a,":VOLT:LEV 1"); -> Setting Voltage level for measurement
IssueCommand(e4980a, "FETC:IMP:CORR?\n"); -> Fetching Impedence
*/
IssueCommand(e4980a,":MEM:CLE");
IssueCommand(e4980a, "*IDN?\n");
printf("%s\n", ReadResponse(e4980a, 10000));
// Initial Setup
IssueCommand(e4980a, ":FUNC:IMP:TYPE CSRS\n");
IssueCommand(e4980a,":FREQ 1000");
IssueCommand(e4980a,":VOLT:LEV 1");
//Data recoreded will be stored in file name 1.csv in the same directory as binary file of form .out
FILE* fp;
fp = fopen(OUTPUTFILE, "w");
//initializing frequency sweep:
//The frequency sweep should ideally be logarithmic, but the device limits the frequency range from 20 - 20khz
//The following code has two parts [1000,5000,4001] and [5001,9981,250]
int freq;
for(freq = 0; freq <= 4000; ++freq)
sample(freq);
for(freq=4001; freq <= 9000; freq += 20)
sample(freq);
IssueCommand(e4980a, "*WAI\n");
fprintf(fp, "%s\n", responseFromLCRMeter);
fclose(fp);
// Resetting .
IssueCommand(e4980a,":FREQ 1000");
IssueCommand(e4980a,":VOLT:LEV 0.2");
}