There is nothing left to be invented in embedded control, Part 3 -

There is nothing left to be invented in embedded control, Part 3

“There is nothing new to be discovered in physics. All that is left is more and more refined measurements.” – Lord Kelvin, address to the British Association for the Advancement of Science – 1900 (disputed)

I am obviously paraphrasing this famous (although disputed) quote from Lord Kelvin, who was addressing the British Association for the Advancement of Science in the year 1900. One hundred and fourteen years later, it might seem like this quote could be applied to the world of embedded control. But this would be just sad, and, thankfully, it is far from the truth. There is plenty of innovation happening in embedded control, and it is occurring right now, in front of our eyes — in the 8-bit world!

In part 1 and part 2 this short article series, we have seen how 8-bit microcontroller cores are so small that relatively large CMOS process geometries can be effectively used to operate at higher voltages, drive higher current loads (up to 100 mA on selected MCUs) and to provide large margins of noise immunity, hence robustness. We have also seen how a new breed of integrated MCU peripherals, called Core Independent Peripherals, are bringing fresh new ideas to the market. These peripherals relieve the core from heavy computational tasks and, especially when combined together like LEGO bricks, they allow the designer to assemble new, highly customized building blocks that provide unprecedented flexibility and result in significant cost savings and power reductions.

Mixing In Analog
In the previous two installments, we examined the first batch of core independent peripherals, including the Configurable Logic Cell (CLC), the Signal Measurement Timer (SMT), the Numerically Controlled Oscillator (NCO), the Angular Timer, the Complementary Output Generator (COG), the Zero Cross Detector (ZCD), the CRC Scanner and the Hardware Limit Timer (HLT). While this is not an exhaustive list, at first sight it might seem that all such peripherals are mainly focused on solving “digital” problems. And they do, but, as we will now see, core independent peripherals do participate just as actively in the mixed-signal space.

Each integrated Analog Comparator module produces a digital output that can be inserted into the logic mix of the core independent peripherals, but there is more. As we have seen in the previous installments, each CLC (macro) block has up to four inputs that can further access up to 32 input signals, each, and one logic output. The output can be published externally on an I/O pin, if so configured. It can also produce an interrupt or, simply set an interrupt flag without any interruption necessarily taking place. But, there is a third option. Each CLC output (rising or falling edge) can be used as a trigger for the Analog-to-Digital-Conversion (ADC) peripheral. This way, the combination of Analog Comparators, ADCs and various core independent peripherals allows us to create new, customized mixed-signal solutions, thanks to the connecting power of the CLC.

Intelligent Analog Solutions
What we are advocating here is not the redesign of basic analog building blocks from scratch, but rather the combination of existing peripherals to form new, “intelligent” functional blocks that, according to the best core-independence philosophy, will liberate the MCU core from cycle-consuming tasks. This also reduces the power consumption, the required clock speed and, ultimately, the cost of the application.

As we did before, let’s examine these claims with a practical example that will demonstrate the real potential behind this intuition…

Let’s imagine an embedded-control application where a short input (analog) pulse is received from a source in the form of a sensor (of sorts). Let’s also imagine how the amplitude of such a pulse is of utter importance to us and needs to be measured accurately, in order to determine some vital parameters of our control system. The duration of the pulse might be known to us, but the exact time of its arrival will not. In other words, the pulses will be asynchronous with respect to other application timing references.

Figure 1: Measuring Peak

A Chain Reaction
Asusual, let’s start by reviewing a more traditional approach to theproblem. The first one that comes to mind would include an inputamplification and a filtering stage. This would probably make use of anoperational amplifier and a basic application circuit, followed by ananalog comparator. For maximum flexibility, we might want to have aprogrammable threshold, which allows us to imagine connecting aDigital-to-Analog (DAC) converter with the “other” comparator input.Once the threshold is crossed, discriminating the arrival of the pulsefrom the underlying noise, an output pulse would be sent to the MCU;likely to produce an interrupt. The interrupt service routine could thenstart an ADC conversion, after an appropriate delay meant to center thesampling time right at the peak. Such a delay could be generated by atimer or, depending on its duration, simply by a (blocking) countingloop. The result of the ADC conversion might be available shortlyafterward, leaving us with the choice, once more, whether to enable theADC module interrupt or simply await the result in a, hopefully, short(blocking) loop. See Figure 2 for a depiction of this circuit and thesequence of events we imagined.

