modelIndependent

Two microcontrollers run the same program and import the same module: each keeps its own state

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

Two MCU blocks run the same program, multi_counter.py, which imports the module multi_counter_lib.py (placed next to it) and increments its module-level counter every 100 ms, five times. Each microcontroller runs in its own Python sub-interpreter: its program globals, its imported modules (here the counter), machine, time, sys.path and its file system are its own. Both boards therefore count exactly 5 ticks and light their GP1 LED at the end; with a shared state, the counter would reach 10 and the second board would also see the globals of the first.

With two microcontrollers or more, every line printed by a program is prefixed with the instance name in the simulation log ([mcu1] ...), as the scripted peripherals already do.

Components

TypeNameDefaultDescription
MCUmcu1First board: Resources/Scripts/MCU/multi_counter.py
MCUmcu2Second board: the same program
Modelica.Electrical.Analog.Basic.Groundground
Modelica.Electrical.Analog.Basic.Resistorr10limits the current of led10
MicroPythonMCU.Peripherals.LEDled10mcu1 GP0: blinks with the ticks of mcu1
Modelica.Electrical.Analog.Basic.Resistorr11limits the current of led11
MicroPythonMCU.Peripherals.LEDled11mcu1 GP1: lit at the end if mcu1 counted only its own 5 ticks
Modelica.Electrical.Analog.Basic.Resistorr20limits the current of led20
MicroPythonMCU.Peripherals.LEDled20mcu2 GP0: blinks with the ticks of mcu2
Modelica.Electrical.Analog.Basic.Resistorr21limits the current of led21
MicroPythonMCU.Peripherals.LEDled21mcu2 GP1: lit at the end if mcu2 counted only its own 5 ticks