You need to log in to create posts and topics.

How does the simualtor works internally?

Hello,

i was wondering how the simulator works internally.

As far as I can tell, there is the timerEvent method which runs every 50ms?

The circuit gets calculated “inside” the timer with an extra thread?, so I assume that electronic components like a

resistor are updated every 50ms like the timer?

What about the microcontrollers? They seem to be called inside the timerEvent too with

runEvent from e_mcu.cpp. How does this work with the clock speed of the MCU for example 16MHz for the ATmega328p?
 
Is it also possible to run the simulator at speeds above the 100% real time? Like 300% real time for example?
 
I really would like to understand this because it's really interesting to me.
 
Best regards

Hi.

As far as I can tell, there is the timerEvent method which runs every 50ms?

The circuit gets calculated “inside” the timer with an extra thread?, so I assume that electronic components like a

resistor are updated every 50ms like the timer?

There are certain tasks that are executed in the timerEvent and then a concurrent thread is launched to do all the circuit calculations.

 

What about the microcontrollers? They seem to be called inside the timerEvent too with
runEvent from e_mcu.cpp. How does this work with the clock speed of the MCU for example 16MHz for the ATmega328p?

This is done in a concurrent thread (runEvent), so not in the timerEvent.
MCUs or any other component work based in events.

 

Is it also possible to run the simulator at speeds above the 100% real time? Like 300% real time for example?

Currently it is not possible in SimulIDE, but it could be done (if the computer can keep with it).

 

Hi, thanks for the answer. One thing I'm still not really sure about is the "speed" of the simulator.

Do the AVRs run at their native clock frequency, e.g. 16MHz, while the electronic circuits run at 20Hz?

Do the AVRs run at their native clock frequency, e.g. 16MHz, while the electronic circuits run at 20Hz?

The simulation engine does not run at any specific frequency, it is event driven, not clock driven.

What runs at 20 Hz is the "repaint" and other updates related to the the circuit canvas .