Aside from its core electronics simulation capabilities, PSIM offers a flexible environment for creating custom signals out of known data and customizing simulations in general. Key tools include controlled sources, math blocks, script blocks, and lookup table blocks. This article focuses on using lookup table blocks in PSIM.
Let's start with the 1D Lookup block:
When you import the 1D Lookup block into the schematic and click the 'Help' menu, you'll see that this block uses interpolation to determine the output based on the inputs. This means the inputs don’t need to match the exact values of the first column of the lookup table and are not limited by them.
Let's work with a simple example. Imagine we have a custom drive cycle of speed data vs. time, which we want to use as the reference speed for a speed controller. The speed data is saved in a CSV file (accel.csv
), with time in the first column and speed in the second column.
We can load this data by opening the 1D lookup table block and navigating to accel.csv
using the “Open File…” button:
Important Notes:
The CSV data should not contain "column headers"; all data from row 1 should be numerical
The first column of the CSV is compared with the input node data of the block to determine the output
The second column contains the actual data that will be interpolated and exported from the output node of the block
In this example, the first column corresponds to time, so the time block will be used in the PSIM schematic. The output will be the speed, which will act as a reference for the speed controller in this simulation, as well as the input to a math block containing a simple second-order vehicle model to determine the load torque based on this speed:
Now let's move to the 2D Lookup Table option, which is a bit more complicated. To maintain the advantages of interpolation, choose the 2D Lookup Table (interpolation) block from the library:
This block contains two inputs and one output. The notation for the first and second input is:
The "Help" menu of the 2D Lookup Table can be a little intimidating, so let's follow the process of setting this up with two separate examples.
1st example
If your 2D lookup looks like this:
Then you need to transform it to the following format to be accepted by PSIM:
Note that there are no names and only numerical data exists. The same as the 1D Lookup
The 2nd and 3rd row data should be in ascending order, otherwise you will get an error
The first row is dedicated to declaring the number of rows and columns the 2D lookup has
The second and third rows contain the datasets of the two inputs of the lookup
The following rows contain the output data
2nd Example
The second example involves a csv file containing coupled inductors losses vs. current vs. frequency. The csv file is named current_vs_freq_vs_losses.csv
, and the data is gathered in three columns in this manner:
We have currents ranging from 1A to 100A [100 unique current test points] and frequencies ranging from 1Hz to 200kHz [44 unique frequency test points].
Therefore, we have 44 different loss data points for current = 1A, 44 different loss data points for current = 2A, and so on... This notation is different from the first example and requires more effort to translate into a format that PSIM will accept.
We can either leverage Excel’s TRANSPOSE function or use a Python script (attached along with data files to recreate) that will read the Ploss data from current_vs_freq_vs_losses.csv
, transpose the data per 44 rows, and save the transposed results in a new file. The transposed results should contain a single row with 44 columns per current testpoint. We have 100 unique current test points so we need to do this process 100 times and thus the final output file will be a dataset with 100 rows and 44 columns:
The dataset and script to replicate can be found in the attachments section:
For the 3D Lookup table, we are referencing the simple 3D LuT block and not the .mat file one:
This block follows the same logic as the 2D lookup table. In fact, it is just a repetition of the 2D LuT logic for every element of the “3rd dimension”. Let’s investigate a simple example provided by one of our users in PSIM’s forum:
In this 3D LuT example, saved as a comma-separated-value file, we have 3 inputs: x1,x2,x3 and 2 outputs: y1,y2.
Important Note
The simple 3D LuT block in PSIM only works for single output LuTs. This means that we need to place two separate 3D LuT blocks parsing the same inputs x1,x2,x3 each and having two separate outputs y1,y2 for this example.
Just for the sake of simplification, let’s work with one 3D LuT block, parsing only the y1 output.
We can notice that:
x1 input has 3 different values: 3, 70, 500
x2 input has 3 different values: 31, 36, 41
x3 input has 2 different values:520, 640
The methodology to define the PSIM compatible csv file is the following:
Please keep in mind that the green, yellow and blue row data should be in ascending order, otherwise you will get an error.
The final file format can be in .csv format. You can load it as .csv from inside PSIM if you select "All Files" while browsing to the file:
You will find the above colorized csv along with the final csv to be used in PSIM attached -> test_3d.zip