Overview

Digital I/O blocks provide direct control of microcontroller GPIO (General Purpose Input/Output) pins for interfacing with LEDs, buttons, relays, logic signals, and external digital peripherals. The MPLAB Blockset offers intuitive blocks for reading inputs, writing outputs, and detecting pin state changes across all Microchip device families.

Available Digital I/O Blocks

Digital Input - Read GPIO Pin State


Digital Output - Write GPIO Pin State


Digital Output Write - Update GPIO State


Digital Output Read - Read GPIO Output State


ChangeNotification - GPIO Interrupt on Change


Block Selection Guide

By Application

ApplicationRecommended BlockWhy?
LED ControlDigital_OutputSimple on/off control
Button ReadingDigital_InputPoll button state
Button InterruptChangeNotificationEfficient event detection
Relay ControlDigital_OutputSet initial state, control via Write
Chip Select (SPI)Digital_Output + WriteManual CS control
State MachineDigital_Output_Read + WriteRead current state before change
Fault IndicatorsDigital_Output_WriteDynamic LED control
Limit SwitchesDigital_Input or ChangeNotificationPolling or interrupt-based

By Performance Requirements

🟢 Polling Mode (Simple, predictable timing)

  • Digital_Input - Read pin state at fixed sample rate
  • Digital_Output_Read - Check output state periodically

🟡 Dynamic Control (Variable timing, algorithm-driven)

  • Digital_Output_Write - Update pins based on control logic
  • Digital_Output - Set initial state

🔴 Interrupt Mode (Lowest latency, event-driven)

  • ChangeNotification - React immediately to pin changes

Pin Configuration Best Practices

Pull-Up/Pull-Down Resistors

When to use internal pull-ups:

  • ✅ Button inputs (active-low with pull-up)
  • ✅ I2C bus (SDA/SCL) - if no external pull-ups
  • ✅ Open-drain outputs
  • ❌ High-speed signals (use external resistors)

Typical resistor values:

  • Internal: 10kΩ - 50kΩ (chip-dependent)
  • External buttons: 4.7kΩ - 10kΩ
  • I2C bus: 2.2kΩ - 10kΩ (depends on bus capacitance)

Open-Drain vs Push-Pull

ModeDescriptionUse Cases
Push-PullActively drives high and lowLEDs, relays, standard logic
Open-DrainActively drives low, pull-up for highI2C bus, wired-AND logic, level shifting

GPIO Speed and Drive Strength

dsPIC/PIC24:

  • Standard output drive: ~15 mA typical
  • Check datasheet for pin-specific limits

PIC32:

  • Configurable drive strength (low/medium/high)
  • Up to 18 mA per pin (device-dependent)

SAM ARM:

  • Multiple drive strength settings
  • Up to 12 mA per pin (varies by family)

⚠️ Important:

  • Never exceed absolute maximum ratings
  • Use external drivers for high-current loads (>10 mA)
  • Check Voh/Vol specifications for logic level compatibility

Device Family Considerations

Peripheral Pin Select (PPS)

Devices with PPS:

  • dsPIC33F/E (selected devices)
  • dsPIC33C/A (all devices)
  • PIC24 (selected devices)

Key Points:

  • Peripheral functions (UART, SPI, etc.) can be mapped to multiple pins
  • GPIO blocks automatically configure PPS if needed
  • Check datasheet for remappable vs. fixed pins

Pin Multiplexing Priority

Most microcontrollers have pin multiplexing with priority:

  1. Highest Priority: Analog functions (ADC, comparator)
  2. Medium Priority: Digital peripherals (UART, SPI, PWM)
  3. Lowest Priority: GPIO

⚠️ Conflict Warning:

  • If a pin is configured as analog, it cannot be used as GPIO
  • If a peripheral is enabled on a pin, GPIO control is blocked
  • Use Port Info block to visualize pin assignments

Troubleshooting Common Issues

Digital Input

Problem: Input always reads 0 or 1

  • Check: Pin not configured as analog (ADC/comparator)
  • Check: Peripheral not using the pin
  • Check: External circuit properly connected
  • Check: Pull-up/pull-down enabled if floating input

Problem: Noisy readings

  • Check: Add external filter capacitor (100 nF typical)
  • Check: Enable internal pull-up/pull-down
  • Check: Reduce sample rate for slower signals

Digital Output

Problem: Pin does not change state

  • Check: Pin not configured as input
  • Check: Peripheral not overriding GPIO control
  • Check: External load not too high (>10 mA)
  • Check: Power supply sufficient

Problem: Dim LED or weak output

  • Check: Current-limiting resistor value (typically 330Ω - 1kΩ for LED)
  • Check: GPIO drive strength sufficient
  • Check: Use external buffer for high-current loads

Change Notification

Problem: Interrupt never fires

  • Check: Change Notification enabled for correct pin
  • Check: Edge trigger configured correctly (rising/falling/both)
  • Check: Global interrupts enabled
  • Check: Pin actually changing state (verify with input block)

Problem: Too many interrupts

  • Check: Debounce mechanical switches (hardware or software)
  • Check: Noisy signal (add external filter)
  • Check: Reduce sensitivity (change edge detection mode)

Device Family Support Summary

Digital I/O BlockdsPIC30FdsPIC33FdsPIC33EdsPIC33CdsPIC33APIC24PIC32SAM
Digital_Input
Digital_Output
Digital_Output_Write
Digital_Output_Read
ChangeNotification⚠️

Legend: ✅ Full Support | ⚠️ Selected Devices | ❌ Not Available

Note: Core GPIO blocks (Input, Output, Write, Read) are available on all devices. ChangeNotification uses device-specific CN peripheral.


See Also

Related Block Categories:

Recommended Reading:

  • Use Change Notification for efficient button detection
  • Use Digital_Input for polled status monitoring
  • For high-frequency signals: Use dedicated peripherals (Input Capture, QEI)

Example Projects:


💡 Quick Selection Guide:

  • Need to read a button? → Digital_Input (polling) or ChangeNotification (interrupt)
  • Need to control an LED? → Digital_Output + Digital_Output_Write
  • Need SPI chip select? → Digital_Output (initial high) + Digital_Output_Write
  • Need state machine GPIO? → Digital_Output_Read + Digital_Output_Write
  • Need interrupt on pin change? → ChangeNotification

Digital Input

The Digital Input block reads the state of digital input pins from any available GPIO port on Microchip microcontrollers. The block supports …

Read more →

Digital Output

The Digital Output block is a high-level composite subsystem block that provides digital output functionality with optional read-back capability. …

Read more →

Digital Output Read

The Digital Output Read block reads the current state of output pins by accessing the LAT (latch) register. This block provides feedback on the …

Read more →

Digital Output Write

The Digital Output Write block is the core digital output writing block that directly controls GPIO pins via LAT register writes. This block …

Read more →