The Digital Output Write block is the core digital output driver that directly controls GPIO pins via LAT register writes. Selected pins are configured as digital outputs with user-selectable push-pull or open-drain modes. When the block input is defined as one uint16, the value is used as-is without masks, which may affect other pins on the same port if they are also configured as digital outputs.
When to use:
When NOT to use:
No screenshot available โ block uses standard parameter dialog similar to Digital Output.
| Port | Data Type | Description |
|---|---|---|
| Port signal | boolean or uint16 | Digital value to write to selected pin(s). If multiple pins are selected without PACK option, each pin requires its own boolean input. If PACK option is enabled, a single uint16 input sets multiple pins via bit positions. |
| Parameter | Variable | Type | Description |
|---|---|---|---|
| Port | PORT | popup | GPIO port selection (A, B, C, etc.). Dynamically populated based on target device pin map. Shows available pin indices for each port. |
| Pins | PIN | edit | Array of pin indices to control, e.g., [0] or [0 1 2]. Valid range is [0..15] for 16-bit ports or [0..31] for 32-bit ports. Out-of-range or unavailable pins are automatically filtered out with a warning. Defaults to [0] if left empty. |
| Initial Output | INIT_VALUE | edit | Chip-dependent. Initial pin state at startup. Accepts scalar (applies to all pins), vector (per-pin values), or bitmask (when PACK enabled): โข Scalar -1 or negative: “don’t care” (leaves pin at reset state)โข Scalar 0 or 1: applies to all pinsโข Scalar >1: interpreted as bitmask, bitwise-AND with selected pin maskโข Vector: per-pin values, extended or truncated to match number of pins. Visible on dsPIC30F, dsPIC33F, dsPIC33E, dsPIC33C, dsPIC33A, PIC32, PIC32A (Arch 1,2,3,4,8). Hidden on SAM devices. |
| set input as one uint16/uint32 | PACK | checkbox | When enabled, accepts a single uint16 (16-bit ports) or uint32 (32-bit ports) input where bit positions correspond to pin numbers. Atomic write: When all selected pins are present and TRIS is fully configured, LAT register is written directly without read-modify-write. Otherwise, uses masked update. |
| Request exact simultaneous write | SIMULTANEOUS | checkbox | Conditional. When enabled, all pins are written to LAT register in a single instruction using read-modify-write sequence. Only visible when multiple pins are selected AND PACK is disabled. |
| Output mode | OUTPUT_PIN_MODE | popup | Chip-dependent. Electrical configuration: Push-Pull (default) for standard CMOS output, or Open Drain for open-collector applications. Only visible on dsPIC33E, dsPIC33C, dsPIC33A, PIC32, PIC32A (Arch 3,4,8). Hidden on older dsPIC30F/33F and SAM devices. |
| Block execution ordering | ORDERING | popup | Controls block scheduling: None, Input, Output, or Input & Output. |
| Sample Time | SampleTime | edit | Sampling interval in seconds. Use -1 for inherited sample time. |
Initial Output Parameter Visibility:
Output Mode Parameter Visibility:
Generated Code Optimization (PACK mode):
(PinsBitmask | TRIS) == 0xFFFF, generates direct LAT assignment: LAT%<PORT> = input;LAT%<PORT> ^= (mask & (LAT%<PORT> ^ input));MCHP_Digital_Output.tlc lines 62-71INIT_VALUE Processing:
-1 or any negative value: No initialization code generated (MCHP_PORT does not include INIT0 or INIT1)0 or 1: Applied to all pins (MCHP_PORT includes ,INIT0 or ,INIT1 for each pin)>1: Bitwise-AND with selected pin mask, then each pin gets individual INIT bit% Add block to model
add_block('MCHP_Blockset/Digital IO/Digital Output\nWrite', [mdl '/DigitalOut']);
% Configure key parameters
set_param([mdl '/DigitalOut'], 'PORT', 'B');
set_param([mdl '/DigitalOut'], 'PIN', '0');
set_param([mdl '/DigitalOut'], 'INIT_VALUE', '0');
set_param([mdl '/DigitalOut'], 'OUTPUT_PIN_MODE', 'Push-Pull (default)');
Problem: Output doesn’t drive high in Open Drain mode
Problem: Pins toggle unexpectedly when using PACK mode
Problem: Initial Output value not applied at startup
0 or 1. The value -1 means “unchanged” and leaves the pin in its reset state (typically input/high-impedance).