Catto / Topic Map · Digital Electronics IV Year 7
Digital Electronics IV · 120 h · Topic 5 of 6

Smart displays

The display is the only part of the equipment the user sees. An excellent instrument with a confusing interface is perceived as a bad instrument, and a poorly handled display is also one of the main consumers of processor time and battery current.

Multiplexing HD44780 Graphics Interface

01Seven segments and multiplexing

D1D2D3D4D1D2D3D4on-time of each digittimeFull cycle5 msEach digit1.25 msScan200 HzBrightness equivalent to 10 mA = 40 mA peak.Only one digiton at a time.Twelve lines insteadof twenty-eight.Below 60 Hz flicker is visible; that is why 100 to 200 Hz is used. The common pin of each digit gets a transistor.
Figure 1. Four-digit multiplexing, animated. At any instant there is only one digit lit; the scan is so fast that the eye sees them all together. This is how four digits are driven with twelve pins instead of twenty-eight.
Ipeak=Iavg·Nfscan≥60Hz With N multiplexed digits, each one is lit only 1/N of the time: to keep the brightness the peak current has to be raised in the same proportion, within what the display can take.
Worked example · Four digits

We want a brightness equivalent to 10 mA per segment in direct current, with 4 digits multiplexed and a scan rate of 200 Hz.

  • Each digit is lit 1/4 of the time, that is, 1.25 ms out of every 5 ms.
  • Peak current required: 10 mA × 4 = 40 mA per segment, within what is allowable in pulsed operation for most displays.
  • With all eight segments lit —the 8 with its decimal point—, the peak per digit reaches 320 mA: a microcontroller pin does not deliver that. A transistor per digit is needed.
  • At a 200 Hz scan rate, each digit is refreshed 200 times per second: there is no visible flicker, not even when moving your head.

Below 60 Hz flicker appears; between 60 and 100 Hz the flicker is noticeable when you move your eyes quickly or when filming the display.

The classic mistake: no resistors or no transistor

An LED connected directly to a pin without a current-limiting resistor is destroyed, and sometimes the pin with it. And even with resistors, the sum of the currents of the eight segments far exceeds what the common pin of a digit can handle: there is always a transistor on the common cathode or common anode. It is the most frequent cause of digits that look dimmer the more segments they have lit.

02Alphanumeric LCD

The HD44780 and its compatibles
  • 16×2, 20×4 and similar formats. It has been the de facto standard for decades.
  • It is driven with 8 or 4 bits of data plus three control lines. In 4-bit mode each byte is sent in two halves: six pins in total.
  • It distinguishes commands from data by the RS line: clearing, positioning the cursor and configuring are commands; characters are data.
  • It lets you define up to eight custom characters, which is how to get the ñ, accented letters, unit symbols or a progress bar.
  • The contrast potentiometer is not optional: without it, the screen looks blank or all black and seems broken.
With an I²C adapter

A port expander turns the six pins into two. It is what is almost always used today: it frees up pins and simplifies the wiring, at the cost of a slower refresh.

Timing matters: after a clear command the controller needs more than a millisecond. Writing without respecting those waits produces lost characters or garbage, and it is the mistake that makes it look like “the display is faulty.”

03Graphic and smart displays

TypeInterfaceCharacteristics
128×64 OLEDI²C or SPIVery high contrast, needs no backlight and consumes in proportion to the pixels that are lit. It degrades if it always shows the same fixed image.
TFT graphic LCDSPI or parallelColor and good resolution. It needs a backlight, which accounts for most of its consumption, and a fair amount of data throughput.
LED matrixSPISigns and long-distance viewing. With a dedicated driver, the microcontroller only sends the content.
E-paper (electronic ink)SPIConsumes power only when the image changes and reads perfectly in ambient light. Extremely slow refresh: suited to what changes only now and then.
Display with its own controllerserialIt brings its own processor and a ready-made interface: the microcontroller sends high-level commands and receives events. This is what is called a smart display.
TEMPERATUREsetpoint 22.0 °CTEMPERATUREsetpoint 22.0 °CEverything is redrawnOnly what changed is redrawn23.423.4Pixels written per refresh8192Pixels written per refresh1134A monochrome 128x64 display needs a 1 kB buffer and fits in any micro. A color 320x240 TFT is 150 kB:it does not fit, so you must draw by regions. In both cases the rule is the same: update only what changed.
Figure 2. Video buffer and partial refresh, animated. Redrawing the whole screen on every pass wastes time and causes flicker; updating only what changed is what makes the interface feel fast.
The calculation that decides the architecture

A monochrome 128×64 display is 8192 pixels, that is, 1 kB of buffer: it fits in the RAM of almost any microcontroller. A 320×240 TFT at 16 bits per pixel is 150 kB: it does not fit in a small micro, so you have to draw directly onto the screen, by regions, or use one with its own controller.

And data throughput matters too: refreshing that whole TFT 30 times per second takes about 36 Mbit/s. That is why smooth graphical interfaces do not redraw everything: they update only the region that changed.

04Designing the interface

What makes an equipment display good
  • The important value, large and always in the same place.
  • Units always visible. A number without a unit tells you nothing.
  • A number of decimals consistent with the instrument’s real accuracy: showing five decimals of something measured with two is lying.
  • The state of the equipment visible at a glance: running, faulted, standby.
  • Error messages say what happened and what to do, not a code that has to be looked up in a lost manual.
Details that cost dearly
  • Dancing numbers: if the last digit changes ten times per second, it cannot be read. Average it and refresh two or three times per second.
  • Menus more than two levels deep with only two buttons: nobody navigates them.
  • A permanent backlight on battery-powered equipment.
  • Tiny text on a panel that is viewed from two meters away.
  • Missing confirmations on destructive actions, such as erasing the log.
The display must not block the equipment

Writing to an LCD over I²C can take tens of milliseconds. If that is done inside the control loop, the control degrades. The solution is the usual one: the display is updated in the main loop, at its own pace, reading variables that the control keeps up to date. And never from an interrupt service routine.

05In the lab

Lab 1 · Multiplexing from scratch

Drive four seven-segment digits by multiplexing, with transistors on the commons. Vary the scan frequency from 20 Hz to 500 Hz and note the value from which the flicker disappears, by eye and by filming with a phone. Measure the average current and the peak current.

Lab 2 · Custom characters on the LCD

Define the eight custom characters of an alphanumeric LCD to display the ñ, a degree symbol and a five-step progress bar. Use them to implement a progress indicator.

Lab 3 · Partial refresh

On a graphic display, draw a complete interface and measure how long each full refresh takes. Then implement updating only the region that changed and measure again. Also compare the power consumption in both cases.

Lab 4 · Display power consumption

Measure the equipment’s current with the display off, on without backlight and with the backlight at maximum. Calculate the battery life in the three cases and propose an automatic shut-off strategy.

06Common mistakes

SymptomUsual cause
The LCD looks blank or all blackContrast not adjusted. It is almost never broken.
Strange characters appear or characters are lostThe controller’s wait times after each command are not respected.
Digits go dim when they show an 8The transistor on the common is missing: the pin cannot handle the current of all eight segments.
Visible flickerScan frequency too low. Below 60 Hz it is always visible.
The equipment becomes slow when the display is addedIt is refreshed inside the control loop, or everything is redrawn on every pass.
The last digit changes nonstopAveraging is missing, and the refresh rate has to be lowered to what the eye can read.
The OLED shows a ghost imageDegradation from leaving fixed pixels lit for a long time. It is mitigated by moving the content or turning it off.
The battery lasts very littleBacklight always on: in many devices it is the main load.

07Self-assessment

Why are seven-segment displays multiplexed?

To save pins: four multiplexed digits use twelve lines instead of twenty-eight. One is lit at a time and the fast scan makes the eye see them all.

With 6 multiplexed digits, what peak current is needed for a brightness equivalent to 8 mA?

Ipeak = 8 mA × 6 = 48 mA per segment, provided the display can take that value in pulsed operation.

What is the minimum scan frequency and why?

On the order of 60 Hz, and in practice 100 to 200 Hz is advisable. Below that, the flicker becomes visible, especially when moving your eyes.

Why is a transistor needed on the common of each digit?

Because the sum of the eight lit segments far exceeds the current that a microcontroller pin can handle.

How does an HD44780 tell a command from a character?

By the RS line: in one state it interprets the byte as a command —clear, position, configure— and in the other as data to display.

What are custom characters for?

To display what is not in the controller’s table: ñ, accented letters, unit symbols or progress bars. Up to eight can be defined.

How much RAM does the buffer of a monochrome 128×64 display take?

8192 pixels at one bit each: 1 kB. It fits comfortably in almost any microcontroller.

Why is a color 320×240 TFT not handled the same way?

Because its full buffer is about 150 kB, which does not fit in a small micro. You have to draw by regions directly onto the screen or use one with its own controller.

What advantage does e-paper have?

It consumes power only when the image changes and reads perfectly in ambient light. In exchange, the refresh is extremely slow: it suits information that changes only now and then.

Where in the program is the display updated?

In the main loop, at its own pace and reading variables that the control keeps up to date. Never inside the control loop or an interrupt service routine.

Development of the topic “Smart displays” of Digital Electronics IV (Year 7), based on the “Curriculum Proposal – Second Cycle of the Technical-Vocational Track, Secondary Education – Electronics,” Ministry of Education of the Province of Córdoba, DGETyFP. Back to the Topic Map · catto.ar