+ All Categories
Home > Documents > FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision...

FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision...

Date post: 06-Oct-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
8
Accumulate and Hold controls. Moreover, a set of analog and digital auxiliary inputs allow you to display configurable information on the screen such as center frequency, refer- ence level, scan time, and so on (see Figure 1). Lastly, an RS-232 port dumps hard copies of the screen to a host computer. As you can see in Figure 2, the XY- Plotter’s overall architecture is sim- plistic: it contains nothing more than a PIC18F252, a few MCP6022 analog amplifiers, a low-cost LCD, and sever- al other low-cost components. I built an integrated power supply using a MCP1541 precision voltage reference. LCD TIMING REQUIREMENTS I used an FTN reflective Epson ECM-A0635-2 LCD with a 240 × 320 pixel black and white screen (see Figure 3). The display is extremely dumb, and it should be supplied in real time with the required pixels. The host controller must send a new frame every 15 ms. Each frame includes 240 lines, and each line includes 320 pixels grouped into 4-bit nibbles. In addition to the 4-bit data input port, the controller must also supply three clocks: frame, line, and nibble. One new nibble must be delivered every 780 ns, which I arrived at via the following equation: 15 ms/240/(320/4). Note that for this project I used the display turned by 90° in Portrait mode 42 Issue 158 September 2003 CIRCUIT CELLAR ® www.circuitcellar.com Implementing a graphical LCD is an excellent way to drastically change the look and feel of a project. You can transition from a classic technician- oriented, two-lined text LCD to a user-friendlier device. Unfortunately, graphic LCDs are resource-hungry devices, both in terms of memory and CPU power. So, you’re forced to either create lovely minimalist designs with an intelligent LCD (with on-board LCD controller, processor, and memory, as described by Jeff Bachiochi in Circuit Cellar 150) or swap the usual microcontroller for a classic microprocessor, memory, dis- play controller set. Both options are expensive, and there doesn’t seem to be another solu- tion. For instance, the 240 × 320 pixel display used in this project eats one 4- bit nibble every 780 ns, and it needs a minimum of 10 KB of RAM just to store the displayed bitmap. Thus, it’s The XY-Plotter Robert spent nearly 100 hours building his high-performance, LCD-based XY-Plotter. Now that he has written about the process, it should take you much less time to construct your own. Follow along as he shows you how to maximize your time and money when driving graphic LCD panels. impossible to drive it directly with a high-end PIC controller providing a 100-ns cycle when clocked at 40 MHz and 1536 bytes of RAM, right? Nothing useful can be done in less than seven assembly instructions per nibble, correct? As you probably expect, this project proves that the impossible is possible with an optimized firmware design. You’ll even learn that it’s possible to use this minimalist concept for some- thing useful! PLOTTER BASICS I got the idea for the XY-Plotter from an old spectrum analyzer sleeping in my garage. Despite the fact that the heavy analyzer’s CRT display was dead, the radio parts worked well. So, from time to time, I used it with an oscillo- scope as an output device. The arrange- ment was cumbersome and uncomfort- able to implement. Consequently, I decided to repackage the analyzer in a smaller, prettier enclosure and design an LCD alternative to the CRT dis- play. Because I wanted the ability to reuse the design, I chose to develop a generic display subsystem, the XY- Plotter (see Photo 1). The XY-Plotter is an autonomous analog-like display with two main x and y inputs. Continuously scanning the two inputs, the plotter displays them on a real-time x-y graph by way of configurable modes (i.e., Sample, Maximum, Peaks, or Average) with FEATURE ARTICLE by Robert Lacoste CONTEST WINNER Drive High-Resolution LCDs For Less Photo 1—The large 240 × 320 LCD is affixed to the PCB. The three control push buttons and the screen dump RS-232 connector are along the bottom edge. Circuit Cellar, the Magazine for Computer Applications. Reprinted by permission. For subscription information, call (860) 875-2199, or www.circuitcellar.com. Entire contents copyright ©2001 Circuit Cellar Inc. All rights reserved.
Transcript
Page 1: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

