Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

RMS voltage

2 posters

Go down  Message [Page 1 of 1]

1RMS voltage Empty RMS voltage Tue Nov 28, 2023 9:16 pm

ru5t



Hi there!
First of all - ton of thanks for such a great and fast piece of software!

The question is about voltmeter. As I can see, it acts like a probe - shows voltage 'here and now'. But how can I get RMS voltage?
Trying to simulate AC -> DC rectifier and RMS voltage would be of great help.

Maybe it could be coded with scripted component? Or am I missing something?
I'm using latest development version build from commit a8daf4dda6aa982c044fe5f65c0b878d3eb7152b.

2RMS voltage Empty Re: RMS voltage Tue Nov 28, 2023 11:10 pm

arcachofo

arcachofo

Hi ru5t.


The question is about voltmeter. As I can see, it acts like a probe - shows voltage 'here and now'. But how can I get RMS voltage?
Trying to simulate AC -> DC rectifier and RMS voltage would be of great help.
Yes this is planned, but not implemented by now.

Maybe it could be coded with scripted component? Or am I missing something?
I'm using latest development version build from commit a8daf4dda6aa982c044fe5f65c0b878d3eb7152b.
Yes it could be done with scripted component.
The script part would be quite straight forward, adding something to display the value is not documented as far as I can remember, but I can help with this.

The downside would be the speed of the scripted component, if it is not for high frequencies it should not be a problem, but in any case it adds some extra cpu usage.

3RMS voltage Empty Speed not a concern Wed Nov 29, 2023 1:07 pm

ru5t



The speed, indeed, is not an issue, so, please guide me on how to script this stuff.

4RMS voltage Empty Re: RMS voltage Wed Nov 29, 2023 1:53 pm

arcachofo

arcachofo

Indeed I already have some voltmeters I did to test scripted components linked with other components to make a display.
One uses a text item and the other one uses 7segment displays.

These voltmeters are 2 level:
There is an scripted component that reads the inputs and send data to linked components.
This scripted component is then linked to displays compoentes in a circuit used to make a subcircuit.

The easiest way to use these in to add the folder "test" to your "User data folder":  https://simulide.com/p/settings/
Next time you open simulide you will see a new category "Test" in the component list with the new components.

There are 4 components:
VoltD: Scripted component.
Voltmeter0: subcircuit with VoltD and 7segment inside.
VoltT: Scripted component.
Voltmeter1: subcircuit with VoltT and test component inside.

You can see all files in File explorer->User Data->test
Note that I made these scripts just for testing , there ase a few missing things, but you probably will see it.

From here you can understand how everything works and edit void voltChanged() in voltD.as or voltT.as to make an AC voltmeter.

For any problem or anything that is not clear to you just comment here.
Attachments
RMS voltage Attachmenttest.zip
You don't have permission to download attachments.
(7 Kb) Downloaded 9 times

5RMS voltage Empty Re: RMS voltage Wed Nov 29, 2023 4:07 pm

ru5t



Managed to attach these components. Stuck for some time 'cause didn't expected 'test' directory name to be one and only accepted name to be loaded to components tree.

So now I'm able to use and tune 'em. But how? )
Looked around a little:
.../data/codeeditor/compilers/compilers/angelscript.xml for *.as files.
Does simulIDE uses this library https://www.angelcode.com/angelscript ? Looks like it.
If so - can you point me to the API available inside of these scripts? I mean there's no code completion available in built in ide. Provided components and this video
do give some hints, but.. documentation (or piece of code) would be much better.
Checked in Knowledge Base but couldn't find any hint.

6RMS voltage Empty Re: RMS voltage Wed Nov 29, 2023 9:14 pm

arcachofo

arcachofo

So now I'm able to use and tune 'em. But how? )
arcachofo wrote:From here you can understand how everything works and edit void voltChanged() in voltD.as or voltT.as to make an AC voltmeter.
Those voltimeters are already done and working (mostly).
The only thing you need to do is to modify void voltChanged() to implement an AC voltmeter.
There are some other details, but I leave it to you.

In that video you can see how to proceed and it explains how voltChanged() works.

If you have some question about some specific issue just ask here.


Does simulIDE uses this library https://www.angelcode.com/angelscript ? Looks like it.
Yes, simulide uses a modified version of that library.

do give some hints, but.. documentation (or piece of code) would be much better.
Here is some documentation:
https://simulide.com/p/scripted/

Piece of code: what about VoltD.as and voltT. as ?

