By Jon D. Pearson, Cypress Semiconductor
Abstracting Your Microcontroller
Our example purposely changed the hardware outside of the
microcontroller to make a more universal point, but the same process
applies if the microcontroller hardware changes.
If we started with the thermistor design of Figure 2 and changed our
microcontroller, the commands to configure and access the ADC would
change, the register sequence to multiplex and sample the inputs would
change and perhaps the counts-to-temperature conversion would change.
But since these were all tucked neatly into rectangles (representing
functions and/or macro definitions and calls) simply replace the
contents of the rectangles with the new instructions required by the
new microcontroller, and, voila! hardware changed, but software is
unchanged.
While I haven't yet come across an embedded design tool that make
these changes for you when switching between one microcontroller vendor
and another, many vendors do provide wizards to set-up the hardware
initially, which does make the process of changing hardware, choosing a
new device offered by the same vendor, relatively straightforward.
When it comes to making it easier to design-out hardware,
microcontroller companies are striving to simplify the process a few
steps further by employing hardware abstraction within their software
development tools. The peripheral functions of microcontrollers are
selected by users from a catalog of choices, depending upon what the
application requires, and can be added or removed from the design as
the needs change.
By employing generic instance names, like PWM1 or ADC, the user can
change his/her mind about the actual hardware function details and let
the tool manage the first layer or wrapper of abstraction. For instance
in Figure 2, if an incremental (integrating) ADC is desired rather than
the SAR (successive approximating) ADC, the tools would automatically
make the changes to the middle light blue rectangle.
Abstraction can even be carried to a higher level. For example, with
the PSoC Designer and PSoC Express visual embedded design tools for the
PSoC Mixed-Signal Array devices, the software by default employs a
hardware abstraction method and generates all the layers automatically (Blue
elements in Figure 2
and Figure 3 earlier).
In order to modify the thermistor, the user selects "Thermistor"
from a catalog in PSoC Express, defines the "Compute Desired Speed"
control algorithm, and the development tool presents which PSoC devices
are available with the necessary resources for the application.
Upon selecting a device, the tools generate the necessary firmware
to read, convert and store the thermistor temperature in fixed-point
format into a data structure and make it available to the "Compute
Desired Speed" algorithm.
If the specifications of the thermistor change, the user can select
a different PSoC device, adjusting for memory, pin-count, cost, etc.
Only those device with the necessary resources for the application will
be displayed and the hardware abstraction layers will be regenerated
without impacting the control algorithm.
One day, all projects will have reasonable schedules, marketing will
decide in advance exactly what customers want, write it down and not
change its mind, and application software with all desired features
will fit within the memory space of the chosen microcontroller.
But until that day arrives (I'm not holding my breath yet), you can
reach a reasonable facsimile of embedded utopia by designing your
embedded systems to isolate all hardware in neat wrappers and layers,
uncoupled from the control software.
Then look out the window, breathe deep, take a moment to notice an
eagle high in the sky circling for its prey, and then turn your
attention back to marketing's urgently demanded last minute changes to
satisfy (insert name of your favorite disruptive customer here).
Jon Pearson began designing commercial embedded systems in 1986
for commercial aircraft, telecommunications satellite systems and
notebook computers. Jon has been driving marketing efforts at Cypress Semiconductor since 2000
when the first Programmable System-on-Chip mixed-signal array devices
were created. Currently Jon leads the development tools marketing
efforts for PSoC and other programmable devices. You can reach him at jpx@cypress.com.