Accumulate and Hold controls.Moreover, a set of analog and digitalauxiliary inputs allow you to displayconfigurable information on thescreen such as center frequency, refer-ence level, scan time, and so on (seeFigure 1). Lastly, an RS-232 portdumps hard copies of the screen to ahost computer.

As you can see in Figure 2, the XY-Plotter’s overall architecture is sim-plistic: it contains nothing more thana PIC18F252, a few MCP6022 analogamplifiers, a low-cost LCD, and sever-al other low-cost components. I builtan integrated power supply using aMCP1541 precision voltage reference.

LCD TIMING REQUIREMENTSI used an FTN reflective Epson

ECM-A0635-2 LCD with a 240 ×320 pixel black and white screen (seeFigure 3). The display is extremelydumb, and it should be supplied inreal time with the required pixels.The host controller must send a newframe every 15 ms. Each frameincludes 240 lines, and each lineincludes 320 pixels grouped into 4-bitnibbles.

In addition to the 4-bit data inputport, the controller must also supplythree clocks: frame, line, and nibble.One new nibble must be deliveredevery 780 ns, which I arrived at via thefollowing equation: 15 ms/240/(320/4).Note that for this project I used thedisplay turned by 90° in Portrait mode

42 Issue 158 September 2003 CIRCUIT CELLAR® www.circuitcellar.com

Implementing a graphical LCD is anexcellent way to drastically changethe look and feel of a project. You cantransition from a classic technician-oriented, two-lined text LCD to auser-friendlier device. Unfortunately,graphic LCDs are resource-hungrydevices, both in terms of memory andCPU power. So, you’re forced toeither create lovely minimalistdesigns with an intelligent LCD (withon-board LCD controller, processor,and memory, as described by JeffBachiochi in Circuit Cellar 150) orswap the usual microcontroller for aclassic microprocessor, memory, dis-play controller set.

Both options are expensive, andthere doesn’t seem to be another solu-tion. For instance, the 240 × 320 pixeldisplay used in this project eats one 4-bit nibble every 780 ns, and it needs aminimum of 10 KB of RAM just tostore the displayed bitmap. Thus, it’s

The XY-Plotter

Robert spent nearly 100 hours building his high-performance, LCD-based XY-Plotter. Nowthat he has written about the process, it should take you much less time to construct yourown. Follow along as he shows you how to maximize your time and money when drivinggraphic LCD panels.

impossible to drive it directly with ahigh-end PIC controller providing a100-ns cycle when clocked at 40 MHzand 1536 bytes of RAM, right?Nothing useful can be done in lessthan seven assembly instructions pernibble, correct?

As you probably expect, this projectproves that the impossible is possiblewith an optimized firmware design.You’ll even learn that it’s possible touse this minimalist concept for some-thing useful!

PLOTTER BASICSI got the idea for the XY-Plotter from

an old spectrum analyzer sleeping inmy garage. Despite the fact that theheavy analyzer’s CRT display was dead,the radio parts worked well. So, fromtime to time, I used it with an oscillo-scope as an output device. The arrange-ment was cumbersome and uncomfort-able to implement. Consequently, Idecided to repackage the analyzer in asmaller, prettier enclosure and designan LCD alternative to the CRT dis-play. Because I wanted the ability toreuse the design, I chose to develop ageneric display subsystem, the XY-Plotter (see Photo 1).

The XY-Plotter is an autonomousanalog-like display with two main xand y inputs. Continuously scanningthe two inputs, the plotter displaysthem on a real-time x-y graph by wayof configurable modes (i.e., Sample,Maximum, Peaks, or Average) with

FEATURE ARTICLE by Robert Lacoste

CONTEST WINNER

Drive High-Resolution LCDs For Less

