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. GP6 lights 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. GP7 lights 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

TypeNameDefaultDescription
MCUmcuscriptPath = Scripts/MCU/gpio_pull.py
Modelica.Electrical.Analog.Basic.Groundground
Modelica.Electrical.Analog.Basic.VariableConductorbuttonGndPush button from GP0 to GND (controlled conductance, no ideal switching)
Modelica.Blocks.Math.BooleanToRealcontactGndPressed: 0.1 Ω; released: 1 GΩ
Modelica.Blocks.Sources.BooleanTablepressGndGP0 button pressed from t = 0.1 s to 0.2 s
Modelica.Electrical.Analog.Basic.GroundgroundGnd
Modelica.Electrical.Analog.Basic.VariableConductorbuttonVccPush button from GP3 to 3.3 V
Modelica.Blocks.Math.BooleanToRealcontactVccPressed: 0.1 Ω; released: 1 GΩ
Modelica.Blocks.Sources.BooleanTablepressVccGP3 button pressed from t = 0.4 s to 0.5 s
Modelica.Electrical.Analog.Sources.ConstantVoltagevccButton3.3 V supply of the GP3 button
Modelica.Electrical.Analog.Basic.GroundgroundVcc
Modelica.Electrical.Analog.Basic.ResistorrWeakWeak 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.ConstantVoltagevccWeak
Modelica.Electrical.Analog.Basic.GroundgroundWeak
Modelica.Electrical.Analog.Basic.ResistorledGndLoad standing for an LED: lit while the GP0 button is pressed
Modelica.Electrical.Analog.Basic.ResistorledVccLoad standing for an LED: lit while the GP3 button is pressed
Modelica.Electrical.Analog.Basic.GroundgroundLed