16F877A devBoard

Laen’s PCB Order comes through again with some nice quality boards for a recent design.  I wanted to try soldering a few TQFP microcontrollers in a toaster oven, and ended up using a 16F877A.  Using the 16F877A allowed enough pins to connect quite a few devices together.   Since you get three copies of any PCB that you order, I decided to try and use one for building a scoring controller for an airhockey table.

My basic requirements for the board were:

  • ICSP port
  • LCD character display
  • 7-segment display using a MAX7219 driver IC
  • Thermocouple support using a MAX6675 sensor IC
  • Piezo speaker
  • 2 onboard buttons for input
  • 4 onboard LED’s
  • RS232 I/O via software -> PICBASIC
  • Unused pins brought out to header pins

I then went to work using eagleCAD for the schematic and board layout.  After many changes I finally settled on a design.

The design was then sent off to Laens PCB order for fabrication.  A few weeks later the boards arrived and I began to assemble them. I decided to assemble just one in the beginning to see if they were even going to work.

Here was the build log:

PIC16F877A TQFP Development Board ver.1 Log

****************WARNING****************
ver1 of the development board has a few traces that were not fully routed during design.

Pins E.0 and E.2 need to be connected via jumpers.

The LCD_AnyPin.pbp must be used to allow different pins for the LCD.

The MAX6675 silkscreen is upside down, turn the IC 180 before placement.

The silkscreen by the speaker shows D.6 while it is actually D.7.

The Thermocouple I have is WHT=+, RED=-
*******************************************

4/2/2012:
After soldering the minimum required components, my first attempt at programming via ICSP did not work. The ICSP connector must be placed a certain way; see completed board. Finaly I was able to successfully program the 16F877A via the ICSP, although a program to flash the LED failed.

4/12/2012:
A simple PICBASIC program to flash the LED connected to E.0 initally would not work. I tried various settings of the fuses but nothing seemed to work. While looking over the board layout trying to figure out the problem, I noticed two traces form the onboard LEDs were not fully connected to the PIC! I dont know how this slipped through, but was an easy fix with some small gauge jumper wire. I then decided to remove the 33pF capacitors on the 20mHZ crystal and replace them with 22pF. I also changed the 47uF capacitor on the 7805 with 10uF. After reprogramming the 16F877A again, the green LED began to blink! Now I was finally starting to think the board wasn’t a complete bust. I soldered on the final components and decided to wait until tomorrow to try it.

4/13/2012:
I did not want to start the board without configuring the 16F877A to use the various I/O’s first. My initial test of the MAX7219 did not work. I also noticed the MAX6675 was now becoming very hot. I removed the MAX6675 until I have more time to look at it in detail. Initial thoughts are wrong routing of signals. I finally got the MAX7219 to work. After moving the code over from the PID program I noticed there is a subroutine “Transfer” that directly calls the PORTS instead of using a variable. Once both were changed to their corresponding ports the 7segment display jumped to life! The MAX6675 still wasn’t working properly.

4/15/2012:
I finally figured out the cause of the overheating MAX6675. The artwork that was silkscreened on the PCB has the chip orientation wrong. Once I noticed this I de-soldered the old chip and placed a new one using  the reversed orientation. This fixed the MAX6675 and now works perfectly. After using the LCD_AnyPin.pbp from Darrel Taylor, I then was able to set the individual pins for the LCD bypassing PICBASICs restrictive settings. So up to this point it seems everything is working that I have tested. I need to check out the RS232 connection and the onboard speaker.

4/16/2012:
The onboard speaker works after noticing the silkscreen is incorrect by displaying port D.6 while it is actually D.7.

4/21/2012:
Everything seems to be funtioning on the second board I built. I used SMD LED’s instead of thru-hole. The SMDs I had can be soldered nicely between the pads for the thru-hole versions. The finished board looks much nicer than when using the SMD LED’s. While building the second board I had trouble getting it to reliably start. It seemed intermitent at best with no reason. Later I narrowed it down to either the crystal or the trim capacitors near it. Once the trim capactitors were removed The board seemed to work perfectly. I read something a while back that mentioned the capactince? of the entire board can allow use of no trim capacitors. Whats weird is the first prototype has the capactitors and works fine.

Here are some images of the assembly process:

PCB just after coming out of the oven

After installing basic components to allow use of the ICSP

Completed development board with LCD removed

Picture of the bottom side showing the wire jumper fix

Completed board w/LCD attached running a demo

Running a test of the MAX7219 7segment driver