Photo 1—The large 240 × 320 LCD is affixed to thePCB. The three control push buttons and the screendump RS-232 connector are along the bottom edge.

Circuit Cellar, the Magazine for Computer Applications. Reprintedby permission. For subscription information, call (860) 875-2199, orwww.circuitcellar.com. Entire contents copyright ©2001 CircuitCellar Inc. All rights reserved.

Page 2: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

www.circuitcellar.com CIRCUIT CELLAR® Issue 158 September 2003 43

PIC or multiplexed with LCD datalines (thanks to a firmware reconfigu-ration on the fly).

Lastly, the ubiquitous MAX232 doeswhat it’s intended to do. It should benoted that I included an in-circuit pro-gramming header just in case; howev-er, I haven’t had to use it thanks toMicrochip’s boot loader firmware. Allof the programming was accomplishedthough the serial port.

POWER SUPPLIESThe power supply is a significant

part of the design (see Figure 5). First, Ineeded a clean 5 V. I was alreadyusing all of the PIC’s analog inputs,so I couldn’t configure its ADC inexternal-reference mode. I still need-ed a stable reference for the analog-to-digital conversions. After experi-encing a few headaches, I decided touse the PIC in its 0- to 5-V referencemode and to provide a well-stabilized5 V. I implemented a high-precisionMCP1541 voltage reference and builta discrete power supply around alow-drift LMC6462 op-amp. The sec-ond part of the op-amp is used to getthe 0.6-V reference drawn on by theoffset circuitry.

The LCD was hard to deal withbecause it needed both a –24-VDCinput (for the display itself) and a 100-VAC power for the EL backlight. Tolimit the number of power inputs, Iwent with a small 5- to ±12-VDC con-

rail-to-rail op-amp. Two 20-turn trim-mers per input give you the ability toeasily adjust the full-scale deviation aswell as the DC offset for each channel.One of the channels, AUX2, evenincludes two inputs summed by theanalog amplifier.

The values of the resistors used foreach amplifier stage can be adjustedfor each specific application to accom-modate different input ranges andadjustment precision. It is not obvioushow to design an amplifier stage withpositive and negative offset adjust-ment without a negativepower supply. Here’s mytrick: A fixed positive volt-age, which is derived from a0.6-V reference, is first sub-tracted from the input signal,and then a variable positivevoltage is added to it, provid-ing an offset that’s either pos-itive or negative. I used Excelto calculate the resistors.

The PIC is clocked by a 10-MHz crystal up-converted to40 MHz thanks to the on-board PLL. The LCD isdirectly connected to the PICI/O lines, whereas the auxil-iary digital inputs, which areused to dynamically selectthe text for the screen, areeither direct inputs of the

(320 pixels high, 240 wide), so thescan lines are vertical.

MICRO OF CHOICEI chose the PIC18F252 microcon-

troller on the basis of certain project-specific criteria. First, I needed speed.The more instructions in these bloody780-ns nibbles the better. I also want-ed a significant amount of RAM. I did-n’t store the full bitmap but choseinstead to store minimum, maximum,and sample values for each columnalready requiring 768 bytes. In addi-tion, I needed a precision A/D con-verter and a large program memory foramassing the huge tables used in thedesign (including character bitmaps).Lastly, flash memory was necessaryfor configuring the display for eachapplication.

One or two years ago, these require-ments probably would have beenimpossible to fulfill, but, thanks to sup-pliers like Microchip, they are now eas-ily satisfied, with the PIC18Fxx2 prod-uct line in particular. The PIC18F252,for instance, has 1.5 KB of RAM andplenty of flash memory (32 KB).

GRASPING THE SCHEMATICS Figures 4 and 5 are schematics of

the XY-Plotter. Each analog input (X,Y, AUX1, and AUX2) is conditionedthanks to half of an MCP6022 dual

X

Y

AUX1

AUX2

2×MCP6022

DA1

DA2

DA3

DA4

PIC18F252

MAX232