As simple as this problem may haveinitially appeared, by now it should be clear that, in thisapplication, as each pulse arrives, the MCU is going to spend a lot ofits cycles either serving the numerous interrupts and/or simply waitingfor results. Obviously, the complexity of the software state machinerequired and the minimum MCU clock speed required are going to bestrongly dependent on the specific details of the problem: namely, theinput pulse’s average frequency and width. The more frequently, onaverage, that the input pulses are expected to arrive, the more theMCU’s time will be wasted (in percentage terms) simply tending to thestate machine. The shorter the pulses are expected to be, the higher theMCU clock speed that will be required and the more likely it is that wewill be forced to select short (blocking) delay loops over interrupts.At this point, we might conclude that the reaction time imposed isactually too short for a low-cost, general-purpose microcontroller.

Figure 2: A Chain Reaction

Thecode in Listing 1 represents the typical structure of aninterrupt-driven state machine that tracks the detection and conversionof the pulses in our example application. Here, for brevity, I haveshown (in pseudo code comments) only parts of the “state handlers.”

/* * Example 3: Traditional Sensor Implementation */#include “mcc.h”	volatile int PulseAmplitude = 0;volatile int Flag_Available = FALSE;#pragma interrupt  void ISR( void){    static int state = S_DEFAULT;    // dispatch / state machine    switch( state)    {     default:     case S_DEFAULT:       // start a fixed delay timer        ...       // disable comparator interrupts        ...       // load and enable timer interrupts (or blocking loop)        ...       state = S_DELAY;       break;     case S_DELAY:      // start ADC conversion      ...      // disable timer interrupt,       ...      // enable ADC interrupt      ...     case S_SAMPLE:// fetch ADC results (handle over-run)...      PulseAmplitude = ADC_GetConversionResult();      // disable ADC interrupt       ...      // enable comparator interrupt      ...      // set Flag to indicate new measurement  available      Flag_Available = TRUE;      state = S_DEFAULT;      break;} // ISRint main( void){    SYSTEM_Initialize();   // Init I/O and peripherals    while( TRUE)    {        // Idle or background tasks        // test if a new pulse measurement has been completed        if ( Flag_Available)         {            printf( “Pulse amplitude: %d”, PulseAmplitude);            // clear flag measurement available            FlagAvailable = FALSE;        }    }}

Listing 1: A traditional interrupt-driven solution (template)

And Now for Something Completely Different
Theintelligent-analog approach, used in conjunction with core independentperipherals, is quite different. First of all, the required analogcomponents—Operational Amplifier, DAC, Analog Comparator and ADC—arealready available on-chip on several low-cost andgeneral-purpose microcontroller families. Further, most if not all ofthe analog connections among such modules are available directly inside the MCU. This, by itself, reduces the cost of the solution, as it allows us to use an MCU in a smaller pin count and package.

Anotherbenefit is that the entire chain of events can now be fully automated.The comparator output can trigger a timer (an HLT can be used here, or aCOG for very short delays) that will, in turn, trigger the ADC (via theCLC trigger option) at exactly the required time.

Figure 3: A Core-Independent Solution

Inthe end, the MCU is now going to receive a single interrupt for eachincoming pulse; and this will only be to fetch the ADC result. Oncemore, the complexity of the software (state machine) has been greatlyreduced, and the value of the minimum MCU clock frequency is now likelyto be orders of magnitude lower. In fact, we have now freed up so muchtime that we might consider putting the microcontroller in idle oranother eXtreme Low Power (XLP) mode while waiting for each ADCinterrupt.

Alternatively, we might consider adding more featuresand automation to the system by connecting additional peripherals, suchas the SMT, to perform averaged pulse-frequency measurementsover given windows of time. Once more, these measurements would beperformed automatically, without requiring any MCU coreintervention—once the proper configuration has been set.

Listing 2presents the solution for our example application, once the analog andcore-independent peripherals have been connected to automate the entirechain of events. Notice how interrupts have been completely removed, andthe simple polling of the ADC conversion-complete flag is sufficient toobtain the last measured pulse amplitude.

/* * Example 4: Analog + CIP chaining Sensor Implementation */#include “mcc.h”int main( void){    SYSTEM_Initialize();   // Init I/O and CIP peripherals    while( TRUE)    {        // Idle or background tasks        // test if a new pulse measurement has been completed        if ( ADC_IsConversionDone())             printf( “Pulse amplitude: %d”, ADC_GetConversionResult());    }}

Listing 2: A Core-Independent Solution

More Examples of Intelligent Analog
Moreexamples of intelligent-analog applications for the core independentperipherals can be found in power supplies—particularly solid statelighting (LED) drivers. Here, traditional design methodology combineswell-known analog solutions (DC/DC converter topologies) with basicmicrocontroller supervisory circuits.

