Master Block Icon
CRITICAL: The Master block is MANDATORY in every MCHP Blockset model. This is always the FIRST block to add to any new model. Without it, no other MCHP blocks will function. The Master block is the central configuration block for the entire MCHP Blockset. It defines the target microcontroller, clock configuration, peripheral initialization, compiler settings, and code generation options.

When to use:

When to use:

  • Starting ANY new MCHP Blockset model (MANDATORY β€” always first block)
  • Changing target microcontroller or development board
  • Configuring system clock frequency (crystal, PLL, internal RC)
  • Setting device configuration bits (watchdog, code protection, debug pins)

When NOT to use:

  • Understanding that this block is REQUIRED in every model β€” no exceptions
  • Selecting a supported device family (800+ dsPIC/PIC32/SAM chips available)
  • Verifying clock configuration achieves desired MIPS/MHz for application timing

Block Dialog

Master β€” General Tab
Oscillator TabMaster β€” Oscillator Tab
Memory TabMaster β€” Memory Tab
Debug TabMaster β€” Debug Tab
Dual Core TabMaster β€” Dual Core Tab

Ports

Inputs: None (configuration block only)

Outputs: None (configuration block only)

This is the master configuration block that defines target device and system settings. It does not have signal portsβ€”it provides global configuration used by all other MCHP blocks in the model.

Parameters

Target Configuration

ParameterVariableDescriptionValues/Range
TargetPICREFMicrocontroller selection. Dynamic popup filtered by supported families with oscillator support verification.800+ devices (dsPIC, PIC32, SAM)
PackagePACKAGE(SAM only) Package selection for ARM devices (affects pin availability).TQFP, LQFP, QFN, etc.

Clock Configuration

ParameterVariableDescriptionValues/Range
Oscillator SourceOSCILLATOR_SELECTPrimary oscillator source selection. Options dynamically updated based on chip capabilities.β€’ Internal Fast RC (FRC) | β€’ Internal Low Power RC (LPRC) | β€’ Crystal/Ceramic Resonator | β€’ External Clock (EC) | β€’ Device-specific options
Crystal FrequencyQUARTZCrystal/resonator frequency when using external oscillator.0.4 MHz to 40 MHz (device-dependent)
Enable PLLACTIV_PLLEnable Phase-Locked Loop for frequency multiplication.on / off
Target MIPSMIPS_DESIREDTarget instruction cycle frequency (FCY). Automatically calculates PLL settings.Device-specific | Up to 200 MIPS (dsPIC33A) | Up to 300 MHz (SAME70)
Auxiliary ClockACLKCON(dsPIC33C only) Auxiliary clock configuration for PWM and other peripherals.AFPLLO, FRC, FOSC
CPU DividerCPUDIV(SAM Cortex-M0+ only) CPU clock divider selection.1, 2, 4, 8, 16, 32, 64, 128
Voltage RangeVDD_range(SAM Cortex-M0+ only) Operating voltage range (affects flash wait states).1.62-2.7V, 2.7-3.6V, 3.6-5.5V
FRC TuningFRC_TUNE_*Fine-tunes the Fast RC oscillator centre frequency. Visible only when FRC (or FRC-derived PLL) is selected as the oscillator source. Grid and range are chip-dependent (see FRC / BFRC Tuning below).Per-chip grid, or Custom expression
BFRC TuningBFRC_TUNE_Range1P5_Step0P047Fine-tunes the Backup FRC oscillator (dsPIC33A only). Visible only when BFRC is selected as the oscillator source.Β±1.5 % grid in 0.047 % steps, or Custom expression
        Select oscillator source (internal RC or external crystal/clock)
        If using crystal, specify frequency in QUARTZ parameter
        Enable PLL if higher frequencies are required
        Set MIPS_DESIRED to target frequency - PLL multipliers are calculated automatically
        Block display shows achieved MIPS/MHz on the diagram

FRC / BFRC Tuning

