Professional Documents
Culture Documents
Embedded Systems Design 2011-07-08S370
Embedded Systems Design 2011-07-08S370
Leading Embedded
Development Tools
1-800-348-8051 www.keil.com
The INTEGRITY RTOS ®
www.ghs.com
Copyright © 2011 Green Hills Software, Inc. Green Hills, the Green Hills logo and INTEGRITY are trademarks of Green Hills Software, Inc. in the U.S.and/or
internationally. All other trademarks are the property of their respective owners.
Find It Here. Faster.
™
Scan Here
to Watch Video
Mouser and Mouser Electronics are registered trademarks of Mouser Electronics, Inc.
T H E O F F I C I A L P U B L I C AT I O N O F T H E E M B E D D E D S Y S T E M S C O N F E R E N C E S A N D E M B E D D E D. C O M
COLUMNS
barr code 11
How to enforce coding
standards automatically
BY MICHAEL BARR
Too many well-intentioned coding
standards are ineffective and gather
more dust than followers. Automatic
EMBEDDED SYSTEMS DESIGN enforcement points the way to greater
compliance.
VOLUME 24, NUMBER 6
JULY/AUGUST 2011 break points 33
Assume nothing
BY JACK G. GANSSLE
16
An engineer’s duty is to assume noth-
ing, think of everything, and be hum-
ble. Yes, humble.
DEPARTMENTS
#include 5
Dumbing down embedded design
BY RON WILSON
Like it or not, the abstraction in
embedded systems design is
changing, again.
parity bit 7
History repeats itself
EMBEDDED SYSTEMS DESIGN (ISSN 1558-2493) print; (ISSN 1558-2507 PDF-electronic) is published 10 times a year as follows: Jan/Feb, March, April, May, June,
July/August, Sept., Oct., Nov., Dec. by the EE Times Group, 600 Harrison Street, 5th floor, San Francisco, CA 94107, (415) 947-6000. Please direct advertising and editorial
inquiries to this address. SUBSCRIPTION RATE for the United States is $55 for 10 issues. Canadian/Mexican orders must be accompanied by payment in U.S. funds with addi-
tional postage of $6 per year. All other foreign subscriptions must be prepaid in U.S. funds with additional postage of $15 per year for surface mail and $40 per year for
airmail. POSTMASTER: Send all changes to EMBEDDED SYSTEMS DESIGN, EE Times/ESD, PO Box #3609, Northbrook, IL 60065-3257, embedsys@omeda.com. For cus-
tomer service, telephone toll-free (847) 559-7597. Please allow four to six weeks for change of address to take effect. Periodicals postage paid at San Francisco, CA and additional
mailing offices. EMBEDDED SYSTEMS DESIGN is a registered trademark owned by the parent company, EE Times Group. All material published in EMBEDDED SYSTEMS
DESIGN is copyright © 2010 by EE Times Group. All rights reserved. Reproduction of material appearing in EMBEDDED SYSTEMS DESIGN is forbidden without permission.
INDUSTRIAL AEROSPACE SYSTEM ON A CHIP
THREADX: WHEN IT
REALLY COUNTS
When Your Company’s Success, And Your Job, Are On The Line -
You Can Count On Express Logic’s ThreadX® RTOS
Express Logic has completed 14 years simply must succeed. Its royalty-free
of successful business operation, licensing model helps keep your BOM low,
and our flagship product, ThreadX, T H R E A D and its proven dependability helps keep
has been used in over 800 million your support costs down as well. ThreadX
electronic devices and systems, repeatedly tops the time-to-market results
ranging from printers to smartphones, from single-chip reported by embedded developers like you. All the while,
SoCs to multiprocessors. Time and time again, when Express Logic is there to assist you with enhancements,
leading manufacturers put their company on the line, training, and responsive telephone support.
when their engineering team chooses an RTOS for their
next critical product, they choose ThreadX. Join leading organizations like HP, Apple, Marvell, Philips, NASA,
and many more who have chosen ThreadX for use in over 800
Our ThreadX RTOS is rock-solid, thoroughly field-proven, million of their products – because their products are too
and represents not only the safe choice, but the most important to rely on anything but the best. Rely on ThreadX,
cost-effective choice when your company’s product when it really counts!
Contact Express Logic to find out more about our ThreadX RTOS, FileX® file system, NetX™ Dual IPv4/IPv6 TCP/IP stack, USBX™
USB Host/Device/OTG stack, and our new PrismX™ graphics toolkit for embedded GUI development. Also ask about our TraceX®
real-time event trace and analysis tool, and StackX™, our patent-pending stack size analysis tool that makes stack overflows a
thing of the past. And if you’re developing safety-critical products for aviation, industrial or medical applications, ask Newnes
ThreadX, FileX, and TraceX are registered trademarks, and NetX, USBX, PrismX, StackX, and Certification Pack are trademarks of Express Logic, Inc.
All other trademarks are the property of their respective owners.
EMBEDDED SYSTEMS DESIGN BY Ron Wilson#include
Editorial Director
Ron Wilson
(415) 947-6317
ron.wilson@ubm.com
Dumbing down embedded
Managing Editor
Susan Rambo
(415) 947-6675
susan.rambo@ubm.com
design
Acquisitions/Newsletter Editor,
ESD and Embedded.com
Bernard Cole
(928) 525-9087
bccole@acm.org
Contributing Editors
W hen John Bruggeman left Wind
River to become chief market-
ing officer at Cadence Design
Systems, he didn’t leave the embedded
community so much as he shifted to a
This may sound infeasible and un-
desirable. But please remember that
we’ve seen this shift before. Skilled as-
sembly-level programmers objected—
rightly, but irrelevantly—that compil-
Michael Barr
Jack W. Crenshaw new phase of the industry’s evolution. ers could never generate the code
Jack G. Ganssle Neither did he leave behind his ear for a quality they could for embedded sys-
Dan Saks
great sound bite or his ability to spot tems. Crafters of bare-metal code and
Art Director
Debee Rommel the trend behind the noise. application-specific kernels railed—
debee.rommel@ubm.com At the Design Automation Confer- with equal justification and effect—
Production Director ence this June, Bruggeman showcased that no off-the-shelf RTOS could be as
Donna Ambrosino
dambrosino@ubm-us.com both these traits in one statement. We efficient and reliable as their creations.
Article submissions
were discussing the struggle to increase All were swept away into niches where
After reading our writer’s guidelines, send the level of abstraction in embedded their expertise was defensible. Today
article submissions to Bernard Cole at
bccole@acm.org
systems design, and he remarked, “This there are few surviving practitioners of
whole fragmented, RTOS-tied world is either assembly-language program-
Subscriptions/RSS Feeds/Newsletters
www.eetimes.com/electronics-subscriptions shrinking. We are coming to the point ming or proprietary kernel develop-
Subscriptions Customer Service (Print) where only a handful of mission-critical ment who are not working for an
Embedded Systems Design applications will use an RTOS and code RTOS vendor or—increasingly—a
PO Box # 3609
Northbrook, IL 60065- 3257 developed in C/C++. Everything else is semiconductor company. “Between
embedsys@omeda.com going to the Linux/Android world.” Portland and Alameda, Intel alone has
(847) 559-7597
Bruggeman’s concept is that the about three thousand software devel-
Article Reprints, E-prints, and
Permissions Linux port, libraries, drivers, and tasks opers,” Bruggeman observed.
Mike Lander with hard deadlines are becoming the So what is the future for skilled
Wright’s Reprints
(877) 652-5295 (toll free) responsibilities of the IC vendors, not craftspeople who know an RTOS or
(281) 419-5725 ext.105 the embedded systems developers. All three inside-out, are black-belts in C or
Fax: (281) 419-5712
www.wrightsreprints.com/reprints/index.cfm this work gets done once per chip fami- C++, and can deploy linked-list struc-
?magid=2210 ly, before a new MCU line or SoC is in- tures, hash tables, complex interrupt
Publisher troduced—not once per application. schemes, and similar joys to actually
David Blaza save memory and slash energy con-
(415) 947-6929
When an embedded design team selects
david.blaza@ubm.com a chip, the IC comes with a platform sumption? You need a strategy.
Associate Publisher, ESD and EE Times such as Android or AUTOSAR (the AU- One approach would be to embrace
Bob Dumas Tomotive Open System ARchitecture, if the future: use your skills to become a
(516) 562-5742
bob.dumas@ubm.com you haven’t been following that indus- black belt in Android development, or
try) already running. The embedded an AUTOSAR guru. Another would be
systems design team writes their appli- to find markets likely to be late adopters
cation in Java, just as if they were writ- because of hardware or legacy-code
ing an iPad app. All of the complexity limitations, power constraints, or cul-
Corporate—UBM Electronics of machine-dependent and time-criti- tural isolation. This can delay the in-
Paul Miller Chief Executive Officer
David Blaza Vice President cal code is encapsulated by the chip evitable, but it has about it a bit of
Karen Field Senior Vice President, Content
Felicia Hamerman Vice President, Marketing maker. striping the road in front of the steam-
Brent Pearson Chief Information Officer
Jean-Marie Enjuto Vice President, Finance
roller. Or you can join a semiconductor
Amandeep Sandhu Director of Audience Engagement &
Analytics
Ron Wilson is now edi- company. But I don’t suggest denial.
Barbara Couchois Vice President, Partner Services & tor-at-large on EDN Whatever you decide, don’t just sit
Operations
magazine. This is his last
Corporate—UBM LLC #include as the editorial there.
Marie Myers Senior Vice President,
Manufacturing
director of Embedded
Pat Nohilly Senior Vice President, Strategic Systems Design. You
Development and Business
Administration
may reach him at
ron.wilson@ubm.com.
www.embedded.com | embedded systems design | JULY/AUGUST 2011 5
INNOVATOrs buIld NeTwOrks wITh explOsIVe speed
ANd excepTIONAl INTellIGeNce.
How do innovators build networks of stunning speed and intelligence, while keeping costs squarely under control?
They work with Wind River. Our advanced networking solutions give leading network equipment manufacturers the
packet acceleration, hardware optimization, and system reliability they need to deliver breakthrough performance and
greater value—from the core to the consumer and everywhere in between. All while reducing their costs and cutting
their time-to-market so they can focus on innovation to create a truly competitive edge.
!
very sophisticated free-ware packages shots at http://sourceforge.net/project/
like Eclipse that can be tweaked to pull
Twenty years ago the screenshots.php?group_id=126731.
the various tools together should reduce big buzz was making —przemek
the cost-of-entry for small teams want-
ing to add their contribution to the
ecology in this niche.
I’m sure there’s business in here but
! software more like
hardware. Anyone
These days there seems to be growing
interest in using the python Scipy,
Numpy, and Sage for numerical pro-
not as we know it.
Finally, the processor comes together with the FPGA in a fully extensible
processing platform called Zynq.™ More intuitive to program in the way
you already know. Fully customizable to your requirements. Faster to
®
implement and get to market. As a software engineer, if you know ARM Cortex,™ you already
know Zynq. And if you know Xilinx, you already know this is innovation you can count on.
Visit us at www.xilinx.com
© Copyright 2011. Xilinx, Inc. XILINX, the Xilinx logo, Zynq, and other designated brands included herein are trademarks of Xilinx in the United States and other countries. All other trademarks are the property of their respective owners.
ARM is the registered trademark of ARM Limited in the EU and other countries. Cortex is the trademark of ARM Limited in the EU and other countries.
I would not use your brain core like that of Star Trek, but it looks like tion of the middle class and greater sep-
temperature example as one of sensor the first ones to go the stars are the aration between the wealthy and the
fusion, but more a case of simulated technology rather than us human. I poor. Elimination of labor, in general,
plant state where we create a simulation wonder if smart robots will go first in does not necessarily help people psy-
of the thermal functioning of the brain to a 50-year voyage into the far, far, and chologically. We want to have a sense of
to create a model of temperatures we away part of the galaxy. It surprised me accomplishment and relevance. Being
cannot measure due to lack of access. to think about the other possible result free to paint, write music, smoke dope,
In the circles I’ve moved in, sensor from a robot boom... “kill all the engi- or watch TV 24 hours a day does not
fusion is far more about using tech- neers”? Yikes! I surely hope that doesn’t make for happy, well-adjusted citizens.
niques like Kalman filters to take meas- become a reality. I’ve been reading All it does is provoke an entitlement
urements from multiple different sen- much of our problem with oil shortages mentality that ultimately results in vio-
sor types and combining them so that and the need for new energy resources lence when the goodies run out.
we can synthesize a set of measure- but to consider now that we have to Why do so many men (particularly) die
ments that provide an accurate meas- tame the technology development for soon after retirement? They lost a sense
urement. For example, accelerometers of purpose—in general, those who sur-
and gyros both have their shortcom- vive are those who have found some-
ings, but sensor fusion allows us to
mash these together to get the useful
info while sidestepping the limitations.
——cdhmanning
! “Kill all the engineers”?
Yikes!
thing to give to others—a sense of be-
ing needed, and accomplishment of
something that matters.
Outside of a few specialties, such as
our own sake adds another burden. It very dangerous working environments
As has been mentioned in the article, it’s looks like humanity has now to evolve and things like self-driving cars, I think
not just the state machine but some- and become more of an adult as we that ultimately robots will benefit only
thing like artificial intelligence, applying need to perhaps stop doing things for those who own the manufacturing sys-
the interpolation and extrapolation our own benefit and not just do be- tems. As robots become more “aware”
techniques, similar to what is being ap- cause we can. That’s maturity. Does hu- they may decide, as some sci-fi writers
plied in robotics. This is OK for robots man history resemble that of a life of a have warned, that people are just get-
to do these kind judgments based upon human being? ting in the way...
the surrounding situation but in an au- —Luis Sanchez —NevadaDave
tomotive situation such inferior dupli-
cation of what a common driver’s hu- Absolutely fascinating, Jack! This edito- Thanks for the article! There is just one
man mind can do in a split second is an rial brings to mind several things: Wolf error, the refresh rate of the screen is
unnecessary addition to already over- and Iron, a book by Gordon Dickson, in not once per second, this only occurs if
crowded electronics in the automobile. which the world’s economic system un- the trigger is not properly set. My guess
—prabhakar_deosthali dergoes a sort of “soft” collapse, and is that the trigger level was not adjusted
those who can actually “do” things (as to the center of the waveform. Once
Situational awareness opposed to those who shuffle money triggered, you will find that the screen
Although of great interest and noble around) are the ones who survive. Sec- refresh is actually very fast (up to 32Hz
goals (“Sensor fusion brings situational ond, regarding Star Trek—one thing depending on the settings). A printable
awareness to health devices,” Supreet that I constantly find fascinating is how manual will be available soon.
Oberoi, www.eetimes.com/design/embed- early sci-fi writers virtually never “got” —ganzziani
ded/4216526) with a potential to benefit how computer technology would shape Gabriel Anzziani
medical care delivery, the implementa- the future societies. In reality, the Enter- Gabotronics
tion [of situational awareness] will al- prise would be run by mind commands
ways have the burden of contemporary from just a few individuals—more like The Gabotronics breadboard oscillo-
medicine—patient compliance with Carl Sagan’s “spaceship” in Cosmos. scope is indeed a really nice piece of
medication / sensor(s). We’re getting close to mentally con- work, and at a great price! Another
—ReneCardenas trolled systems now. similar product is the also open-
I fully expect to see self-steering source Seeed Studio DSO-Nano. It’s a
Creative writing cars available in not too many years. As bit more expensive ($89), and only
I almost got goosebumps reading about far as social attitudes and conse- single channel, but is in a field-ready
slaves (“Of slaves and scopes,” Jack quences—“Them that’s got shall get, enclosure. (It has a different product
Ganssle, June 2011, www.eetimes.com/ them that’s not shall lose...” We will see slant—field versus breadboard use.)
4216410)! I hope the future becomes the continuing trend toward elimina- —Mark Moulding
!
You should make automated engine, a screenshot from
rule checking part of the
followers. Automatic enforcement which is shown in Figure 1,
everyday software build points the way to greater compliance. comes preconfigured with
process. Ideally, you would support for more than a
restrict version control dozen popular coding stan-
check-ins to accept only code that has passed all automat- dards applicable to development of real-time embedded
ed checks. software, including those from JPL, MISRA, and Netrino.
Likewise, no code that violates any automatically-en- For example, out of the box, LDRA’s static analysis en-
forceable rule should be allowed into a peer code review. gine is able to automatically enforce about 80% of the
That way, human code reviewers can focus their limited rules in the Embedded C Coding Standard (Michael Barr,
time and attention on (1) what the module or function is 2009, Netrino). Some coding standard rules, such as those
regarding the names of variables and functions or the con-
tents of comments, can only be enforced by human code
Michael Barr is the author of three books and over reviewers.
60 articles about embedded systems design, as well Teams with smaller budgets should consider using in-
as a former editor in chief of this magazine. He is a
popular speaker at the Embedded Systems expensive tools they may already have. Each such tool will
Conference, a former adjunct professor at the only be capable of enforcing a subset of the rules automat-
University of Maryland, and the president of Netrino. ically, but used together they may be able to enforce the
You may reach him at mbarr@netrino.com or read
his blog at www.embeddedgurus.net/barr-code. majority of the more common rules. The following sec-
! sophisticated commercial
static-analysis tool.
Figure 1
tions look at the configuration settings available in a pair of 2.1.b Comments shall never be nested.
widely-used static analysis tools: PC-Lint and RSM.
The relevant PC-Lint configuration generates an error
PC-LINT whenever nested comments are found in the code:
Gimpel Software’s PC-Lint (www.gimpel.com) is a widely
used and inexpensive static-analysis tool for C and C++ pro- +e602
grams that has been continuously maintained for more than
25 years. Pricing depends on the number of users and host PC-Lint can also be used as an aid to clean up nested
operating system but starts at just $389. (For those develop- header file inclusions to comply with this rule:
ing software on Linux/Mac/Unix rather than a “PC”, there is
a version called FlexeLint, which starts at $998.) 4.2.d No header file shall contain a #include statement.
In general terms, PC-lint is a “static analysis tool that will
check your C/C++ source code and find bugs, glitches, in- To configure the tool to highlight header files that aren’t
consistencies, nonportable constructs, redundant code, and actually being used by the source modules that (directly or
much more. It looks across multiple modules, and so, enjoys indirectly) include them, use these settings:
a perspective your compiler does not have.”1 The current ver-
sion is 9.00. In the context of automatically enforcing coding +e766 // Included header file not used in module.
standards, a number of PC-Lint’s configuration settings are +e966 // Indirectly included header not used.
of interest.
For example, suppose you want to enforce a coding rule A complete PC-Lint/FlexeLint 9.00 configuration file to
such as: automatically enforce numerous rules from the Embedded C
Coding Standard is available free online at netrino.com/files/
1.7.c The goto keyword shall not be used.2 pclint_netrino.lnt. Comments in the file make clear which
numbered rule(s) each group of configuration settings
PC-Lint can be configured to generate a warning message enforces.
each time the goto keyword appears in your C/C++ code by
including: RSM
M Squared Technology’s RSM (short for “Resource Standard
-deprecate( keyword, goto, violates coding standard ) Metrics”) is another inexpensive static-analysis tool for pro-
grams written in C/C++ (and similar languages). Pricing de-
in your local .lnt configuration file. pends on the number of users and host operating system but
Here’s another example of a rule that can be automatical- starts at under $200. Versions of the tool are available for
ly enforced this way: non-PC development platforms as well.
DRIVEFORINNOVATION
12 months. 10,000 miles. Many technology stops.
Join us on the ultimate electronics road trip. Learn new technologies and
supply chain options, access tools, industry icons and innovators along the way.
driveforinnovation.com
RSM configuration options to enforce the Netrino’s Embedded C Coding Standard.
Rule # Brief rule description Configuration notes
1.2.a Line length limited to 80 characters. Quality Notice 1
1.3.a Braces surround all blocks of code. Quality Notice 22
1.7.c Keyword goto not used. Quality Notice 9
1.7.d Keyword continue not used. Quality Notice 43
1.7.e Keyword break not used outside switch. Quality Notice 44
2.2 Location and content of comments. Quality Notices 17, 20, 51; Options -Es -Ec -EC
3.1 Use of white space. Quality Notices 16, 19
3.5.a No tab characters. Quality Notice 30; Option -Dt
3.6.a UNIX-style (single-character) linefeeds. Option -Du
4.1.a-d Module naming conventions. Option -Rn
4.2.a Precisely one header file per source file. Option -Rn
6.1.a-e Precisely one header file per source file. Quality Notice 2; Option -l
6.2 Cyclomatic complexity of functions. Quality Notices 10, 18, 27; Option -c
6.3.b.i-iii Preprocessor macro safety mechanisms. Option -m
8.2.d If-else if statements always have else. Quality Notice 22
8.3.b Switch statements always have default. Quality Notices 13, 14, 56
8.5.a No unconditional jumps. Quality Notices 9, 43, 444
Table 1
In general terms, RSM is a “source code metrics and Table 1 identifies other coding standard rules that can be
quality analysis tool.”3 The current version is 7.75. Among enforced by RSM as well as the specific quality notices and/or
other things, RSM counts numbers of lines of code vs. white options that apply to each.
space and comments, number of function points, and com- A complete RSM 7.75 configuration file to automatically
putes the cyclomatic complexity of individual functions. enforce numerous rules from the Embedded C Coding Standard
And oh so much more, including lint-like features. In the is available free online at http://netrino.com/files/rsm_netrino.cfg.
context of automatically enforcing coding standards, a Comments in the file make clear which numbered rule(s) each
handful of RSM’s configuration settings are of interest. group of configuration settings enforces.
For example, suppose you want to be notified about lines Remember, it is always cheaper and easier to prevent a
of code that exceed a certain maximum acceptable line length bug from creeping into code than it is to find and kill it after
as in the rule: it has entered. A key strategy in this fight is to write code in
which the compiler, linker, or a static-analysis tool can detect
1.2.a The length of all lines in a program shall be limited to a bugs automatically—in other words, before the code is al-
maximum of 80 characters. lowed to execute.
To be effective, coding standards must be enforceable as
The RSM Quality Analysis feature set always checks code well as actually enforced. Thus, regardless of the coding
for certain signs of quality. Among those is the following: standard you choose to follow, tools and techniques like
those described here should be part of your team’s bug-
Quality Notice No. 1: Emit a quality notice when the physical killing toolbox. ■
line length is greater than the specified number of characters.
ENDNOTES:
Configuration “options” can be also applied. For exam- 1. See http://www.gimpel.com/html/products.htm for other general infor-
ple, to enforce: mation about PC-Lint and FlexeLint features.
2. This and the other numbered rules in this article are excerpted from
3.5.a The tab character shall never appear within any module. the book Embedded C Coding Standard, which is available in print and
electronic editions from http://netrino.com/coding-standard/, Ama-
just add option ‘Dt’ as follows: zon.com, and other booksellers.
3. See http://msquaredtechnologies.com/m2rsm/ for other general infor-
mation about RSM features.
-Dt
T ouch-sense keys are gaining popularity with both end users and de-
velopers of everyday human-interface applications because the
technology is aesthetically appealing, easy to use, and avoids any
mechanical design. In particular for developers, capacitive touch
sensors are popular because they can be implemented using a cop-
per pad as part of the standard printed circuit board’s design.
!
tion must be per- This article
formed by an scan and control of describes two ap-
electronic device, capacitive keypads— proaches, both
which requires based on voltage
power to operate.
But there is a
problem. Current
technology re-
! irrespective of power-
consuming mode.
variation, that can
be used for imple-
menting capaci-
tive touch sensing.
quires that the The first ap-
electronic device, when in a sleep proach is implemented with a charge
mode, be awakened before it scans the time measurement unit (CTMU) pe-
keypad matrix of capacitive touch sen- ripheral that can be implemented on-
sors. When the electronic device is in a chip with the microcontroller. Cap-
low-power standby or sleep mode, one touch solutions using the CTMU
of two things occur: either response peripheral will have a faster response,
time to the detection of the capaci- as it has different ranges of current
tance degrades or power consumption source that help to charge the analog
of the electronic device suffers. channels at a faster rate—thereby im-
Clearly, what is needed is a way to proving the response time of the cap-
provide automated scan and control of touch system.
capacitive keypads—irrespective of The second approach is the more
whether the major power-consuming traditional one which uses the capaci-
VDD
ADC
+
ANX Input VCHOLD
CHOLD
–
CSENSORn
Sensor N
Figure 1
EDGEN CTMUICON
EDGSEQEN
EDG1SELx
EDG1POL ITRIM<5:0> TGEN
EDG2SELx IRNG<1:0> IDISSEN
EDG2POL EDG1STAT CTTRIG
EDG1MOD EDG2STAT Current source
EDG2MOD
Timer1
Pulse
generator CTPLS
OC1 A/D Comparator 2
converter input
Comparator 2
output
Note 1: Refer to the specific device data sheet to determine which registers are available on your particular device.
Figure 2
!
charged from a constant current
the equation, a relative
• The capacitive touch sensor, which source for a fixed time period (T),
shift in capacitance can be acts a capacitor, is connected to a and the voltage (V) across the sen-
channel that is multiplexed with sor is measured using the A/D
! sensed by observing a
change in voltage. A block diagram of a CTMU-based cap-touch system.
CTMU
from the time the current source starts
ADC
and stops charging the circuit. Sensor 0 MUX
It can be used to provide up to 27
channels for time or charge measurement,
depending on the specific device and the
number of A/D channels available.
The CTMU can be “programmed”
for a variety signal-source variations, via
Channels
on-chip registers containing control bits
…
for configuring edge source selection, CA/D
edge source polarity selection, edge se-
quencing, A/D trigger, analog circuit ca-
pacitor discharge, as well as for selecting
the current source range and current
A/D converter
source trim.
Sensor 15
THEORY OF OPERATION
Operationally, the CTMU peripheral is Figure 3
IxT=CxV
where:
!
converter, as illustrated in tance is caused by a touch on the
Figure 4. sensor pad.
The CTMU peripheral is
• This voltage remains relatively
constant in the successive itera- The availability of a constant cur-
connected directly to the
tions of charge measurement, as
long as no change in the capaci-
rent source in the CTMU peripheral, in
conjunction with a multichannel A/D
! A/D converter’s input,
allowing it to connect to
THE BASICS OF CAPACITIVE TOUCH-SENSING
TECHNOLOGY
The recent success of the capacitive-sensor scroll wheel, now being
! any pin through the ana-
log multiplexer.
used in quite a few devices, has given this technology an edge over
other touch-sense technologies. converter, provides an effective plat-
When any object with capacitive characteristics—such as a fin- form for interfacing to the capacitive
ger—comes close to a capacitive touch sensor, it acts as another ca- touch sensor.
pacitor due to its dielectric nature. This varies the effective capacitance The CTMU peripheral is connected
of the system, which is used to detect the touch. directly to the A/D converter’s input, al-
The finger acts as one of the parallel plates, while another parallel lowing it to connect to any pin through
plate is connected to the sensor input of the chip, as shown in the illus- the analog multiplexer. With this con-
tration below. The iron content in human blood creates strings of ca- figuration, a CTMU peripheral can
pacitors that are aligned to the surface of the body. When such strings measure the capacitance of all the sen-
of capacitors come in proximity with a conductor, a capacitance that sors that are connected to the A/D con-
is essentially coupled to ground is created, which causes a change in verter channels.
the measured voltage, determining the touch. The trim bits associated with the
A typical capacitive touch-sense system is composed of three main current source facilitate the calibra-
functional blocks: tion, to counter the external interfer-
ence and transmission losses.
• An analog block for capacitive sensing.
FIRMWARE ELIMINATES EMI/EMC
• A controller for processing the data. Factors such as humidity, heat, extent of
• An interface block for communicating with a host processor. touch, contaminants on sensors, and
EMI/EMC interference can cause dy-
namic fluctuations in capacitance,
thereby impacting the system’s capaci-
The principles of capacitive touch sensing.
tive touch-sensing capabilities.
To counter these influences,
firmware can be employed with both
CF
the CVD and CTMU methods. Trip-
level dynamic variation can also be
used. These techniques will make the
system more robust.
Area
Additionally, this approach allows
Protective overlay
the use of software filtering, which re-
Copper pad
sists any residual noise on the sensor
d Printed circuit pad by programming the firmware reg-
board isters to distinguish between a touched
CS and an untouched condition.
Design teams can develop algo-
rithms for both the CMTU and CVD
CF Finger capacitance methods that detect multiple-touch
CS Sensor capacitance
d Distance between the plates
conditions, to help the system differ-
entiate between the intended and the
unintended touch. The software can
BOSTON
September 26-29, 2011.
Attend the East Coast’s Leading Embedded Systems Event.
ESC Boston drives product discussions and faster applications, delivers training and education on
the latest technologies, and helps you discover new solutions to your real-world design challenges.
Explore ESC Boston’s Agenda! Customize your schedule and attend sessions covering today’s most
relevant engineering issues.
Applications Hardware for Embedded Keynote Speakers
• HMI and Multimedia Systems
• Systems Architecture • Challenges and Solutions in
• Reliability, Security, and Embedded Designs
Performance • Connectivity and Security
• Remote Monitoring and Wireless • Programmable Logic and Memory
Networking • Low Power Design and
Microcontrollers
Embedded Software Joerg Borchert Charles G. Sodini
• Linux/Android/Open Source Topics in Embedded-System Vice President, Chip LeBel Professor EECS
• Programming for Storage, I/O, and Design Card & Security ICs MIT
Infineon Technolo-
Networking • Architecture Design gies North America
• Programming Languages and • DSP, Communication,
Techniques and Control Design
• RTOS and Real Time Software • HW and Platform Design Register Now for 10% off ANY package!
• Software Processes and Tools • Quality Design and Intellectual
Property Expo Pass registration is FREE.
Tools and Best Practices esc.eetimes.com/boston
• Debugging and Optimizing
• Design and Test
Promo Code: AD1
• Process and Management
!
Separation between the sensors. The proximity of the sen-
sor to the adjacent sensors should be considered. When a sensor is
the intended and the
touched, the finger introduces additional capacitance not only to the unintended touch.
current sensor, but also to the nearby sensors. Therefore, to insulate the
finger’s capacitance, a space between adjacent sensors must be main- When the sensor is pressed, the
tained. Ideally, the sensors’ separation should be 2 to 3 times the thick- firmware can provide feedback by dis-
ness of the covering material of the capacitive touch-sense system. For playing the appropriate status of the
example, if the thickness of the covering material is 3 mm, the distance touch sensor in the LCD module, driven
between the sensors should be 6 mm to 9 mm, for a typical capacitive- by the pins in Port D. A six-pin header is
touch design. provided, for connecting the reference
Length of the trace. The trace length between the sensor and board to a hardware programmer.
the microcontroller must not be too long, which otherwise might have a
higher susceptibility to parasitic capacitance. This could change the THE CVD OR CTMU
trace resistance and will affect the sensitivity. Ideally, the length of the In this article, we’ve described two ap-
trace should not exceed 12 inches (300 mm). proaches to awakening electronic de-
Material and thickness of the covering material. The vices that have capacitive touch key-
covering material used and its thickness determines the capacitance of pads. We briefly touched on the CVD
a finger that is transmitted to the capacitive-touch sensor. The covering method, which uses a microcontroller’s
material used must have a large dielectric constant, to increase the A/D converter, and went into some de-
sensitivity. Keep the covering material as thin as possible. If the thick- tail about the CTMU method, which in-
ness of the covering material increases, then the crosstalk effect be- volves a separate MCU peripheral. The
tween the sensors increases. CTMU approach enables the design of
Grounding techniques. The sensing method is affected by the scan modules that detect the actuation
parasitic capacitance of a sensor to ground. This can be countered by of any capacitive touch sensor; these
placing ground very close to the sensor, which increases the parasitic modules remain in operation even
capacitance and, hence, reduces its effect on the sensor. when major power-consuming circuits
Selecting an adhesive. The adhesive is used to secure the of the electronic device are in a sleep
covering material to the PCB. The adhesive that is used should be kept mode and will not wake up the major
thin, in order to keep the sensitivity high. Care should be taken to power-consuming circuits until an ac-
make sure that there are no air bubbles when applying the adhesive. tion requiring the circuits is needed.
The bonding instructions of the adhesive should be read before apply- This approach reduces the overall
ing it. power consumption of the electronic
0.1
D+
RD3
RD2
RD1
RDO
D-
VDD
44
43
42
41
40
39
38
37
36
35
34
VUSB
RC6
RC5/D+
RC4/D-
RD3
RD2
RD1
RDO
RC2
RC1
N/C
RC7 1 RC7 N/C 33
2 RD4 RC0 32
RD4
RD5 3 RD5 OSC2 31
4 30 Y1
RD6 RD6 OSC1
VDD 5 29 VDD
RD7 RD7 U1 VSS 8 MHz
6 18F46J50 28 D0
VSS VDD C10 C11
7 VDD RE2 27 D1
8 RB0 RE1 26 C8 22pf 22pf D2
C1 9 25
RB1 RE0 D3
10 24 0.1
0.1 RB2 RA5 RD D4
11 VDDCORE/VCAP 23 LCD
RB RD D5
RA0/AN0
RA1/AN1
RA2/AN2
RA3/AN3
RB6/PGC
RB7/PGD
C9 RD D6
MCLR
RB5
N/C
N/C
RD D7
RB
6.8µF
12
13
14
15
16
17
18
19
20
21
22
RD EN
J1 RD RS VDD VDD
PGC
PGD
Sensor1
1 R17 100 RD RW
MCLR VSS VSS
2 VDD Sensor2
3
4 Sensor3
5
6 VDD Sensor4
R18
Program 10K
MCLR
C7
0.1
Figure 5
device while still maintaining the scan- division. He is a group leader for the ca- its MCUs and the CTMU and CVD methods,
ning of the capacitive sensors on such pacitive touch-sense applications team see application notes and product data sheets,
as well as for the PIC18, 8-bit microcon- available from their website online:
things as keypads. When the CTMU de- troller products at Microchip’s India De-
tects a valid key press of a capacitive sign Center.
touch sensor, the CTMU sends an in- • PIC24F Family Reference Manual, Sect. 11
Charge Time Measurement Unit (CTMU),
terrupt to the electronic device that Harsha Jagadish is an applications engi- DS39724B.
brings it out of a sleep mode and into neer in Microchip Technology’s Advanced
an operating mode, for further process- Microcontroller Architecture Division. Har- • Perme, Tom. “AN1101: Introduction to Ca-
pacitive Sensing.”
sha has worked on various PIC microcon-
ing and appropriate action commensu-
rate with the actuation of the specific
trollers for applications ranging from user- • Davison, Burke. “AN1334: Techniques for
Robust Touch Sensing Design.”
interface development, energy-meter
capacitive touch sensor. ■ designs, and personal-electronic-device
accessories for smartphones and tablets.
• Bohn, Bruce. “AN1250: Microchip CTMU
for Capacitive-Touch Applications.”
Nithin Kumar Mada is a senior applica-
tions engineer in Microchip Technology’s FURTHER READING: • Perme, Tom. “AN1298: Capacitive Touch
Using Only an ADC (CVD).”
Advanced Microcontroller Architecture For more information from Microchip about
Round up samples of your best marketing efforts and enter the contest today. Take
advantage of an opportunity to make history - be the first to win an ECIA marketing
award!
CATEGORIES: P R E S E N T E D AT T H E
E C I A 2 0 11 E x e c u t i v e C o n f e r e n c e
Best PRINT
Brand Awareness Campaign M O N D A Y, O C T O B E R 2 4 T H
Co-OpAdvertising Campaign
I N T E R C O N T I N E N TA L C H I C A G O O ’ H A R E
Corporate Capability Brochure
Corporate Newsletter
ECIA, in partnership with UBM Electronics, is
Best DIGITAL pleased to present this NEW opportunity to
Search Engine Optimization showcase ECIA members’ marketing efforts!
Social Outreach
Web Promotion
Corporate e-Newsletter Your team does a great job of branding your
Best Online Campaign company - this is a chance to grab some well
Best INTEGRATED deserved, industry-wide recognition.
Integrated Marketing
Industry Advocacy
There is a nominal $45 fee per entry -
Best of SHOW enter as many categories as you like.
Single Entry with Highest Score
Enter at
www.eciawards.com
ECIA - connecting all segments of the industry: manufacturers, authorized distributors and manufacturers representatives. www.eciaonline.org
feature
Designing with
core-based
high-density FPGAs
M
BY ROBERT S. GRIMES
Figure 2
!
second window of the minimum, maxi- 16-bits wide, a single interrupt could be
mum, and average values for the pulse
supplied version, and used to read all 16 channels from a sin-
characteristics (for example, delays, use it for the A/D. gle A/D converter.
width, peak amplitude, and total ener- So, I decided to create a new SPI16
gy), and these were sent, along with a each output pulse as necessary to time- controller, based on the supplied ver-
representative pulse, to the main proces- align the output laser pulses. In this case, sion, and use it for the A/D. This was an
sor for storage. the peripheral was fully custom, though example of starting with a supplied IP
the wizard automated the connection to and customizing it for your purposes.
OTHER CUSTOM PERIPHERALS the processor. It should be noted that the SPI16 de-
Other custom peripherals were needed to We also had to create custom periph- velopment was quite trivial, as the sup-
support system devices, both unique and erals for some common devices. For an plied SPI IP already had parameters for
common. As an example of the former, as example, we used a number of Analog the width of an SPI word, but they were
I mentioned earlier, the system actually Devices’ multichannel A/D converters not exposed to the design environment,
consists of four lasers that are combined (the 16-channel AD7490) for acquiring so they could not be changed. All I had
to create the final output. In order to gen- sensor data; these were interfaced to the to do was recode them to 16 bits, make a
erate a coherent pulse, the four must emit FPGA via a serial peripheral interface few other minor adjustments, rename
their pulses (nearly) simultaneously. (SPI) with multiple chip selects. The A/D the IP to a unique name, and I was done.
Each laser is sent a “sync pulse” converter represented a challenge not Finally, I believe the newer versions of
which is used to trigger its Q-switch, and well met by the stock SPI controller pro- the Xilinx EDK tools provide more flexi-
ble SPI controllers, so I would not have
had to develop my own.
Software block diagram.
Four distinct software components cooperate to implement the necessary functionality on top of the Virtex-4FX- SOFTWARE DESIGN
based hardware platform. The software to support the hardware
design in meeting the system require-
Master or laser ments consisted of a number of ele-
application
ments, as illustrated in Figure 3. There
are two distinct boot-time programs
MicroMonitor
(which I’ll describe next), along with a
real-time operating system (RTOS)—
RTEMS and
board-support package the Real-Time Executive for Multi-
Bootstrap
processor Systems (RTEMS) and its
board-support package (BSP). The ap-
plication programs (“master” and
“laser” for the respective processors) use
Virtex-4FX
the environment set up for them by Mi-
croMonitor and RTEMS as a framework
Figure 3
!
sort of guru and booster.
The other responder had already de- subscribing to a pro- Associates, an embedded systems devel-
opment firm based in Boston, MA. Bob is
veloped drivers for several of the periph- ject’s mailing list or a 1983 graduate of MIT, where he first
learned of the joys of combining hard-
erals, which he was so kind to supply to
the effort. Together with Thomas, we
were able to incorporate the drivers into
a new BSP for the Virtex, which I was
able to build and test with early proto-
! forum and post a simple
statement of your plans.
ware, firmware, and software to control
some small aspect of the world at large.
In recent years, he has been busy sorting
garbage (he developed the control elec-
tronics for a recycling system), discover-
ing water (he designed the FPGA “brain”
types of my applications. building the driver as part of my appli-
in a near-infrared spectrometer that dis-
cation, which was relevant for only the covered water on the Moon during the
OTHER DRIVERS main processor anyway, so exposing a bit NASA LCROSS mission), and developing
Other drivers were needed for the IP of extra complexity there seemed worth vestibular research systems for diagnosing
chosen to communicate with my sys- it, at least to me! The important thing is balance disorders at the Massachusetts
Eye and Ear Infirmary (Boston, MA) and
tems’ devices. For example, we used a to remember there are usually several the University of Berne (Switzerland).
number of SPIs to connect multichannel ways to do most things in software! Robert Grimes may be reached at
A/D and D/A converters, Ramtron rsg@alum.mit.edu.
FRAM nonvolatile memories, an SD LESSONS LEARNED
(Secure Digital) card for removable me- I learned these three lessons:
dia, and a temperature monitor chip. ENDNOTES
This required development of a low- 1. Seek collaborators early and often. 1. Wikipedia definition of “Q- Switching” at
level driver that plugged into RTEMS’ Start early by subscribing to a pro- en.wikipedia.org/wiki/Q-switching.
driver manager framework, and specifi- ject’s mailing list or forum and post 2. Real-Time Executive for Multiprocessor
cally, its I2C/SPI subsystem. Fortunately, a simple statement of your plans. If Systems or RTEMS at www.rtems.com.
because my custom SPI16 peripheral you’re not sure how to start, ask for 3. Ed Sutter’s MicroMonitor is “a free em-
was based on the stock peripheral, I was pointers in getting started. Offer to bedded system boot platform centered
able to use the same driver for both; still, work with others who are working around an extensible embedded flash file
system called TFS.” http://umonfw.com/.
this did take a bit of time to get it exactly on similar applications, or who may
4. Grimes, Robert S. Comment posted on
correct, but once done, I was able to be interested.
RTEMS.com. “RTEMS port to Virtex-
communicate with all the above devices, 2. Understand an open-source soft-
4/PowerPC” at www.rtems.com/ml/rtems-
except the SD card. ware project’s licensing philosophy, users/2005/december/msg00067.html.
!
adult’s brain. For one finds that
deeply held beliefs and assumptions embedded system is a humbling experience. And
crumble when the tough choices of humility helps with the first two duties.
reality intervene. Very good reasons
arise why that core belief is simply, in
a particular case, wrong.
Here’s just one of many examples: ionably for most of a year, rebuilding BRILLIANT BUT BRITTLE
I was convinced that the high school an engine, swapping transmissions, Building embedded systems is, too, a
kids shouldn’t own cars. Like the fixing the brakes and all of the other humbling experience. Young engi-
Amish, I felt this would disrupt family issues. He learned auto mechanics neers charge into the development
life and create even more of a barrier and a pride in ownership of the battle armed with intelligence and
to communication. Then my son pre- phoenix that was the product of his hubris, often cranking out systems
sented a plan to buy—with his mon- vision and our shared experience. We that may work but are brittle. Unfet-
ey—two 30-year-old VW microbuses established a new, special bond de- tered by bitter experience, they make
with seized engines and a plethora of spite the afflictions of teenagerhood assumptions about the system and the
other problems, and build one work- that lasts to this day, many years later. environment it works within that,
ing vehicle from the pair of wrecks. Parents tack and jibe, slowly while perfectly natural in an academic
The result was exactly the oppo- learning the meta-lesson: all of our cloister, don’t hold up in the gritty
site of what I expected. We spent our assumptions are wrong. real world. Inputs are noisy. Crud gets
free time working together compan- into contacts. Mains power is hardly
pristine. Users do crazy and illogical
things.
The root cause of brittle systems
Jack G. Ganssle is a lecturer and consultant on embedded
development issues. He conducts seminars on embedded systems is making incorrect assumptions—as-
and helps companies with their embedded challenges. sumptions that may be so banal and
Contact him at jack@ganssle.com. so obvious no one questions them.
But question them we must.
For instance, what is the likeli-
The Big Idea: Business models, ecosystems EET on the QT: The inside scoop on deals,
and technology trends partnerships and who’s who
IP Landscape: IP trends and litigation news Market Data: Pricing, inventory and more
subscribe today
and receive 10% OFF your annual subscription. Promo Code: LR
!
the Arctic Circle where it crashed, the each stage being further injected, in-
algorithm unable to deal with a sun
couple of years later, his spected, detected, infected, neglected,
that wouldn’t rise for months. hair now snowy white. and selected (as Arlo Guthrie would
The sun may not rise tomorrow. say). The completely bogus result
Don’t count on anything. might indicate how much morphine
if variables a and b are each one, to push into the patient or how fast to
HARDWARE FAILS, TOO a+b==2 only on a good day. It could set the cruise control.
An instrument I worked on used a large also be 0x1ab32, or any other value, if Sure, these are safety-critical appli-
hunk of radioactive cesium-137 to any of a number of problems arise, cations that might (emphasis on
measure the thickness of steel. Elabo- such as one variable being clobbered “might”) have mitigation strategies to
rate safety precautions included a hard- by a reentrancy problem, or a stack prevent such an occurrence, though
ware interlock to close a shutter, block- getting blown. Google returns 168,000 results to the
ing off the beam, if the software went Complexity buried in our systems, keywords “FDA recall infusion
nuts. But at one point a defect in the even so deeply as to be invisible in the pumps.” But none of us can afford to
hardware design caused the shutter to code we’re examining (such as some tick off the customer in this hyper-
cycle open and closed, over and over, other task running concurrently), can competitive world.
even though the software was correctly corrupt even seemingly obvious My files are rife with photos of sys-
issuing commands to close the radia- truths. tems gone bad because developers
tion source. It’s hard to know where the The Y2K problem taught us only didn’t look for silly results. There are
invisible beam impinged, but I’m pretty one of two very important lessons in dozens of pictures of big digital clocks
sure that the VP looking down into the writing code: memory is cheap, and adorning banks and other buildings
unit was getting a dose to his forehead. one should never clip the leading dig- showing results like “505 degrees,” or
I saw him a couple of years later, his its of the year. (Perhaps we haven’t “-196 degrees.” One would think any-
hair now snowy white. Was the gray learned even that bit of pedagogy. The thing over 150 or so is probably not
from the radiation or his kids with their Unix Y2.038K bug still looms. I’m re- right. And the coldest temperature ever
shiny new drivers’ licenses? assured that will be long after senility recorded in nature on Earth is –129 de-
!
darn close but completely absurd. error can wreak havoc. A mechanical
Software is topsy-turvy. A This is a very small sample of engineer can beef up a beam to add
single error can wreak inane results from my files of dumb margin; EEs use fuses and heavier wire
computer errors. All could have been to deal with unexpected stresses. The