Deploy task-specific microcontrollers to simplify complex designs

Abstract: Microcontrollers that handle specific tasks can help simplify the design flow for various applications by offloading the tasks and workload of the main microcontroller or microprocessor.

Microchip Technology Inc.
8-bit microcontroller product department
Robert Perkel

Today, large 32-bit microcontrollers (MCUs) and microprocessors (MPUs) running a real-time operating system (RTOS) are increasingly common. However, if you are using a large microcontroller for a complex application, you may run into CPU resource issues while performing small background processing tasks that are not complex but time consuming. Small devices such as 8-bit and 16-bit MCUs can be used to offload 32-bit devices.

Consider an example of using a 32-bit MCU to control non-safety functions in a car, such as entertainment systems, ambient lighting, and air conditioning. This 32-bit device must allocate its resources to handle all tasks associated with these functions. Such tasks also include measuring temperature at various points in the cab, turning the air conditioning system on/off, updating graphic displays, processing user input, adjusting lighting conditions, and playing music. Even for large 32-bit devices, these workloads are too heavy.

However, these tasks are more manageable if the 32-bit device offloads part of the task load to sub-processors that require little monitoring, each sub-processor handling only 1 or 2 of these tasks. This frees up CPU resources on the main processor, reducing software complexity while improving performance and reducing execution time.

This solution is similar to the peripheral in the microcontroller. Peripherals are small modules of specialized hardware that can add new functionality (such as an op amp or analog-to-digital converter) or reduce the amount of work the CPU has to do to perform a given function. In some cases, after initialization, peripherals can operate independently of the CPU.

To illustrate the advantages of peripherals, let’s take the example of generating a pulse-width modulated (PWM) signal. To generate PWM without a dedicated peripheral, simply set the I/O line high, wait a certain number of cycles, set it low, wait for a while, and repeat. This consumes a lot of CPU cycles and, for some functions (like RTOS), is difficult to perform reliably. In contrast, the PWM peripheral allows the CPU to set the desired waveform parameters while performing other tasks.

The first example presented in this article illustrates the benefits of offloading CPU-intensive tasks. In this case, an 8-bit MCU was used to create the I/O expander. I/O expanders are not complicated; however, they can consume a lot of CPU time due to the frequent interrupts they need to handle. By using a dedicated MCU for this task, large 32-bit devices can reduce I/O usage and the number of interrupts that need to be handled. In addition, the feature set of the I/O expander can be set in software, thus enabling customization and adjustment to the application.

The second example in this article demonstrates the performance of a core-independent peripheral by creating a voltage-to-frequency (V/F) converter that operates independently of the CPU. In this example, the only function of the CPU is to initialize peripherals and send debug print messages to the UART. In large systems, the CPU can perform another simple task while the V/F is running in the background.

I/O expander

The biggest benefit of creating an I/O expander with an 8-bit MCU is increased flexibility. The feature set of the I/O expander ASIC is embedded into the device, while the MCU defines its behavior based on the software it executes. This flexibility enables MCU-based versions to meet the needs of the end application.

Implementing Advanced I/O Expanders

Inside the device, the advanced I/O expander operates on a look-up table-based structure. Before reading or writing, a virtual address is sent. This address has nothing to do with registers on the microcontroller – only specific to the lookup table. This means that functions that are not in the microcontroller hardware registers can be added transparently. In addition, the entries in the table can be easily rearranged for specific purposes. Another advantage of this structure is the ability to add permissions to the lookup table. For example, to create a read-only register, simply omit the lookup table write entry.

Deploy task-specific microcontrollers to simplify complex designs
Lookup Table for Advanced I/O Expanders

This more complex structure also applies to non-standard functions. The “MEM OP” function allows the MCU to save or load its current General Purpose Input and Output (GPIO) configuration into memory.

memory storage in the device

MEM OP can also reset the GPIO configuration to the parameters set at compile time.

Note: Not all fields are available for all actions

Function of MEM OP

In addition, there is an option to set the microcontroller to load saved settings at power-up. If enabled, the microcontroller will attempt to load the settings in Configuration 0. If the configuration fails to perform checksum verification, the MCU will revert to compile-time constants. This feature can be disabled in software if not required.

The gist of the solution

The advantage of MCU-based solutions lies in their outstanding flexibility. Unlike ASICs on the market, we can configure MCUs with non-standard functions specific to application scenarios. This application is developed for the general purpose PIC16F15244 family of MCUs.

For an in-depth look at the implementation or to try out the sample, see the README file in the source repository. In addition, a demonstration of the Advanced I/O Expander with Arduino is provided.

Source code, documentation and demos:

Voltage to Frequency (V/F) Converter

Voltage-to-frequency converters improve traditional analog solutions by reducing bill of materials (BOM) costs and, in turn, design area. While many V/F converters on the market require external resistors and capacitors to operate, microcontrollers can operate using only common decoupling and pull-up components (a must for all MCUs).

Application Schematic of TC9400/TC9401/TC9402 10 Hz to 100 kHz V/F Converter

MCUs are not digitized using analog techniques, but rather a combination of peripherals and functions that are independent of the core. The MCU measures the input signal using an internal analog-to-digital converter (ADCC) with computation capabilities, and then divides the clock signal to create a variable frequency output. In this example, the peripherals have been set up to operate independently of the CPU after initialization. This means, the CPU can be used for other tasks in the final application.