Checked in Knowledge Base but couldn't find any hint.
Next time you can use the search box:

RMS voltage Kk38

7RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 12:38 pm

ru5t



RMS voltage Image12[/url]
Here are the questions:
1: VoltT - isn't it supposed to set linked string value? .setLinkedString( 0, str, 0 ); I thought that voltT-10 would be changed to voltage+" V";
2: (Image is cropped - please open it in new tab) I've set breakpoints, and when I run debug, it stops at voltD start. When I press "run to breakpoint" it is expected to stop inside of setup, or at the volt changed . But nothing stops. As we see in console, the lifecycle event is called. So how to debug scripted components? Maybe, ide should be built with some additional flags?
3: noticed that even if both components have debug messages, if voltD gets debugged, only it's messages are printed. If voltT's script is uploaded once more (even without changes) - both components are printed in console.

8RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 12:58 pm

ru5t



RMS voltage Image13[/url]
First question is solved. Linked string - is for linked text component.
So only debugging question remains.

9RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 1:33 pm

arcachofo

arcachofo

Debugging is not implemented for scripts yet, but you can use print messages.

I see you are using both scipts in the same circuit.
I think I didn't explain the files very well:

There are 2 voltmeters:

RMS voltage Kk39

- Voltmeter0: subcircuit with voltD and 2 7segment inside.
voltD is linked to 2 seven segment displays.

- Voltmeter1: subcircuit with voltT and test component inside.
voltT is linked to a Text component.

Each one is a different approach to build a voltmeter with an scripted component linked to other component that works as a display.
You use one or the other.

The data sent to the seven segments is different than the data sent to the Text component:
- For the 7segment the script needs to send one integer for each display.
- For the Text it can send only a float value.

In your case I would use Voltmeter1 that uses the text component is simpler and easier to use.

You can use the subcircuit voltmeter1 directly, the scripted component is inside it.
For example open: test/Voltmeter1/Voltmeter1_test.sim1

10RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 1:55 pm

ru5t



Oh, I see. Yes I didn't even had a chance to dive into subcircuits you provided yet. So much stuff to ask right from the start. That's because I'm new to Simul IDE and not familiar with most of it capabilities.

Anyways, here's poor man's RMS voltage script. That will do for now.

Code:



IoPin@ inPin  = component.getPin("In");
IoPin@ refPin = component.getPin("Ref");

double Um = 0;
bool positive_half_period = true;
bool printed_in_half_period = false;

void setup() // Executed when Component is created
{
    component.setLinkedString( 0, "00 V", 0 );
    print("VoltT: Linked  setup() OK");
}

void reset() // Executed at Simulation start
{
    inPin.setPinMode( 1 ); // input
    inPin.changeCallBack( element, true );
}

void voltChanged()
{
    double voltage = inPin.getVoltage()-refPin.getVoltage();

   if (voltage !=  0){
      double v_abs = 0;
      if(voltage < 0){
         v_abs = -1 * voltage;
          if(positive_half_period == true){
            // half period changed to -
            Um = 0; // reset Max value
            positive_half_period = false;   
            printed_in_half_period = false;
            print("Negative half-period started: " + v_abs + " ("+voltage+")");
         }
      }
      if(voltage > 0){
         v_abs = voltage;
          if(positive_half_period == false){
            // half period changed to +
            Um = 0; // reset Max value
            positive_half_period = true;
            printed_in_half_period = false;
            print("Positive half-period started: " + v_abs + " ("+voltage+")");
         }
      }
      if (v_abs > Um){
         // rising signal. 0 to Max
         Um = v_abs;
      } else {
         if (printed_in_half_period == false){
            //   update text only once after half period's Um is passed
            double U_rms = Um / 1.41421356; // Um/sqrt(2)
            string str= U_rms + " V";
             component.setLinkedString( 0, str, 0 );
            printed_in_half_period = true;
            print("Um = "+Um+" Urms = " + U_rms);
         }
      }
   }
    //string str= voltage+" V";
    // component.setLinkedString( 0, str, 0 );
    //print("VoltT debug : " + str);
}



Thank you for the explanations!

11RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 2:01 pm

arcachofo

arcachofo

Oh, I see. Yes I didn't even had a chance to dive into subcircuits you provided yet. So much stuff to ask right from the start. That's because I'm new to Simul IDE and not familiar with most of it capabilities.
Yes, it takes some time to get used to these things.
And scripted still has only basic functionality so it's a bit more complicated than it could be.
And this case has an extra complication because is an script inside a subcircuit.