240 × 320 LCD

Display mode

Accumulate

Hold

Figure 2—The XY-Plotter’s hardware design is simple. ThePIC18F252 manages everything including LCD pixel generation inreal time. A couple of Microchip MCP6022 rail-to-rail op-amps wereused to scale the analog inputs.

F R E Q = 1 2 3 4 M H Z R E F = – 9 6 D B M

S C A N 2 0 0 K / D V E R = 1 0 D B /

R E S L = 1 K H Z P E A C C L T

T D

K A F H D

One of 16fixed text strings,

depending on digital inputs

DA1[0..3]

One of eightfixed text strings,

depending on digital inputs

DA2[0..2]

Current displaymode indicator

(Sample, Maximum, Peaks, or Mean)

Immediate value ofanalog input AUX1

Immediate value of analog input AUX2

One of two fixed text strings, depending on digital input DA3

One of two fixed text

strings,depending on

digital input DA4

Accumulate mode indicator

Hold mode indicator

Figure 1—The XY-Plotter screen displays a real-time x-y graph as well as three lines of configurable textual statusinformation and real-time measurements.

Page 3: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

44 Issue 158 September 2003 CIRCUIT CELLAR® www.circuitcellar.com

the overall architecture. In order tocomply with the requirement of seveninstructions per nibble, I didn’t use an

verter to generate the –24 V switchedby two transistors under PIC control. Icouldn’t find a ready-made DC/ACconverter for the backlight in time,but it wasn’t an issue. I built a prettyone with a small 220/12-V transformerdriven by a NE555 timer. Done.

PROTOTYPE ASSEMBLYI built a simple PCB for this project

(see Photo 2). All the components fiteasily because I wanted the size of thePCB to be identical to the LCD. Notethat the front panel components,including the push buttons and RS-232 connector, are soldered on the bot-tom. All of the trimmers are easilyaccessible with a screwdriver, becausethey are laterally shifted from one tothe other.

FIRMWARE DESIGNThe hardware side of this project

was straightforward, so if you’re imag-ing that the firmware was more diffi-cult, you’re right. Figure 6 illustrates

interrupt. I built a fully sequentialprogram flow.

A main loop is executed every

Figure 4—The XY-Plotter’s power supply isn’t included in this schematic. An MCP6022 analog amplifier, with scale and offset controls, scales each analog input. Some of themicrocontroller’s I/O lines are multiplexed to limit the I/O count requirement.

Y Dr

number 1

Di

Do80

Y Dr

number 2

Di

Do

80

Y Dr

number 3

Di

Do

80

LCD pannel240 × 320

AC pulse generator

X Dr

EI EO

Number 1

X Dr

EI EO

Number 2

X Dr

EI EO

Number 3

X Dr

EI EO

Number 4

Contrast circuit

(FR)

80 80 80 80

VLCD (V0) LP XSCL D0~D3*DISP OFF DIN VDD VSS VEE

Figure 3—The EPSON ECM-A0635-2 display doesn’t include anything more than lines, columns, registers, anddrivers. The host controller must send pixels with strict timing requirements and supply frame, as well as line andpixel clock signals.

Page 4: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

www.circuitcellar.com CIRCUIT CELLAR®Issue 158 September 2003 45

15.8 ms. It starts with aframe-batch routine thatmanages the push buttons,and more importantly readsthe auxiliary inputs (analogand digital) and generates thetext that will be displayed inthe first lines. The text isstored as ASCII characters inRAM using 90 bytes (3 × 30).

If you want to study thebinary-to-decimal conversionroutine, which I found onthe ’Net, refer to theResources section at the endof this article. The frame-batch routine also managesthe UART by way of a sim-ple protocol. Then a loop isexecuted for each of the 240columns in the display. Ateach iteration, a line-batchroutine is first executed.This routine reads and man-ages the x and y analog values (storingy minimum, maximum, and samplevalues for each x value in three 256-byte RAM areas). The display blank-ing (i.e., y is not stored when x isreducing) is also managed.

