@KerimF:
Creating these components is relatively easy.
I will do a tutorial when this feature is more completed, but here are some basic explanations:
There are 3 files:
name.mcu:
This file describes the device: type, internal components and some other characteristics.
For this VCO it is very simple, just an Input Pin and an Output Pin.
Pins are always included in Ports, even if it is a single Pin.
If you have a look at vco.mcu you will se that it just describes the type, the script used and a Port with 2 pins:
- Code:
<iou name="VCO" core="scripted" script="vco_core.as" >
<ioport name="PORTA" pins="In,Out" />
</iou>
A Microcontroller for example will have other stuff inside like RAM, ROM, Timers, Usart, ADC, etc.
name.package:
This file describes the external package, what you see in the circuit.
Pin Ids must be the same used in name.mcu.
This file is not supposed to be edited manually, but graphically using "package" component:
https://www.simulide.com/p/new-subcircuits.htmlname.as:
This is the script that describes the behavior of the device.
There are some functions and procedures that must be used to interface with simulide.
Syntax is similar to C++, but even if you don't know C++ you can understand it perfectly and just use the same syntax.
I will explain what is used in this VCO:
1- You need to get "handlers" for the Pins you are using:
- Code:
IoPin@ inputPin = component.getPin("In");
IoPin@ outputPin = component.getPin("Out");
Now "inputPin" and "outputPin" are the handlers for your Pins.
Note that we request Pin handlers using the same names defined in .mcu file.
2- Functions:
SimulIDE will always call some functions (if they are defined in the script):
setup() Called when the component is created (only prints a message in VCO).
reset() Called every time the simulation starts. Used to initialize stuff.
In this VCO component it sets one pin to be an input and other to output:
- Code:
inputPin.setPinMode( 1 ); // Input
outputPin.setPinMode( 3 ); // Output
Note that we are using the handlers created previously.
Then we initialize the voltage for the output Pin:
- Code:
outputPin.setVoltage( 0 );
We want to Know when the input Pins changes voltage to recalculate our output.
For that we use
changeCallBack() :
- Code:
inputPin.changeCallBack( element, true ); // Register for Input Pin voltage changes
"element" is just a pre-made handler, it just must be like this.
"true/false" if you want to register or unregister for voltage changes.
Now, every time Input Pin changes voltage SimulIDE will call the function
voltChanged()So in voltChanged() we read the voltage of Input Pin and do whatever we want:
- Code:
void voltChanged()
{
double input = inputPin.getVoltage();
print("DAC input changed " + input );
outputPin.setVoltage( input );
}
Note that in this case it just sets output voltage = input voltage.
But you can do some calculations here and set the output voltage or whatever you want.
Note that you can use the print() function to print messages in the bottom panel.
For the VCO component we don't want to set the output voltage here but generate a clock signal.
This requires an extra step and the use of another function, but I think it is better to go step by step and be sure you get this working and understand the basics.
To create other "analog blocks" you can just copy/paste these files and edit them with your requirements.