Scope β€” dsPIC33F, dsPIC33E, dsPIC33C (CK / CH) and dsPIC33A only. Ignored on chips without an OSCTUN register.

The internal Fast RC oscillator (FRC) and, on dsPIC33A, the Backup FRC (BFRC) can be trimmed at run-time through the OSCTUN register. The Master block exposes this as a popup built from the chip’s datasheet grid, plus a Custom entry that accepts a MATLAB expression evaluated against the base workspace.

GridRangeStepApplies to
Range12_Step0P375Β±12 % (βˆ’12.000 % … +11.625 %)0.375 %dsPIC33F, dsPIC33E (legacy 6-bit OSCTUN, Arch=3, non-CK/CH)
Range1P5_Step0P047Β±1.5 % (βˆ’1.500 % … +1.453 %)0.047 %dsPIC33CK / dsPIC33CH, dsPIC33A (both FRC and BFRC)

Register encoding β€” The Master block converts the selected percentage into a signed 6-bit value written to OSCTUN.TUN (FRC) or OSCTUN.BTUN (BFRC, dsPIC33A only):

  • Positive percent: TUN = round(pct / max_pos Γ— 31) β†’ range 0 … +31
  • Negative percent: TUN = βˆ’round(|pct| / max_neg Γ— 32) β†’ range βˆ’32 … βˆ’1

The conversion is handled by MCHP_Master_OscTuneToRegister. max_pos / max_neg per grid: Range12_Step0P375 β†’ (11.625, 12.0); Range1P5_Step0P047 β†’ (1.45, 1.5).

Custom expression β€” Selecting Custom in the popup enables a sibling edit field (*_CUSTOM) that accepts any numeric MATLAB expression (including workspace variables). The expression is evaluated at build time, clamped to the grid range, and quantised to the nearest 6-bit step before being written to the register. Use this to pass calibration data loaded from, for example, a factory-test routine:

load('factory_calibration.mat', 'frcTrimPct');   % e.g. +0.235
set_param([mdl '/Master'], 'FRC_TUNE_Range1P5_Step0P047', 'Custom');
set_param([mdl '/Master'], 'FRC_TUNE_Range1P5_Step0P047_CUSTOM', 'frcTrimPct');

When to use β€” Temperature compensation of FRC-driven clocks, factory trim-to-target, characterising an unknown FRC drift before moving to a crystal, or deriving a calibrated baud-rate from an uncharacterised device.

Limitations β€” FRC / BFRC tuning does not compensate for long-term drift; for applications that require < 1 % frequency accuracy, use an external crystal or ceramic resonator via the Crystal/Ceramic Resonator oscillator source.

Fuse Configuration (Device Configuration Bits)

The Master block exposes device-specific configuration fuses extracted from Microchip XML specifications. Available fuses depend on the selected chip.

Common Fuse CategoriesExamplesDescription
Watchdog TimerFWDTEN, FWDTPSWatchdog enable and prescaler settings
Code ProtectionFCPS, FBORRead/write protection, boot segment protection
DebuggingFICD, FJTAGICD/JTAG enable, pin selection
Power ManagementFBOR, FPORBrown-out reset, power-on reset settings
Peripheral ConfigFIOEN, FBSPeripheral pin select, boot segment

Dual-Core Configuration (dsPIC33CH only)

ParameterDescriptionNotes
Master/Slave SelectionFor dsPIC33CH dual-core devices, select chip name ending with “S1” for slave core configuration.β€’ Master: 33CH128MP508
SECONDARYIMAGEAutomatically set to slave image name when slave device is selected.Used by build system to link secondary core code

Build Configuration

ParameterDescriptionSet By
Compiler PathAutomatically detected compiler installation paths.Auto-configured from system
Header PathsInclude directories for device headers.Auto-configured from DFP
Linker ScriptMemory map linker script selection.Auto-selected or custom
Library PathsStandard library paths (math, DSP, etc.).Auto-configured

External Mode Configuration

