- Published: Thursday, 26 July 2012
- Written by Jon Chandler
- Hits: 5940
Powering up my new sous vide controller board required to troubleshooting to find an easily fixed problem. Some indications were misunderstood, resulting in some confusion. I'm sharing this systematic troubleshooting process to help you analyze problems.
The Board Design
The board is based around a 28-pin 18F-series micro and a TI TMP513 chip configured to read a thermocouple. The board has a 16x1 connector for a HD77480 character LCD, two inputs for switches and an output to control an SSR (solid state relay). In keeping with the TAP-28 convention, there are 6 pin connectors for I2C (the TMP-513 uses the I2C interface) and UART communications. The board was designed with general applications in mind, so there are also locations for an I2C EEPROM, a Microchip RTC and a MCP-23017 port expander chip.
Because of the number of port pins needed, the LCD data lines share the ICSP clock and data lines.
ICSP (in-circuit serial programming) uses two port pins for loading/reading the micro in-circuit. The clock and data pins must be free to change level under programmer control. With a few precautions, these two port pins can be used in the circuit without problems. As long as there is not too much capacitive loading on a pin and it's free to be driven high or low, no conflicts will result. These two pins cannot be tied to output pins of a chip that powers on high or low; if the chip is tri-state until commanded to do otherwise, no problems will result from sharing these lines.
An HD44780 uses a parallel interface of 4 or 8 bits plus 2 or 3 control lines. The data lines are usually inputs to the LCD and can be shared for other purposes without problem. The three control lines of the interface are:
- E - Data is read into (or out of) the LCD when this line is strobed
- RS - This line tells the LCD if the data on the input lines is a command or a character to be displayed.
- R/W - This is the read/write line for the LCD. Data is usually written to the LCD but it is possible to read data from the LCD. The read mode is not often used, in which case, the R/W pin must be tied to ground.
The LCD will also require power and ground of course (don't forget the 0.1 μF bypass cap) and an adjustable voltage to the Ve pin to control contrast. This connection is not an option; if the contrast is not properly set, nothing will be visible on the LCD.
Two additional pins are associated with the LCD interface, usually for an LED backlight. Verify these pins, including there location with respect to the 14 pins of the interface on the LCD connector. An LED backlight may or may not include a current limiting resistor on the LCD board. Verify this with the data sheet or by measuring backlight current draw.
The table to the right shows connections to an HD77480 character LCD. The connections highlighted in blue are optional - if not used, follow the instructions in the notes column. The connections highlighted in green depend on the LCD in use and may not be exactly as shown.
Powering Up the Board
I assembled the board, plugged in the LCD and tried to load my existing LCD code. The immediate response from the PICkit 2 programmer was "Device Not Detected." I checked that the chip was properly inserted in the socket in the correct orientation. No problem there. I took a quick look at the schematic and board files. Nothing was amiss. Part of the schematic and board showing the LCD connections are shown below. Ignore the red lines on the schematic. The bottom layer of the circuit board is a ground plane. Connections to the ground plane are not shown in this view.
I unplugged the LCD and tried again. The micro was properly detected and the code loaded. Hmmm. ICSP and the LCD should get along but I can unplug it for programming. Kind of a pain in the backside but not a huge problem.
This was the fist clue missed. If something should work and it doesn't, determining why is a good idea.
Ok, the code was loaded and the LCD connected. Crank...crank...crank...eventually I got the contrast pot to the correct position and a visible display showing two lines of solid blocks instead of the text I expected.
The existing code was written for a 16x2 display and I'm using a 20x4 display with this board. I don't recall any specific settings for the number of lines in the display but I checked the Swordfish LCD module just to be certain that I hadn't forgotten a needed setting. As expected, there's no setting needed, so this wasn't the source of the problem.
The next step was to look at the schematic. I'm using a 4-bit interface connected to the upper nybble of Port B for the data lines. The software was properly configured for this port. The control lines E, RS and R/W go to variaous port pins and the connections specified in my software correspond to the schematic.
At this point, I swapped displays since there was an identical one of the top of my desk. Same result.
I usually don't use the R/W line but I did in this case. Just to be sure, I manually configured the R/W pin to be an output and set it low just in case the Swordfish module doesn't handle this correctly (if specified, the module uses it, if not, the module ignores it). No change in the display.
Next, I checked the board file. Data pins to the right locations. E to the correct port pin (sometimes I swap around the control lines during board layout for easier routing). RS to the connect port pin. R/W...damn. At the last minute, I decided to re-purpose the port pin going to the R/W pin to be a One-Wire interface. I never use any features of the LCD requiring reading data from the display anyway, so this was a reasonable decision. This change is shown in red in the schematic above (but I failed to update the schematic to show this).
If the R/W pin is grounded, the data lines to the LCD are inputs. If the R/W pin is high, the LCD data lines are outputs. Looking at the board file, I saw that I forgot to ground the R/W pin after I re-purposed the port pin connected to it. The back of the board is shown below, mirrored to align with the image of the top side above. The arrows indicate connections made to the ground plane using thermal isolation to permit soldering. Note that pin 5 (R/W) of the LCD connector is not connected to ground. Grrrrrrr.
A jumper from pin 5 to a nearby ground point and I was in business. The display looked exactly as expected. A simple fix.
Remember the ICSP connection that failed? Because the R/W line wasn't grounded, those data lines became outputs driven high or low. The PICkit couldn't control the levels to write and read from the micro. Once the R/W line was grounded, the LCD and ICSP worked together perfectly. The clue to the LCD problem was present at the start. If I had taken the time to understand why the ICSP lines in parallel with the LCD data lines had failed, I would have found the R/W problem sooner. Not much time was lost in this case but other times ignoring things that doesn't make sense has cost me many hours of effort.
Common ICSP Errors
No device detected - The ICSP clock and data lines may be incorrectly connected, not connected or loaded such that the level cannot change.
Can't Control Vpp - The voltage level on the /MCLR pin is brought up to about 12 volts to make the micro enter programming mode. If /MCLR is connected to ground, say by a mis-wired reset switch (a recent error for me), the programmer won't be able to elevate the voltage level. Check connections.
Excess Current Draw - The PICkit 2 has strong self-preservation instincts. If too much current is drawn (> 100 mA), the output will be shut down. If this occurs, the PICkit 2 must be reset. Disconnect the PICkit 2 from USB and close the GUI software to reset the PICkit 2. Reconnect the PICkit and re-start the GUI.