The other day I was trying to simulate a customized NTC resistor, and finally I came with the solution of creating a new custom component.
First of all, open a .ssc file in order to access to the block editor. Choose a component, for example a resistor, and open the block parameter.
Blocm parameter: Resistor |
.ssc file example |
Inside this block editor we can create any component.
In my case, I would like to create a NTC with B equation dependence:
Code:
component MyNTC_B_equation
Explanation that will appear in the block parameter:
%NTC Name of the component
%Resistor with temperature dependece defined by R = R0* exp(B*(1./T-1/T0))
%Where R is the nominal resistance at the reference temperature in ohms and B is the characteristic temperature constant
% Temperature must be in Kelvin!!!
Pins that will be in our component
%component pins
nodes
p = foundation.electrical.electrical; %+:left
n = foundation.electrical.electrical; %-:right
end
variables
i = {0,'A'};
v = {0,'V'};
end
Parameters by default that the user can change:
%user interface
parameters
R0 = {33,'kOhm'}; %nominal resistance
B = {3000, 'K'}; %characteristic temperature constant
T0 = {300,'K'} %Reference temperature
T = {300,'K'} %Current temperature
end
%function of model
function setup
if R0 < 0
pm_error('simscape:GreaterThatOrEqualToZero','Resistance')
end
through (i, p.i, n.i);
across (v,p.v,n.v);
end
Component behaviour
%component behaviour
equations
v == R0 * exp(B*(1./T-1/T0))*i;
end
end
Note: The code is just the blue one!
Now, in order to create a library with this component, we must save the file in a folder starting with '+'. For example: '+MyComponents'.
Now, in Matlab enviroment, and in the path we have the new folder, we write:
>>ssc_build
MyComponents;
Matlab will give us back a comment:
Generating Simulink library 'MyComponents_lib' in the current directory '...'
And the library will be created with the component inside it.
Custom components library |
Here I have two examples inside my library: NTC and R therms. The library will convert all the .ssc files to inside the folder to components.
If we select our component into a new Simulink model and we double-click it we can see the different parameters that need to be enter by an external user. We can also go to the code of the NTC.
Block parameters: Custom component |
Now, we can use the component in any schematic we want.
With that tool, we can create whatever we need for our examples! If you have an example I will be glad to look at it and use it in my future examples! You can use mine too!
Hope this helps!
Generating Simulink library 'MyComponents_lib' in the current directory '...
ReplyDeleteThis is generated in my matlab.Now ,how to see my model
Hello ! I tried to do so but I cannot add a file containing '+' to MATLAB path and so I am unable to run the ssc_build command. How did you do ?
ReplyDelete