Thanks to the coreindependent peripherals—along with the MCUs’ advanced analog integrationof high-speed comparators, DACs, operational amplifiers and ADCs—aswell as the direct internal analog connectivity offered, new hybridsolutions are now possible. These solutions defy the usual definitionsof digital or analog power supplies, as they merge on-chip analogDC/DC capabilities that were previously delegated to separatefixed-function devices with the flexibility and low cost of small 8-bitmicrocontrollers.

Figure 4: Intelligent Analog in a Core-Independent Synchronous Buck Converter

All Connections Inside and Outside
As a side note, the internal analog connectivity ofthese new families of (core independent peripheral enabled)mixed-signal microcontrollers is perfectly matched with superior digitalI/O connectivity, thanks to the Peripheral Pin Select (PPS)feature. PPS, originally available only on very high pin count devices,is now offered on even the smallest microcontrollers (8/14/20-pinpackages), and provides the unprecedented freedom to assign any desiredpin as the input to one or more of the digital peripherals. At the sametime, it can assign any digital peripheral output function to one ormore of the output pins.

But Wait there is More
Here is a final (for now) batch of core independent peripherals:

Auto Clock Tuning
Whilemost modern microcontrollers include an on-chip oscillator, thisrequires typically some form of calibration. Calibration can beperformed at run time by the MCU, when a reference signal is available(USB application or access to an RTCC). The new Auto Clock Tuning modulemakes this process completely automatic and independent from the MCU’soperation. It is so effective that, for example, a USB-capablemicrocontroller is able to operate at Full Speed (that is 12Mbit/s) offthe internal oscillator, achieving better clock stability than 0.25%over the entire industrial temperature range (from -40˚C to +80˚C).

The High Endurance Flash Block
Thisis a non-volatile memory block that is guaranteed to provide the samenumber of erase/write cycles that a typical data EEPROM (100,000) cando, but it can perform the write operation on an entire block of data atonce! Further, the MCU core is automatically set to idle while waitingfor the write operation to complete, minimizing both power consumptionand the complexity of the logic required to perform it. This is a greatpower-saving feature, when the non-volatile memory is used to store theapplication status, in the case of a brown-out event.

The Hardware Capacitive Voltage Divider
TheHardware Capacitive Voltage Divider (HCVD) is a most effectivemethodology to perform capacitive-touch sensing, as well as level,pressure and vibration sensing. The MCU’s HCVD module automates theentire measurement sequence, relieving the core from the tight timingrequirements and allowing easier integration of the sensing algorithm ina control application.

The Math Accelerator
Thisis a 16-bit, fixed-point arithmetic module designed to perform aPID-loop calculation independently from the MCU core. (The PID is thesingle most common algorithm used in embedded control.) It has beenestimated that the Math Accelerator can achieve an MCU workloadreduction of almost three orders of magnitude.

In Summary
Aswe have seen in this short article series, there is plenty ofinnovation taking place in the 8-bit microcontroller space. The coreindependent peripheral philosophy is at the very heart of thisinnovation, and it is helping to redefine what is possible for low-cost,general-purpose MCU applications. While they don’t receive the samemedia attention as larger, 32-bit architectures, 8-bit MCUs areleveraging their robustness and ease of use, while reducing softwaresize and complexity and integrating more intelligent analog.


  • PIC16F170X – a small pin count, entry-level microcontroller family featuring core independent peripherals, PPS and intelligent analog
  • PIC16F171X – a medium pin count, entry-level microcontroller family featuring core independent peripherals, PPS and intelligent analog
  • PIC16F161X – a small pin count microcontroller family featuring core independent peripherals, including the SMT, CRC SCAN, ZCD, 100 mA output drivers and Angular Timer
  • PIC16F176X – a small pin count microcontroller family featuring core independent peripherals and intelligent analog integration
  • PIC16F178X – a medium pin count microcontroller family featuring core independent peripherals and intelligent analog integration
  • ISBN: 97813129077759 – Di Jasio – This is (not) Rocket Science

Lucio Di Jasio isthe EMEA Business Development Manager for Microchip Technology Inc. Hehas held various technical and marketing roles within the Company’s 8,16 and 32-bit MCU divisions for the past 20 years. As an opinionated andprolific technical author, Lucio has published numerous articles andseveral books on programming for embedded-control applications.Following his passion for flying, he has achieved both FAA and EASAprivate-pilot license certifications. You can read more about Lucio’slatest books and projects on his blog at:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.