For MCU-based solutions, the challenge is that the performance is not as good as the analog solution. The resolution of the output itself is limited by the ADCC. On the surface, ADCC is 12-bit, but it will run at 14-bit resolution configured to oversample, depending on how the program is configured. Likewise, the on-chip numerically controlled oscillator (NCO) used to synthesize the output frequency has limited resolution and may have jitter in its output, depending on the value measured by the ADC.

The MCU-based solution can be divided into three different peripheral modules – analog sampling module, output oscillator module and duty cycle generator.

Solution Block Diagram

Analog Sampling Module

Analog sampling module implementation

The analog sampling block is responsible for performing the analog-to-digital conversion. To achieve a 100 kHz output within the frequency limitations of the device, the ADCC has been configured to oversample and then averaged to obtain a 14-bit result.

This oversampling configuration has the disadvantage of adding additional statistical noise to the results, which can be compensated for by averaging the oversampling and adding hysteresis. To achieve hysteresis, ADCC’s threshold interrupt function can be used. (For simplicity, only the details of how this example uses the threshold interrupt feature will be presented.)

After ADCC completes the oversampled average calculation, the resulting value is compared to the setpoint register in the peripheral. If the difference between the two is greater or less than the set threshold, an interrupt is triggered. The CPU can mask this interrupt and be unaffected, however, this interrupt triggers a direct memory access (DMA) that copies the averaged oversampled result to the ADCC’s setpoint register, creating a lag. If the threshold is not exceeded, no DMA copy will occur, thus not triggering a DMA update of the output oscillator block.

Output Oscillator Block

Structure of the Output Oscillator Block

The output oscillator block of this solution is responsible for generating the clock signal at the desired output frequency. This output signal is internally connected to a duty cycle generator, which halves the output frequency but produces a 50% duty cycle output. Therefore, the output oscillator block operates at twice the output frequency.

At the heart of the output oscillator block is the Numerically Controlled Oscillator (NCO). The NCO peripheral works by adding an incremental value to the accumulator on the rising edge of the input clock, and then deriving the peripheral’s output based on accumulator overflow. (See the data sheet for a complete description of the NCO.)

In this example, the NCO2 has been set to internally create the required input clock frequency to get a 100 kHz output from a 14-bit input. The 14-bit result is used because the 12-bit result of the ADCC itself is not enough to produce a 100 kHz output without an external clock source.

ADC results

NCO1 output (doubled)

Output frequency


0 Hz

0 Hz


12.2 Hz

6.1 Hz










Ideal output for 100 kHz V/F converters (watchdog off).

If the output frequency of the NCO2 is changed or an alternate source is used, the output frequency will be adjusted to a different output range. For example, if the frequency of the NCO2 is reduced to 1.28 MHz, the output will be a maximum of 10 kHz.

ADC results

NCO1 output frequency (doubled)

Output frequency


0 Hz

0 Hz


1.2 Hz

0.6 Hz



156.3 Hz







Ideal output for 10 kHz V/F converters (watchdog off).

Duty Cycle Generator

Duty Cycle Generator Block Diagram

The duty cycle generator module of this solution is responsible for creating the 50% duty cycle output. This is an optional feature – the output of the NCO can be used directly, but doing so will increase the magnitude of the duty cycle change.

The generator is implemented using a Configurable Logic Cell (CLC). A CLC is a small module of configurable logic, similar to a cell of a Field Programmable Gate Array (FPGA). CLCs can be used as discrete logic gates (such as AND-OR or OR-XOR) and can also be configured as latches or flip-flops. In this solution, the CLC is implemented as a JK flip-flop with reset. J and K remain at logic high. The output oscillator block is used as a clock for flip-flops. Each input clock pulse causes the output to toggle, resulting in a 50% duty cycle. Note: Frequency jitter of the output oscillator block will have an effect on the duty cycle.

Timer 6 acts as an unstable “watchdog” timer. If the output does not generate an edge (rising or falling), the timer will overflow and send the generated clock pulse to the CLC, which controls the lower limit of the output frequency range. The output flips to half the timer frequency (the output is 6 Hz) instead of going to DC.

The gist of the solution

This example shows that to use hardware peripherals to create core-independent functions, an external integrated circuit is often necessary. One of the biggest advantages of this configuration is that peripheral operation can be set in software, making it easy to adapt the example to the end application. Due to the large number of peripherals used, the PIC18-Q43 family of MCUs was chosen to implement this example.

For more information about the example, see the README documentation in the example repository. In addition, the example repository contains an implementation of the frequency-to-voltage converter, which can be implemented on the same device as the voltage-to-frequency converter.

Click this link for source code and documentation:


While both high-performance microcontrollers and microprocessors have their place, the role of 8-bit and 16-bit MCUs cannot be underestimated when it comes to performing small specialized tasks. Such tasks are not necessarily very complex, but can be time-consuming or time-critical. With less task load, 32-bit devices can have simpler implementations, resulting in improved reliability, reduced memory usage, and lower power consumption.

The Links:   FZ2400R12KL4C BSM35GB120DLC MIG200J6CMB1W