The last step is tricky. For each line,the firmware must generate the nibblesto send the LCD on the fly. It mustfirst send the nibbles corresponding tothe graphic area (the back of the screendepicted in Figure 1) and then theones for the three text lines at the top.Now let’s discuss the details.

GRAPHIC DISPLAYHow can you generate the graphic

display on the fly? The fixed parts(e.g., borders and scales) are easily sentto the LCD with the proper timing.The graph is built in real time fromthe minimum, maximum, and samplevalues. It also depends on the displaymode (see Figure 7).

The LCD is used in Vertical mode(320 pixels high), so the scan is verti-cal, too. Thus, the successive nibblessent to the LCD correspond to succes-sive vertical blocks of four pixels. In

order to generate them, anoptimized algorithm isimplemented based onanother trick: For each col-umn, there is only oneblack line surrounded bywhites. First, the blackline’s two extremities(ystart and ystop) are cal-culated based on the oper-ating mode. Then, a loopsends an optimal numberof fully blank nibbles fol-lowed by (depending onthe ystart and ystop val-ues) precalculated bitmapsthat correspond to the dif-ferent situation and arestored in a precalculatedtable as well as full black

or full white nibbles in good quantity.For reasons of efficiency, the flashmemory-based table is cached at start-up in a RAM page. Figure 8 providesvisual description of the algorithm.

TEXT DISPLAYThe three text lines are also gener-

ated on the fly based on the ASCIIcharacters that are stored in RAM. Forthis purpose, a specific characterbitmap was precalculated and storedin flash memory. The table gives thesuccessive nibbles to send to the dis-

Figure 5—The power supply includes four independent subsystems, one of which is the main 5-V regulator, which I built using ahigh-precision Microchip MCP1541 reference. I used a 5- to –24-V converter for the LCD. A homemade converter supplies thebacklight voltage (100-V AC). Lastly, note that a 0.6-V reference is provided for offset control.

YMAX

YSAMP

YMINInput y signalfor the same

value of xSample Maximum Mean Peak

Display mode

Figure 7—Four display modes are supported by theXY-Plotter. Sample mode simply plots the first y valueacquired for each x value. The Maximum mode plotsthe highest y for a given x. The Mean mode isn’t in facta true mean; it simply displays the midpoint of the mini-mum and maximum values. Last but not least is Peakmode, which displays a line showing all of the y valuesmeasured for a given x.

Initializations

Main loop

Execute frame batch (one time each 10 frames) Read push buttons, manage Display mode Read auxiliary inputs, update textual display in RAM Manage UART

Lines loop (executed 240 times)

Execute line batch Sequentially read x and y through ADC Store measurements, calculate min/max, manage blanking

Display graphic area (284 pixels, 71 nibbles to send) Generate drawing on the fly based on Display mode (peak, etc.)

Display text area (3 × 12 pixels, nine nibbles to send) Generate bitmap on the fly based on ASCII characters in RAM

Ove

rall

refr

esh

perio

d 15

.8 m

s

3 to

8 µ

s25

to 3

0 µs

12 to

28

µs

240

× 6

5 µs

200

µs

Figure 6—The most critical section of this chart, which shows the archi-tecture and timing of the firmware, is the graphic display routine.Basically, 71 nibbles must be sent in 30 µs, giving 422 ns per nibble orfour PIC instructions per nibble (even at 40 MHz).

Page 5: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

46 Issue 158 September 2003 CIRCUIT CELLAR® www.circuitcellar.com

play for each character (from back totop and from left to right). Each char-acter is encoded in an 8 × 12 pixelbitmap, giving 30 (240/8) charactersper line.

A significant overhead is needed atthe start of each character (first scanline out of the eight) in order to pre-calculate the different pointers. I builtthis unusual character bitmap table inExcel, starting with a standard 8 × 12bitmap I found on the Internet.