Anyways, here's poor man's RMS voltage script. That will do for now.
Great! I will try it.

12RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 2:05 pm

arcachofo

arcachofo

Hey wait...
There is still one thing:
What if refPin is changing voltage instead of inPin?

13RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 2:31 pm

ru5t



I've just started to learn this whole circuits stuff, that's why some things are not obvious to me. And I can be wrong for sure.
In this case I've tried to simulate multimeter plugged into AC circuit. It shows positive voltage RMS value only. So if inputs are reversed - that doesn't change much - just what half period we get first - positive or negative. Or am I missing something?

RMS voltage Image14[/url]

Inputs are reversed as you can see.

14RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 2:55 pm

arcachofo

arcachofo

Or am I missing something?
Try this:

RMS voltage Kk40

And I think you should clear the display at reset() better than setup(), if you stop/start the simulation the screen is not updated.

There are some other issues, for example if the wave stops, the last value remains in the display.

Evil is in the details...

15RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 4:57 pm

ru5t



I see..
Checked Voltmeter 1 subcircuit - it has a 10 MOhm resistor inside. And since I've already updated voltT component - Voltmeter1 shows RMS value. That's great)

But I don't get why is it that when voltT is connected in forward way - the voltage difference occurs, voltChanged is triggered, measures performed. When voltT is connected in reverse way - voltChanged is triggered once on the simulation start so no V max collected, no calculations.

I mean: if voltT is ideal component with no resistance and no circuit between inPin and refPin - then there should be no measures when it is attached in forward mode. But it measures.


16RMS voltage Empty Re: RMS voltage Thu Nov 30, 2023 10:42 pm

arcachofo

arcachofo

But I don't get why is it that when voltT is connected in forward way - the voltage difference occurs, voltChanged is triggered, measures performed. When voltT is connected in reverse way - voltChanged is triggered once on the simulation start so no V max collected, no calculations.
voltChanged is triggered by changes in inPin but noy by changes in refPin.

I mean: if voltT is ideal component with no resistance and no circuit between inPin and refPin - then there should be no measures when it is attached in forward mode. But it measures.
Why should be no measures?

17RMS voltage Empty Re: RMS voltage Fri Dec 01, 2023 12:32 am

arcachofo

arcachofo

You did the "poor man's RMS voltage script", here is the "lazy man's RMS voltage script".

Mostly to show how to solve some issues, for example:
- Display value does not refresh if wave stops.
- Not working with DC.
- String can overflow the screen.

It uses the function updateStep() to check if the voltage is actually changing and updates the screen.
The value is only printed in updateStep() at 20 FPS which is much more efficient.
It also shows some string manipulation.

This is still not a true RMS voltmeter, it is only correct with DC and sinusoidal symmetric AC, everything else gives wrong values.
A true RMS voltmeter would be more complicated.

Code:
IoPin@ pPin = component.getPin("In");
IoPin@ nPin = component.getPin("Ref");

double lastV;
double lastD;
double maxV;

void setup() // Executed when Component is created
{
    print("Linked  setup() OK");
}

void reset() // Executed at Simulation start
{
    lastV = 0;
    lastD = 0;
    maxV  = -1e12;
    
    pPin.setPinMode( 1 ); // input
    nPin.setPinMode( 1 ); // input
    
    pPin.changeCallBack( element, true );
    
    component.setLinkedString( 0, "0 V", 0 );
}

void updateStep() // Called at circuit refresh rate (default 20 FPS)
{
    string str="";
    
    if( maxV != -1e12 ){
        str= maxV*0.7071;
        maxV = -1e12;
    }
    else str = pPin.getVoltage()-nPin.getVoltage();
    
    uint strLen = str.length();
    if     ( strLen > 5 ) str = str.substr( 0, 5 );
    else if( strLen < 5 ) while( str.length() < 5 ) str = " "+str;
    
    component.setLinkedString( 0, str+ " V", 0 );
}

void voltChanged() // Called at pin voltage change: pPin.changeCallBack()
{
    double voltage = pPin.getVoltage()-nPin.getVoltage();
    double deltaV  = voltage - lastV;

    if( lastD > 0 && deltaV < 0 ) maxV = lastV; // maximum

    lastD = deltaV;
    lastV = voltage;
}

18RMS voltage Empty Re: RMS voltage Fri Dec 01, 2023 6:38 pm

ru5t



Thank you so much for your guidance. That's a very helpful sample.

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum