当前位置:网站首页>PSIM software learning ---08 call of C program block
PSIM software learning ---08 call of C program block
2022-06-26 04:39:00 【Embedded @hxydj】
stay PSIM Circuit simulation , If a function cannot be built using the circuit component model in the component library , have access to C Program element , To write C Program code implementation . among C Language modules include simplification C Modules and common C modular .C The application method of program module is as follows .
simplify C modular
Call simplification C The steps of the module are . Open the menu bar Elements — Other — Function Blocks — Simplified C block.


Now open a C modular , take C The module is placed in the circuit diagram .
Double click this C The module opens it .
At this point, you can write in this blank area C Code. , Writing C Before code , First, briefly introduce the meaning of each attribute in this interface .
Name : Used to set C Module name .
Input: Used to set the number of input pins , Input pin is used for x Named after the , such as x1、x2、x3 … xn.
Output: Used to set the number of output pins , For output pins y Named after the , such as y1、y2、y3 … yn.
Writing C Code time , There are also two default variables that can be used t and delt,t Refers to the total time the system is running ,delt It refers to the time step , That is, how often the system calls C Module once . For example, the running time of the system is 1s, The time step is 0.0001s, that 1s The clock system will call c modular 1000 Time . This t and delt The value of is oneself in Simulation Control Set in the .
Next write C Code .
Here, the input port and output port are respectively set to one , C The code is also very simple , Set the output signal to twice the input signal . Next, build a simple test circuit .
Enter an amplitude of 10 v , The frequency is 1000 The sine wave signal of , Then measure the output signal . The output waveform is as follows :
It can also be seen from the waveform that the output waveform is the input waveform 2 times .
For time C Modules look more intuitive , You can edit the shape drawing of components . Double-click to open C modular , And then choose Edit Image.
A graphic editing window will open , In this window, you can edit the component shape by yourself .
After editing, see the following :
Close the graphic editing window after editing , At this point, you can see in the simulation circuit diagram C The input / output port of the module will have a text prompt .

Universal C modular
Call general C The steps of the module are . Open the menu bar Elements — Other — Function Blocks — C block.
Universal C Modules and simplicity C The use of modules is basically the same , General C The module is placed in the circuit , Then double click to open .
And simple C Module comparison , Universal C A function type option is added to the module . The functions of these function types are concluded below .
Variable / Function definitions : Define the header file or variable required in the code .
OpenSimUser Fcn: Call the code here once to set the system initialization at the beginning of simulation .
**RunSimUser Fcn:** Here are the specific execution functions C Code . In the simulation process , Each time step calls the code in the secondary module .
CloseSimUser Fcn: Call the code here once when the simulation exits .
And simple C Module comparison , Universal C The module adds the code before the function is run and after the function is executed . It is equivalent to adding an initialization and collection function to the function .
Do the same for C Module code . Here, the input and output ports are set to one , The function of the code is that the output signal is twice the input signal . The code is written in RunSimUser Fcn Inside the module . The other three modules don't matter , Just use the default code .
The I / O port here is not x and y 了 , It is in and out Of Array .
The current module is a function , All parameters are passed in from the function entry . About the detailed usage of this module , Can point Help Button to view the help document of the system .
After writing the code , You can choose Edit Image Button , Yes C Edit the graphic symbols of the module .
Finally, build a simple circuit to test .
The simulation waveform is as follows :
It can be seen from the waveform that , The output signal is the same as the input signal 2 times .
From the above two tests, we can see , simplify C Modules and common C The use of modules is basically the same . But here we should pay attention to one thing , Every C Variables in a block are not valid for other C It is invisible to the program block . take C The value in the block is passed to another C The only way to program a block or other circuit , It is through C The input and output ports of the program block . When C The output of a block is directly connected to another C When inputting a program block , Simulation software runtime , First run the 1 individual C Block , Then run the second C Block .
Finally, a slightly more complex example is used to demonstrate C Usage of modules .


A sine wave generator is used to generate a frequency of 60Hz, The range is 1V The sine wave of . Then use the system's own effective value calculation tool to calculate the effective value of the current sine wave . Send this sine wave to a C Module , adopt C Code to calculate the effective value of the current sine wave . Finally, compare whether the effective values calculated respectively are the same .
Compiling C The code is as follows :
C The code implementation idea is : When the system uses this module at each time step , The sum of the squares of the current input voltage is accumulated , When a period of sampling is completed , Average the cumulative sum , And then we'll make a prescription .
The simulation waveform is as follows :
It can be seen from the simulation waveform that , System native RMS The results calculated by the value calculation tool and C The result calculated by the module is the same .
边栏推荐
- How to use the configured slave data source for the scheduled task configuration class scheduleconfig
- 6、 Project practice --- identifying cats and dogs
- [geek challenge 2019] rce me
- 08_SpingBoot 集成Redis
- 2020-12-18
- Guide de la pompe de données Oracle
- 2021-01-31
- mysql高级学习(跟着尚硅谷老师周阳学习)
- pip 批量完全卸载包
- digital image processing
猜你喜欢

08_ Spingboot integrated redis
![Fastadmin always prompts sqlstate[23000]: integrity constraint violation: 1052 column 'ID' in order clause is am](/img/71/ed3b2ca9e6d4afd2dae3c601b3a75b.jpg)
Fastadmin always prompts sqlstate[23000]: integrity constraint violation: 1052 column 'ID' in order clause is am

Database design (I)

PIP batch complete uninstall package

Introduction to markdown grammar

Resolve PHP is not an internal or external command
![[H5 development] 02 take you to develop H5 list page ~ including query, reset and submission functions](/img/39/64df931d5ec54d7d19ae444fa372ba.jpg)
[H5 development] 02 take you to develop H5 list page ~ including query, reset and submission functions

2.9 learning summary

Minecraft 1.16.5 biochemical 8 module 1.9 version 1.18 version synchronization

Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步
随机推荐
[Qunhui] Internet access + custom port
08_SpingBoot 集成Redis
2021-01-31
1.12 learning summary
Laravel pay payment access process
Numpy index and slice
Rdkit chemical formula molecular formula search
Mobile terminal pull-down loading pull-down loading data
PHP get mobile number operator
Physical design of database design (2)
numpy 索引及切片
CTF crypto (I) some simple encoding and encryption
CDN with OSS acceleration
202.2.9
08_ Spingboot integrated redis
Microsoft prohibits Russian users from downloading and installing win10/11
Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview
Be a hard worker from today on
There is no response to redirection and jump in the laravel constructor [original]
1.14 learning summary