LINE-BATCH ROUTINEThe line-batch routine manages

the acquisition of the x and y analogvalues as well as the storage of theminimum, maximum, and samplevalues in RAM. I built the routine asa five-stage step machine (see Figure9). Each step corresponds to a differ-ent acquisition sequence.

You can’t lose time with thisarchitecture. A full pair of x and yvalues is acquired every 260 µs (4 ×65µs), which produces a satisfactory3.8-kHz update rate. Depending onthe scan rate you apply (i.e., the fre-quency of the saw-tooth applied onthe x input), two modes are auto-

matically executed. If the scan rateis lower than 15 Hz (3.8 kHz/256) orthe scan time is higher than 7 msper division (1/15 × 10) using theusual scope vocabulary, then morethan one y value is acquired for eachx value per scan, enabling function-ality such as minimum, maximum,and peaks.

If the scan speed is higher (up to

500 Hz), an equivalent time-sampleddisplay is generated, and minimum,maximum, and peak measurementsare only available in Accumulatemode (i.e., no resetting of the mini-mum and maximum between scans).

OPTIMIZATION TIPSOptimizing the firmware’s cycle

count requires a huge effort. Forinstance, one of its basic tasks is tosend N pulses to the LCD’s nibbleclock input. A loop already needsfive cycles to do this, but rememberthat you have time for less thanseven instructions per nibble, andthe firmware has more to do thansimply send clock pulses! So, you’llneed additional optimization tech-niques like code expansion and thecalculated goto procedure (seeListing 1).

I used the calculated goto tech-nique extensively. Basically, I wasmanually unrolling the code like anoptimized compiler does (or tries todo). For instance, I used a long calcu-lated goto table to select the specificline-generation algorithm for each col-umn in the display (e.g., graduations,plain line, ordinary curve column,etc.). The result is a strange assemblylisting to read but an interesting oneto write!

Another tip is to copy, at startup,the combined pixel table from flashmemory and paste it in RAM. An indi-rect access to RAM is quicker than a

table read from flash memory.

MEMORY REQUIREMENTSThe aforementioned firmware

optimizations are memory hungry.Fortunately, with 32 KB of flashmemory it’s not an issue. Myfirmware currently uses only 10 KB.

I used the PIC18F252’s entireRAM. Three pages at 256 bytes eachwere used to store the respectiveminimum, maximum, and sampledy value for each x value. One pagewas devoted to the storage of theASCII text, although only 90 byteswere actually needed. One last 256-byte page was used to store thebitmap patterns. That left 256 bytesfor general-purpose variables. All inall, that’s 1536 bytes.

Start = 10/Stop = 22

Finish the screen with full whites

Send one combined three black/one white nibble

Send two full black nibbles

Send one combined two white/two black nibble

Send two full white nibbles

Finish the screen with full whites

Send one double-combined one white/two black/one white

Send three full white nibbles

Send one combined two white/two black nibble

Start = 13/Stop = 14S

can

dire

ctio

n

Sca

n di

rect

ion

Figure 8—The 4-bit nibbles are generated in real time for each of the LCD’s scan lines based on the position of thefirst and last black pixel on that column. The firmware first calculates how many 0000s must be sent, and then twothings can happen: If all the black pixels to draw are in the same nibble, then a combined white/black/white nibbleis extracted from a table and sent to the display (on the right). Otherwise, one white/black transition nibble is sent,followed by the required number of full black nibbles, and followed by one black/white transition nibble (on the left).

Initial

0

1

2

3

4

Configure ADC for channel x

Read y from ADCStore y in array, indexed by last x read Configure ADC for channel x

Launch A/D conversion for channel x

Read x from ADCIf > than previous x, reset Min/Max (x)If < than previous x, then blanking modeIf not blanking mode, configure ADC forchannel y

Launch A/D conversion for channel y

Bla

nkin

gN

ot b

lank

ing