Using PICBASIC, I created a demo for the board testing various features including the LEDs, speaker, thermocouple, and the 7segment display. Ill post the code in another post.  Right now I am trying to implement a simple menu system for selecting various tests.

Final thoughts on the project:  I was impressed the board had only a few mistakes that were fixable; especially for not testing the design first via simulation or using a breadboard.

Fume extractor for soldering….

  After making more pcb’s to solder, I finally decided it was time to build a fume extractor.  With all the spare parts I have laying around it wouldnt be that hard to contruct.  I etched a small pcb for using an LM317 voltage regulator as a ghetto speed control for a 70mm PC cooling fan.  The box was constructed out of various scrap pieces around the basement.  With everything finished I think a coat of paint will help, and a charcoal filter from the local Salvation Army will complete the project.

Trying to post source code into WordPress post

'********************************************************************
'* Name : UNTITLED.BAS *
'* Author : Sean Harmon *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 5/19/2011 *
'* Version : 1.0 *
'* Notes : Quick Infrared scanner using IR demodulator connected *
'* to port assigned to IRPin. *
'* PULSIN measures the pulse width of the IR-LED *
'* : *
'********************************************************************
DEFINE OSC 20 '// Define Oscillator @ 4mHz
include "ansi.inc"

ADCON1 =%00000111

'---------------------------------------------------------------------
'---------- Define LCD Options ---------------------------------------
'---------------------------------------------------------------------
Define LCD_DREG PORTD '// Define the data port
define LCD_DBIT 0 '// Select port bit [0-lower or 4-upper]
define LCD_RSREG PORTC '// Select RS port
DEFINE LCD_RSBIT 4 '// Set RS bit (port number)
define LCD_EREG PORTC '// Set E port
define LCD_EBIT 5 '// Set E bit
define LCD_BITS 4 '// 4 or 8 bit LCD

'---------------------------------------------------------------------
'----------[Define HSEROUT Options]-----------------------------------
'---------------------------------------------------------------------
DEFINE HSER_TXSTA 20h
DEFINE HSER_RCSTA 90h
DEFINE HSER_BAUD 9600
'DEFINE HSER_SPBRG 25 '//commented out to get 9600baud working

'DEFINE PULSIN_MAX 5000 '// MAX wait time for pulsin
TRISB.4 = 1 '// Set IR pin as Input

trx_pin VAR PORTA.0
IRPin Var PORTB.4 '// Set IR input pin

mode Var word '// Storage for serial mode
baud VAR byte
state var byte
Index VAR byte
IR_Size Var byte
IR_PULSE VAR WORD(13) '// 13-bytes. 8 data ; 5 address

mode = 16468
index = 0

Pause 500 'allow LCD to startup
@ ClearScr '//Clear Screen
hserout [10,13,"-----[IR Scanner]-----",13,10]
serout2 trx_pin,49236, [" IR Scanner "]
LCDout $FE, 1, " IR Scanner"

main:
pulsin IrPin,0,IR_Pulse(0)
if IR_Pulse(0) < 30 Then goto main
FOR Index = 1 TO 15
PULSIN IRPin,0,IR_PULSE[Index]
if Ir_Pulse[index] < 40 Then
IR_Size = Index
goto PrintIR
endif
NEXT Index

printIR:
lcdout $FE, 1
hserout [10,13]
for Index = 0 to (IR_size - 1)
serout2 trx_pin, 84, [IR_Pulse(index), " "]
hserout [DEC ir_pulse(index), " "]
lcdout #IR_pulse(index), " "
pause 10
Next Index
pause 100
goto main

OBDII Scanner IC shows up….

image

After making a pcb for my friends car, I started to look at more info on the OBDII standard used most cars built after 1996.  By tapping into the OBDII system, you are able to view and control many different parameters in a car.  While interfacing into OBDII systems is possible with a PIC, it seems much simpler to use an OBDII IC that takes care of most of the protocol. There are a few IC’s on the market that range from $8-20, but I was able to get my hands on a few samples for free from OBDSolutions. The chip is basically and OBDII to RS232 interpreter, allowing control over various car sensors and DTC codes. When the fans quit working on the Malibu, a DTC code showed the problem was that the fan relays had failed. By simply unplugging the ETC sensor it trips an error in the ECU that activates both fans immediatley. Since both fans came on we knew the relays were working fine. By checking the internet I found a lot of these cars have this problem. It has something to do with ECU burning on a certain section of the pcb.