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 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
| Application | Recommended Block | Why? |
|---|
| LED Control | Digital_Output | Simple on/off control |
| Button Reading | Digital_Input | Poll button state |
| Button Interrupt | ChangeNotification | Efficient event detection |
| Relay Control | Digital_Output | Set initial state, control via Write |
| Chip Select (SPI) | Digital_Output + Write | Manual CS control |
| State Machine | Digital_Output_Read + Write | Read current state before change |
| Fault Indicators | Digital_Output_Write | Dynamic LED control |
| Limit Switches | Digital_Input or ChangeNotification | Polling or interrupt-based |
🟢 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
| Mode | Description | Use Cases |
|---|
| Push-Pull | Actively drives high and low | LEDs, relays, standard logic |
| Open-Drain | Actively drives low, pull-up for high | I2C 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:
- Highest Priority: Analog functions (ADC, comparator)
- Medium Priority: Digital peripherals (UART, SPI, PWM)
- 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
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 Block | dsPIC30F | dsPIC33F | dsPIC33E | dsPIC33C | dsPIC33A | PIC24 | PIC32 | SAM |
|---|
| 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
The Digital Input block reads the state of digital input pins from any available GPIO port on Microchip microcontrollers. The block supports …
Read more →The Digital Output block is a high-level composite subsystem block that provides digital output functionality with optional read-back capability. …
Read more →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 →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 →