Figure 9—The acquisition of the x and y analog values ismanaged thanks to a five-state machine executed each timethe line-batch routine is called (each 65 µs). This allows youto comply with the PIC ADC timing (precharge, conversion,and then read) without losing any time.

Page 6: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

48 Issue 158 September 2003 CIRCUIT CELLAR® www.circuitcellar.com

DEVELOPMENT PROCESSThe project was developed with the

MPLAB environment and simulator. Ialso used Microchip’s boot loaderfirmware (AN851) to burn flash mem-ory, which is an interesting featureeven if firmware improvements arewelcome. In particular, no on-chipdebug facility is currently provided(e.g., breakpoints), but I’m sure they’llbe in the next version.

Also note that the AN851 bootloader doesn’t provide an automaticreentry facility. As soon as an applica-tion firmware is downloaded and acti-vated, there’s no way to reactivate thebootloader without specific user-sup-plied application code (like simultane-ously pressing the three keys atpower-up). This is well documented inthe literature but more secure solu-tions exist (e.g., timeout).

I wasn’t lucky enough to have afull-featured ICE for the processor, so Iwanted to avoid hundreds of burn andtest cycles. I started by developing thecritical code (e.g., the pixel generationalgorithm) on a PC in C—just to vali-

date the algorithm itself. Then, Ideveloped the full firmware withMPLAB, keeping a structuredapproach to facilitate the validation.

Later, I implemented a bottom-upapproach. I simulated 100% of thesoftware with small stub routines inan effort to execute each routine indi-vidually. Note that I was still using

MPLAB and didn’t have a target sys-tem at that point. I even kept a sourcelisting and ticked all of the assemblylines to be sure to go across each ofthem.

I used the MPLAB stopwatch to ver-ify the timings. When everythingseemed fine under the simulationframework, I went to the targetprocessor. That approach proved suc-cessful. My first burned firmware wasnot free from bugs, but I got a work-ing display with the first burned file!

The RS-232 helped a great deal dur-ing the final debugging steps. In fact,rather than having to develop a specif-ic protocol for each project, I used aneasy and powerful method.

First, the UART firmware dumpsthe RAM’s content on the RS-232 portper the host’s request. Following this,software on the PC side is able to grabinteresting information based on theRAM content (e.g., rebuilding some-thing like a screen hard copy). But themost interesting point is that thesame feature is invaluable during thedebugging steps!

Photo 2—The analog front end is on the upper left withits nine trimmers, the power supplies are on the topright, and the PIC is in the middle. The PCB has plentyof empty space because the LCD’s dimensions dictat-ed its size.

Page 7: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

PROBLEMS SOLVEDStrangely, my firmware generated a

serious problem: some of the LCD’scolumns were darker than others, andit was dependent on the operatingmode and input signals. It took meseveral nights of thinking before Irealized that this was because of theslightly different CPU time spentbetween columns. Because the LCD isdumb, its buffers had stayed openlonger on the columns, and they gavea darker display.

As always, when you can clearlydefine a problem, the solution tendsto be straightforward. For this particu-lar problem, I simply configured oneof the on-board timers and waiteduntil precisely 65 µs had been spenton each column. Problem solved.

IMPROVEMENTS TO COMEThe fully operational XY-Plotter

prototype demonstrates that the con-cept actually works. The screen isrefreshed 70 times per second anddoesn’t flicker. The A/D management,graph generation, and textual display

50 Issue 158 September 2003 CIRCUIT CELLAR® www.circuitcellar.com

Listing 1—I used this coding technique to meet the strict timing requirements of the project. The routinesends a configurable number of pulses to the LCD clock input with less than three PIC instructions per pulseon average! Try to do it with a classic loop.

;Send W pulses to the XSCK line (W = 0 to 60). Execution duration: 100;ns × (2xW + 20) for W < 60. Average with W = 20 (worst case) giving;three instructions/pulse (300 ns).**************************************************************************send_upto60_pulses ;Limited to 60 because of page boundaryinput in tmp_send_w_pulses