ParameterDescriptionValues
UART SelectionUART peripheral for external mode communication.UART1-4 (device-dependent)
Baud RateCommunication speed for real-time monitoring.9600 to 921600 bps
Buffer SizeCommunication buffer allocation.256 to 4096 bytes

Busy Flag (Debug Output)

ParameterDescriptionUsage
BUSYFLAGAssign a GPIO pin to toggle during task execution for timing analysis.β€’ Not used

16-bit DSC/MCU Families

FamilyExamplesFeaturesApplications
dsPIC30F30F1010, 30F2020, 30F6015Legacy DSC, basic DSP engineMotor control, power supplies
dsPIC33F33FJ128MC802, 33FJ256GP710AEnhanced DSP, DMA, advanced PWMDigital power, motor control
dsPIC33E33EP512MU810, 33EP256MC710PPS, DMA, high-speed ADCMotor control, instrumentation
dsPIC33C33CK64MC105, 33CH128MP508Dual-core options, high-speed PWMMotor control, power conversion
dsPIC33A(Latest)33AK128MC106, 33AK512MPS512Advanced PWM with FEP, 12-bit ADC
PIC24F/H24F16KL402, 24FJ256GB110General-purpose MCU, low powerPortable, battery-powered apps

32-bit MCU Families

FamilyExamplesFeaturesApplications
PIC32MK32MK0512MCF064, 32MK1024GPE100MIPS M5150, FPU, motor controlAdvanced motor control
PIC32MZ32MZ2048EFM144, 32MZ1024ECH144High-performance MIPS, cryptoIoT, connectivity, graphics
PIC32MX32MX795F512L, 32MX440F256HUSB, Ethernet, graphicsHMI, connectivity
PIC32A(New)32AK1216GC41036Next-gen 32-bit architecture

ARM-based Families (SAM)

FamilyCoreExamplesFeatures
SAME70Cortex-M7SAME70Q21B, SAME70N21B300 MHz, FPU, DSP, Ethernet
SAMS70Cortex-M7SAMS70Q21BHigh-speed processing, security
SAMV71Cortex-M7SAMV71Q21BAutomotive, CAN-FD, safety
SAME5xCortex-M4FSAME54P20A120 MHz, crypto, low power
SAMC2xCortex-M0+SAMC21N18AMotor control, cost-optimized
SAMD2xCortex-M0+SAMD21G18AUltra-low power, IoT
PIC32CZCortex-M7PIC32CZ_MC70High-performance, security

Generated Model Workspace Variables

The Master block creates essential variables in the model workspace (accessible to all blocks):

VariableDescriptionExample
MCHP.id.nameSelected chip reference‘33AK128MC106’
MCHP.id.ArchArchitecture ID8 (dsPIC33A), 5 (SAM M7)
MCHP.fcy.FCYInstruction cycle frequency (Hz)100e6 (100 MIPS)
MCHP.fcy.FOSCOscillator frequency (Hz)200e6 (200 MHz)
MCHP.NTIMERSNumber of available timers1-12 (device-dependent)
MCHP.modsrc.*Peripheral availability flagsDOS module indicators
MCHP.RxPin remapping (PPS) data structureAvailable remappable pins

Code Generation Settings

The Master block automatically configures critical code generation parameters:

  • Target Selection: Sets RTWSystemTargetFile to appropriate .tlc file
  • Compiler Detection: Automatically finds and configures XC16/XC32/XC-DSC compiler paths
  • DFP Integration: Loads Device Family Pack for accurate peripheral definitions
  • PPS Configuration: Enables Peripheral Pin Select for remappable devices
  • Code Replacement: Optionally enables optimized DSP assembly libraries

Common Workflows

New Model Setup

  • Create new Simulink model
  • Open MCHP Blockset library
  • Drag Master block to model (FIRST block)
  • Double-click Master block to open configuration dialog
  • Select target microcontroller from PICREF dropdown
  • Configure clock settings for desired frequency
  • Set any required fuse configuration bits
  • Click OK/Apply - block display shows chip name and achieved MIPS
  • Add other MCHP peripheral blocks as needed

