modelPull
Internal pull resistors: two push buttons without any external resistor (Pin.PULL_UP, Pin.PULL_DOWN), and a pin whose pull is switched against a weak external resistor
Extends from Modelica.Icons.Example (Icon for runnable examples).
Information
The internal pull resistors of the microcontroller (mcu.RPullUp, mcu.RPullDown, 50 kΩ), switched on by Pin(n, mode, pull). Program: Scripts/MCU/gpio_pull.py.
GP0: push button to GND, no external resistor,Pin.PULL_UP. Released, the pull-up holds the pin at 3.3 V; pressed from t = 0.1 s to 0.2 s, it falls to 0 V.GP6lights up meanwhile.GP3: push button to 3.3 V,Pin.PULL_DOWN: 0 V released, 3.3 V pressed from t = 0.4 s to 0.5 s.GP7lights up meanwhile.GP4: only a weak 1 MΩ resistor to 3.3 V. Without pull (0-0.3 s), the input is a real high impedance and the 1 MΩ alone brings it to 3.3 V; with the internal pull-down (0.3-0.6 s), the divider gives 0.16 V; with the pull-up (from 0.6 s), 3.3 V again.
Plot mcu.GP0.v, mcu.GP3.v, mcu.GP4.v, mcu.GP6.v and mcu.GP7.v. The simulation log shows what the program reads on GP4 in each phase.
Components
| Type | Name | Default | Description |
|---|---|---|---|
| MCU | mcu | scriptPath = Scripts/MCU/gpio_pull.py | |
| Modelica.Electrical.Analog.Basic.Ground | ground | ||
| Modelica.Electrical.Analog.Basic.VariableConductor | buttonGnd | Push button from GP0 to GND (controlled conductance, no ideal switching) | |
| Modelica.Blocks.Math.BooleanToReal | contactGnd | Pressed: 0.1 Ω; released: 1 GΩ | |
| Modelica.Blocks.Sources.BooleanTable | pressGnd | GP0 button pressed from t = 0.1 s to 0.2 s | |
| Modelica.Electrical.Analog.Basic.Ground | groundGnd | ||
| Modelica.Electrical.Analog.Basic.VariableConductor | buttonVcc | Push button from GP3 to 3.3 V | |
| Modelica.Blocks.Math.BooleanToReal | contactVcc | Pressed: 0.1 Ω; released: 1 GΩ | |
| Modelica.Blocks.Sources.BooleanTable | pressVcc | GP3 button pressed from t = 0.4 s to 0.5 s | |
| Modelica.Electrical.Analog.Sources.ConstantVoltage | vccButton | 3.3 V supply of the GP3 button | |
| Modelica.Electrical.Analog.Basic.Ground | groundVcc | ||
| Modelica.Electrical.Analog.Basic.Resistor | rWeak | Weak resistor (1 MΩ) from GP4 to 3.3 V: wins when the pin has no pull, loses against the internal pull-down | |
| Modelica.Electrical.Analog.Sources.ConstantVoltage | vccWeak | ||
| Modelica.Electrical.Analog.Basic.Ground | groundWeak | ||
| Modelica.Electrical.Analog.Basic.Resistor | ledGnd | Load standing for an LED: lit while the GP0 button is pressed | |
| Modelica.Electrical.Analog.Basic.Resistor | ledVcc | Load standing for an LED: lit while the GP3 button is pressed | |
| Modelica.Electrical.Analog.Basic.Ground | groundLed |