movf tmp_send_w_pulses,Wsublw .60 ;Calculate 2 × (60 � w)rlncf WREGrlncf WREGmovwf tmp_send_w_pulsesgoto pulsesaligned

pulsesnotalignedorg (1 + high pulsesnotaligned)*.256

;Must start on a page boundarypulsesaligned

movlw high pulsesalignedmovwf PCLATH ;High byte of new PC should be defined

movf tmp_send_w_pulses,Waddwf PCL,F ;Jump to next instruction if W = 0 (60 pulses)bsf PORTB,RB_LCDXSCL_BIT ;pulse 60bcf PORTB,RB_LCDXSCL_BITbsf PORTB,RB_LCDXSCL_BIT ;pulse 59bcf PORTB,RB_LCDXSCL_BITbsf PORTB,RB_LCDXSCL_BIT ;pulse 58bcf PORTB,RB_LCDXSCL_BIT

;etc�bsf PORTB,RB_LCDXSCL_BIT ;pulse 02bcf PORTB,RB_LCDXSCL_BITbsf PORTB,RB_LCDXSCL_BIT ;pulse 01bcf PORTB,RB_LCDXSCL_BITretlw 0 ;Must be in the same page as the first one

Page 8: FEATURE ARTICLE by Robert Lacoste The XY-Plotter€¦ · 5 V. I implemented a high-precision MCP1541 voltage reference and built a discrete power supply around a low-drift LMC6462

www.circuitcellar.com CIRCUIT CELLAR® Issue 158 September 2003 51

SOURCESECM-A0635-2 LCDEpson Europe Electronics

are perfect in every mode. It took me roughly 100 h to com-

plete this project. I still have a coupleof bugs to correct but nothing toocritical. A few more nights of work,and the plotter will be embedded inmy new spectrum analyzer.

This project clearly demonstratedthe power of low-cost microcon-trollers. In addition, it proved thatefficient debugging requires a goodsimulator. I also learned that LCDbacklight high-voltage generators areharmful, but that’s another story.

I have a long list of future improve-ments, one of which is PC-based con-figuration software to customize thedisplay for new applications (e.g.,modification of the textual informa-tion). That will be easy thanks to theflash memory-based PIC I used.

Developing this useful project wasextremely fun. I hope reading about itwas fun too! I

Robert Lacoste lives near Paris,France. He has 15 years of experienceworking on innovative real-time soft-ware and embedded systems.Specialized in cost-optimized mixed-signal designs, he has won over adozen international design contests.Robert currently manages his owndesign and consulting company. Youcan reach him at [email protected] www.alciom.com.

PROJECT FILESTo download the code, go toftp.circuitcellar.com/pub/Circuit_Cellar/2003/158.

RESOURCES8 × 12 Character set, www.sxlist.com/techref/datafile/charset/8x12.htm.

Epsom A0635-2 LCD Preliminaryspecification, www.supelec-rennes.fr/ren/fi/elec/ftp/lcd/a0635.pdf.

R. Fosler and R. Richey, A FLASHBootloader for PIC16 and PIC18Devices, AN851, MicrochipTechnology, Inc., 2002.

D. Jones, “Binary to Decimal Conver-

sion in Limited Precision,” TheUniversity of Iowa, www.cs.uiowa.edu/~jones/bcd/decimal.html, 1999.

Microchip Technology, Inc.,PIC18FXX2 Data Sheet: HighPerformance, Enhanced FLASHMicrocontrollers with 10-Bit A/D,DS39564B, 2002.

+49 89 14005-0www.epson-electronics.de

MCP1541 Voltage reference,MCP6022 analog amplifier,PIC18F252 microcontrollerMicrochip Technology, Inc.(480) 786-7200www.microchip.com

LMC6462 Op-ampNational Semiconductor Corp.(800) 272-9959www.national.com


Recommended