Changing Target Device

  • Open Master block
  • Select new device from PICREF dropdown
  • Click Apply - GUI closes automatically due to parameter structure change
  • Re-open Master block - new fuses and clock options now visible
  • Reconfigure clock and fuses for new device
  • Review all peripheral blocks for compatibility warnings

External Mode Setup

  • Configure UART in Master block for external mode

  • Set baud rate (typically 115200 or higher)

  • In Simulink Configuration Parameters:

  • Code Generation β†’ Interface β†’ External mode

  • Set transport to “tcpip” or “serial”

  • Build and download code to target

  • Connect via Simulink External Mode toolbar

  • Monitor/tune parameters in real-time

Device Support

The Master block supports 800+ Microchip microcontrollers across multiple families:

Examples

Programmatic Setup

% Add block to model
add_block('MCHP_Blockset/System Configuration/Microchip Master', [mdl '/Master']);

% Configure key parameters
set_param([mdl '/Master'], 'PICREF', '33CK64MC105');
set_param([mdl '/Master'], 'OSCILLATOR_SELECT', 'Internal Fast RC (FRC)');
set_param([mdl '/Master'], 'ACTIV_PLL', 'on');
set_param([mdl '/Master'], 'MIPS_DESIRED', '100e6');

Example 1: Basic dsPIC33A Configuration

% Select dsPIC33AK128MC106
% Configure for motor control application

PICREF: 33AK128MC106
OSCILLATOR_SELECT: Crystal / Ceramic resonator
QUARTZ: 8e6              % 8 MHz crystal
ACTIV_PLL: on            % Enable PLL
MIPS_DESIRED: 100e6      % 100 MIPS target

% Result: FCY = 100 MHz, FOSC = 200 MHz
% PLL automatically configured: M=50, N1=2, N2=2

Example 2: SAME70 ARM Cortex-M7 Setup

% Select SAME70Q21B with LQFP package
% High-performance application

PICREF: SAME70Q21B - LQFP144
OSCILLATOR_SELECT: Crystal Oscillator
QUARTZ: 12e6             % 12 MHz crystal
ACTIV_PLL: on            % Enable PLL
MIPS_DESIRED: 300e6      % 300 MHz ARM core

% Result: MCLK = 300 MHz

Example 3: dsPIC33CH Dual-Core Master

% Master core configuration
% Slave core built separately

PICREF: 33CH128MP508     % Master core
OSCILLATOR_SELECT: Internal Fast RC (FRC)
ACTIV_PLL: on
MIPS_DESIRED: 90e6       % 90 MIPS master

% Slave project uses: 33CH128MP508S1

Example 4: Low-Power SAMD21 Configuration

% Ultra-low power IoT application

PICREF: SAMD21G18A
OSCILLATOR_SELECT: Internal 48MHz Oscillator
ACTIV_PLL: off
CPUDIV: 1                % No division
VDD_range: 2.7V to 3.6V  % Standard voltage

% Result: 48 MHz operation

Troubleshooting

Common Issues

ProblemCauseSolution
Block GUI closes on ApplyNormal behavior when changing devices (fuse structure changes)Re-open block to see updated configuration
Compiler not foundXC16/XC32 not installed or not in PATHInstall compiler from Microchip website, run picSetup
Desired MIPS not achievablePLL limitations or oscillator rangeCheck datasheet for valid PLL settings, try different crystal
Fuses not visibleDevice XML not found or old blockset versionEnsure DFP installed, update blockset
Code generation failsMissing DFP or linker scriptCheck compiler optimization block, verify DFP installation
        The Master block MUST be present before adding any other MCHP blocks
        Changing the target device may invalidate peripheral block configurations
        Always verify achieved MIPS matches application requirements
        Dual-core devices require separate projects for master and slave cores
        External mode requires dedicated UART - cannot be shared with application

References