A program to convert Rigol oscilloscopes CSV files to a format readable by LTspice.
This program reads CSV files from Rigol oscillospes and outputs to a time-value format used by LtSpice and other SPICE programs (PWL data).
Download the program from here, unpack all the files in the RAR file to a folder in your computer (e.g., C:\rigol2spice
used in this document)
-
Use your oscilloscope to save a capture in the CSV format to a pen drive, then mount the pen-drive in your computer (example for the pen-drive mounted as drive
D:
, and file saved asNewFile1.csv
) -
Open the Windows command prompt (right-click the Start menu (or press Windows+X) and select "Command Prompt")
-
Run
rigol2spice.exe
with the first argument being the input file an the second argument where you want to save the file to, e.g.:C:\rigol2spice\rigol2spice.exe D:\NewFile1.csv D:\my_capture.txt
Will write a PWL file as
my_capture.txt
inD:\
A Rigol CSV file can store captures from multiple channels (including physical channels and math channels), but a PWL file can only have one channel.
You can analyse and list all the channels in your CSV file with the --list-channels
flag (e.g. C:\rigol2spice\rigol2spice.exe --list-channels D:\NewFile1.csv
) can produce:
Channels:
- CH1 (unit: Volt)
- CH2 (unit: Volt)
Increment: 2us
By default, rigol2spice
will use CH1
. If you want to use channel 2, use the --channel
option and then the channel name (e.g. C:\rigol2spice\rigol2spice.exe --channel CH2 D:\NewFile1.csv D:\chan2.txt
) will save CH2
to D:\chan2.txt
)
Sometimes is useful to clamp the capture between a lower and/or a upper value. Use the --clamp-min
and --clamp-max
flags to apply clamping of the signal. And use the N
prefix to indicate negative values, e.g.:
--clamp-max 5.1
will clamp the upper limit of the signal to 5.1 (vertical unit)--clamp-min N0.1
will clamp the lower limit of the sigal to -0.1 (vertical unit)--clamp-min 0 --clamp-max 3.3
will clamp the lower limit of the signal to 0 (vertical unit) and 3.3 (vertical unit).
You can remove the DC component using the --remove-dc
flag. rigol2spice
will calculate the DC component by averaging the waveform capture.
The --offset
option alllows you to apply a vertical offsset to a signal. In the argument, use the U
or D
prefixes for up and down direction then the desired value, e.g.:
--offset U1
will offset the signal 1 (vertical unit) up (positive)--offset D0.500
will offset the singal negatively (down) by 500m (vertical unit)
You can also use SI prefixes, e.g. D500m
equals D0.500
.
If you want to amplify or attenature the signal (for example, if you forgot to change the probe attenuation compensation on the scope), you can use the --multiply
option. Use the N
prefix to indicate a negative value, e.g.:
--multiply 10
will amplify the signal by 10X--multiply 0.001
will attenuate the singnal by 1000X--multiply N1
will change the polarity of the signal
rigol2spice
will execute vertical orders allways in the following order:
- Clamping (if specified)
- Remove DC (if specified)
- Vertical offset (if specified)
- Multiplication (if specified)
You can shift in time the signal to the left or to the right using the --shift
option, then L
or R
for "left" or "right", and the amount of time you want to shift, e.g:
--shift L5ms
will shift 5 milliseconds to the left--shift R100us
will shift 100 microseconds to the right--shift L0.2ms
will shift 200 microseconds to the left--shift R1s
will shift 1 second to the right
Sample points that end before 0 seconds will be removed.
You can use engineering (e.g., 3.3ns
) or scientific notation (e.g., 5E-3s
). The s
unit is facultative.
Using the --cut
option you can remove sample points of the signal after a certain timestamp. For example, --cut 10us
will remove points of the capture after 10 microseconds, inclusively.
The --repeat
option will allow you to repeat the signal multiple times. E.g., -- repeat 3
will add 3 repetitions of the original signal.
--shift
, --cut
and --repeat
will apply to the capture in this order, from the result of the previous operation.
For example rigol2spice.exe --shift L5ms --cut 7.5ms --repeat 3
will result in:
- Nullify the first 5 milliseconds of the capture, and bring the waveform 5ms to the left
- Remove everything after the new 7.5ms mark. (12.5ms in the original waveform), the total width of the waveform is now 7.5ms.
- Repeat the same 7.5ms three times, the resulting PWL file is 30ms in lenght
You can reduce the sample rate of the capture with the --downsample
option. A --downsample 2
will skip every odd point of the capture and will turn a 100 Megasample/s capture into a 50 Megsample/s capture for example.
To optimize the resulting PWL file, rigol2spice
will skip sample points where the value maintained from the previous point. This produces smaller PWL files for LtSpice that will save CPU time when simulating (due to less parsing), while producing the exact same results.
But you might want to disable this optimisation, for example, if you are passing the results to another tool for analysis/transformation. Use the --keep-all
flag if you want this.
USAGE: rigol2spice [<options>] <input-file> [<output-file>]
ARGUMENTS:
<input-file> The filename of the .csv from the oscilloscope to be read
<output-file> The PWL filename to write to
OPTIONS:
-l, --list-channels Only list channels present in the file and quit
-c, --channel <channel> The label of the channel to be processed (default: CH1)
--clamp-min <clamp-min> Clamp the signal to above this value (use N prefix for negative)
--clamp-max <clamp-max> Clamp the signal to below this value (use N prefix for negative)
-dc, --remove-dc Remove DC component
-o, --offset <offset> Offset value for signal (use D and U prefixes)
-m, --multiply <multiply> Multiplication factor for signal (use N prefix for negative)
-s, --shift <shift> Time-shift seconds (use L and R prefixes)
-x, --cut <cut> Cut signal after timestamp
-r, --repeat <repeat> Repeat signal number of times
-d, --downsample <downsample> Downsample ratio
-k, --keep-all Don't remove redundant sample points. Sample points where the signal value maintains (useful for output file post-processing)
-h, --help Show help information.
To build this program, it's just a simple Swift package, you should be able to build it with a simple on macOS, Windows or Linux:
swift build
I'm not affiliated with Rigol and this is not a project related to Rigol Technologies, Inc.