Talking Electronics PIC Theory



 
Page1
Page2
Page3

"In Circuit"
ELECTRO-TESTER
A "Stand-alone" project using a PIC12c508A chip

Page 4:
CONSTRUCTION, BURNING and USING 

CONSTRUCTION
This is the "Stand-alone" version. All the components fit on a small PC board. The end of the board contains a probe or tip that can touch the positive lead of an electro while it is in circuit.
The board also contains a lead on an alligator clip. This is connected to the negative rail of the project-under-test.  
Two green LEDs produce a zener reference voltage for the correct operation of the circuit while 10 LEDs are used for the display. The only other components are a push button, on/off switch, 3 transistors, a chip, 4 cells, 12 resistors, 100u electrolytic, and a 100n capacitor.

ELECTROLYTIC
TESTER
Stand-alone version
PARTS LIST 
Cost $
xx.75 plus $2.20 postage

5  -  100R     1/4 watt
1  -  220R          "
1  -  1k              "
3  -  2k2            "
1  -  10k            "
1  -  22k            "
1  -  100n
1  -  100u
2  -  3mm green LEDs
10 - 3mm red LEDs
3  -  BC 547 transistors or similar
1  -  8-pin IC socket
1  -  PC mount push switch
1  - on/of slide switch
1  -  black crocodile clip
30cm  -  black hook-up wire
20cm  -   very fine solder
50cm   -  very fine tinned copper wire
4  -  LR932 cells
1  -  PIC12c508A microcontroller (blank)
1  -  Electro-Tester PC board

PC Board only 
$x.50
plus $2.20 postage
Pre-programmed PIC12C508A chip:
$xx.00 plus $2.20 post

Buy a kit

BURNING THE PROGRAM
The complete program for the Electrolytic Tester is shown below, including the .hex file. You will need the Multi-Chip Programmer to burn a PIC12c508A chip, plus the PIP-02 Programming software.  
Go to the Multi-Chip Programmer project for a step-by-step detail on burning the program into the chip. 

WRITING THE PROGRAM
All programs should be produced in small stages called sub-routines, with each sub-routine being tested before adding the next.
If you are going to create a project similar to this or if you want to copy the project and start from scratch, here is the approach we took: 
With any project, the first thing to do is connect the display to the chip and test its operation. This will give you a visual indication of the operation of the program and help you trouble-shoot each section. In this case the display is 10 LEDs.  The circuit diagram shows how they are connected, plus the two gating transistors. If you are going to design with a PIC16F84, you will need to add a 4k7 and 22p ceramic to the clock-in line of the micro for the oscillator. This is all you need. A program is then written to output to each of the LEDs.
The program consists of a delay routine and a "look-up table". 
Even though you may think a particular circuit will work, it's best to double-check by getting the micro to output to the device, just in-case you have made a mistake  in the wiring or in "theory."
Here is the test routine:

           ;ELECTROLYTIC TESTER Test routine to test the LEDs
                     ;Program for PIC16F84 

 Start       ORG 0x00
               BSF 03,5                 ;Go to page1 for setting-up the ports 
               MOVLW 00h            ;Put 00 into W 
               MOVWF 06h            ;to make port 06 (RB) output
               BCF 03,5                  ;Go to page0 for programming
               GOTO Main

 Table1   ADDWF 02h,1         ;Add W to Program Counter
               RETLW 21h            ;1
               RETLW 22h            ;2
               RETLW 24h            ;3
               RETLW 11h            ;4
               RETLW 12h             ;5
               RETLW 16h             ;6
               RETLW 14h             ;7
               RETLW 31h             ;8
               RETLW 32h             ;9
               RETLW 34h             ;0

          ;Delay for testing LEDs

 Delay2   MOVLW 04
               MOVWF 1C
 Delay3   DECFSZ 1Ah,1       ;Delay for main program for scanning
               GOTO Delay3
               DECFSZ 1B,1
               GOTO Delay3 
               DECFSZ 1Ch,1
               GOTO Delay3
               RETURN

        ;MAIN ROUTINE

 Main       MOVLW 0A
               MOVWF 0D          ;decrementing file
               CLRF 0C
 Main1     MOVF 0Ch,0         ;Copy 0C into W
               CALL Table1
               MOVWF 06h          ;output the table value
               CALL Delay2
               INCF 0Ch,1
               DECFSZ 0D,1
               GOTO Main1
               GOTO Main

                END

 When the display is working, you can use it to check each sub-routine as you add it to the program. 
The next thing to do is build the circuit for the "front-end."
 

Combining Hardware and Software
The most difficult part of creating a program is combining the hardware with the software. In this case the difficulty lies in the front-end. You need to know how long it takes to charge an electrolytic. 

The Sub-routines
All programs consist of a number of sub-routines. Each sub-routines carries out a particular task. It is best not to make the sub-routines too small or break them up so that the micro is darting off to other sub-routines all over the page. The micro is perfectly happy doing this, but when you have to physically check a routine to try and locate a fault, fragmented program take a long time to diagnose. 
In addition, it is best to use simple programming with easy to understand instructions as "clever" programming will also take a long time to decipher. 
Place the sub-routines in alphabetical order, after "start" and "table" routines, with the last routine,  "main". 
The first routine we will cover is "Start".
Start. Start has an instruction: CALL Button. This sub-routine contains the instructions to set the port (the GP lines). The Alert flag (bit 7 in file 1E) is cleared and the micro goes to Main.   
Alert is the last routine to be executed in the operation of the program was the last routine to be added. It creates a running LED routine on the display if the project is left ON after 5 minutes of non-use. 
It is called from the main menu. File 1E is incremented each time the Main routine is cycled and when 1E is 40h, the micro goes to Alert. 1E is reset each time the Test button is activated.
There was a small "adaption" or "adjustment" needed between the values in Table1 and the LEDs on the PC board. The zero LED on the PC board is placed after "9" but in the table it is the first data value. If the table is executed as a list, it will create a jumping-effect on the display when the "0" is encountered. This means the routine must leave out "0". 
The routine loads a file (0C) with 9 and decrements it to zero. At the same time it uses the value in 0C to select a byte of data from the table. It jumps out of the routine before the "0" byte is reached. To scan the LEDs in the opposite direction, a count file (0D) must be loaded with a value and decremented to zero. The "look-up" value for the table is file 0C (as previously) and it is zero from the previous decrementing. It is incremented so that is does not select "0" in the table and the loop is executed.  This is how the "0" is avoided. The CALL Button instruction is positioned in the routine so that it is passed by the micro during the display of each LED. This makes it "fast acting"  when the button is pressed. 
Button routine only set the "button-press" flag, bit 7 in file 1F. To do this, one of the lines must be changed from an output to an input. The instructions in Button do this. These instructions work for both the PIC12c508A and PIC16F84 microcontrollers. This program can be used "as is" for either chip, and the two .hex files have been included below. 
Charge. This sub-routine charges the electro to 3.8v as governed by the accurate voltage produced by the two green LEDs. It firstly discharges the electro, just to make sure the charge comes from this sub-routine. The discharge is not really needed.
Dis. This sub-routine discharges the electro to 0.7v through a 220R resistor. This takes a definite amount of time for each value of capacitance. The program creates a timing loop made up of the instructions at LoopX and LoopY, plus the instructions needed to load the counter files. A files is incremented and looked at to see if it is "ten" (0A). If it is ten, the file is zeroed and the next digit is incremented. This next digit must also be looked at to see if it is ten.  
Delay1 is a 1/4 sec delay for the blanking time for the display. Each digit must be turned off for a short period of time just in case the next digit is the same value. 
Delay2 produces the 1 second ON time for the display.
Main is the main sub-routine.  The micro loops around this routine and creates the operations of the project. If 40h loops are executed without the Test button being pressed, the micro goes to Alert, and loops it until the Test button is pressed. 
When the power is turned ON, the micro goes to Main and the first instruction is CALL Charge. This sub-routine charges the electro and goes to Dis where the electro is discharged and the time it takes to discharge is counted by a counter. When the micro comes back to Main, the counter files (11h, 12h, and 13h) contain the value equivalent to the microfarad value of the electrolytic. Main displays the value (hundreds first) for 1 second then blanks the screen for 1/4 second. The micro loops around Main, displaying the value of the electrolytic for 40h loops, then goes to Alert. 
 

         Electrolytic Tester for 508A
                          ;Program for PIC12c508A 
                          ;This program will also work "as is" in a PIC16F84

 Start     ORG 0x00
             CALL Button       ;To set up the port
             CLRF 1E              ;Clear the Alert flag 
             GOTO Main

Table1 ADDWF 02h,1      ;Add W to Program Counter
            RETLW 34h         ;0
            RETLW 21h         ;1
            RETLW 22h         ;2
            RETLW 24h         ;3
            RETLW 11h         ;4
            RETLW 12h         ;5
            RETLW 16h         ;6
            RETLW 14h         ;7
            RETLW 31h         ;8
            RETLW 32h         ;9

         ;Running LEDs to alert user to turn OFF Project

 Alert    MOVLW 09h 
             MOVWF 0Ch
 Alert1  MOVF 0Ch,0       ;Copy 0C into W
             CALL Table1
             MOVWF 06        ;Output data to LEDs
             CALL Delay1 
             CLRF 06
             CALL Button
             BTFSC 1F,7
             GOTO Start       ;Button pressed 
             DECFSZ 0C,1
             GOTO Alert1
             MOVLW 09
             MOVWF 0Dh      ;Decrementing file
             INCF 0Ch,1         ;Start at 1 in table
 Alert2  MOVF 0Ch,0       ;Copy 0C into W
             CALL Table1
             MOVWF 06         ;Output data to LEDs
             CALL Delay1
             INCF 0Ch,1
             CLRF 06
             CALL Button
             BTFSC 1F,7
             GOTO Start ;Button pressed
             DECFSZ 0Dh,1
             GOTO Alert2
             GOTO Alert

              ;Button routine puts flag in file 1Fh
              ; It also sets up the port (port B) for a '508A and/or a PIC16F84

 Button  BCF 1F,7 ;Clear the button-press flag 
             MOVLW 10h ;Put 10h into W 
             TRIS 06h ;to make RB4 (GP4) input 
             BTFSC 06,4 ;Is "test button" pressed?
             GOTO But2 ;Yes
 But1     MOVLW 08h ;Put 08 into W 
             TRIS 06h ;to make RB3 (GP3) input (GP3 can only be input anyway) 
             RETURN
 But2     BSF 1F,7 ;Set the button-press flag 
             GOTO But1
 
           ;This routine charges the electro

 Charge   BCF 06,5 ;Discharge the electro before charging
               CALL Delay2 
               BSF 06,5 ;Charge the electro
               CALL Delay2
               CALL Delay2
               GOTO Dis

        ;00 to 999 COUNTER    (each unit = 1u)

 Dis        CLRF 11h     ;11h is units file. Start=0
              CLRF 12h     ;12h is 10's file. Start=0
              CLRF 13h     ;13h is 100's file. Start=0 
              CLRF 06       ;Make GP5 LOW to discharge electro and all other lines
              NOP             ;Give the circuit time to settle down 
              NOP             ; and produce 000 readout if no
              NOP             ; electrolytic is connected
              NOP
              NOP
              NOP
 Dis1      BTFSC 06,3 
              RETURN                 ;Electro discharged
              MOVLW 08h
              MOVWF 1Bh
 LoopX   MOVLW 10h
              MOVWF 1A
 LoopY  DECFSZ 1Ah,1
              GOTO LoopY
              DECFSZ 1Bh,1
              GOTO LoopX
              INCF 11h,1             ;Increment the 1's file 
              MOVLW 0A
              XORWF 11h,0
              BTFSS 03,2
              GOTO Dis1             ;File 11h is not 10! 
              CLRF 11h                ;Zero the digits file 
              INCF 12h,1               ;Increment the 10's file 
              MOVLW 0A
              XORWF 12h,0
              BTFSS 03,2
              GOTO Dis1            ;File 12h is not 10!
              CLRF 12h               ;Zero file 12h 
              INCF 13,1 
              MOVLW 0A
              XORWF 13h,0         ;Clear 13h just in case it is over 9
              BTFSS 03,2 
              GOTO Dis1
              CLRF 13h
              GOTO Dis1

 Delay1 DECFSZ 1Ah,1         ;1/4 sec Delay for OFF time
             GOTO Delay1
             DECFSZ 1B,1
             GOTO Delay1 
             RETURN

 Delay2  MOVLW 04               ;1sec delay for ON time
              MOVWF 1C
 Delay3  DECFSZ 1Ah,1 ;
              GOTO Delay3
              DECFSZ 1B,1
              GOTO Delay3 
              DECFSZ 1Ch,1
              GOTO Delay3
              RETURN

            ;MAIN ROUTINE

 Main      CALL Charge 
 Main1    MOVF 13h,0             ;Copy hundreds into W
              CALL Table1
              MOVWF 06               ;Output the digit
              CALL Delay2             ;Show digit for 1 sec
              CLRF 06
              CALL Delay1             ;Off for 1/4 sec
              CALL Button             
              BTFSC 1F,7               ;Is button pressed
              GOTO Start               ;Yes
              MOVF 12h,0              ;Copy 10's into W
              CALL Table1
              MOVWF 06
              CALL Delay2
              CLRF 06
              CALL Delay1
              CALL Button                 
              BTFSC 1F,7                  ;Is button pressed
              GOTO Start                  ;Yes
              MOVF 11h,0
              CALL Table1
              MOVWF 06
              CALL Delay2
              CLRF 06
              CALL Delay2
              INCF 1E,1                      ;Increment the Alert file
              MOVLW 40h                 ;Put 40h into W for 5 minutes Alert 
              XORWF 1E,0
              BTFSC 03,2                   ;Test zero flag. Is Alert file 40h! 
              GOTO Alert                    ;Yes
              CALL Button                   ;No
              BTFSC 1F,7                    ;Is button pressed
              GOTO Start                     ;Yes
              GOTO Main1                   ;No

              END



 
The block of numbers below is the HEX file for Electrolytic Tester-508A version. Copy and paste it into a text program such as TEXTPAD or NOTEPAD and call it: Etst508A.hex   (for Electro-Tester508A version). This version is for the Electrolytic Tester project using a PIC12C508A chip. 
:1000000029097E006E0AE20134082108220824082A
:10001000110812081608140831083208090C2C00BF
:100020000C0203092600600966002909FF06000A80
:10003000EC02100A090C2D00AC020C020309260088
:100040006009AC0266002909FF06000AED021D0ADC
:100050000E0AFF04100C06008606310A080C060082
:100060000008FF052E0AA6046509A60565096509AD
:10007000390A710072007300660000000000000081
:1000800000000000000066060008080C3B00100C91
:100090003A00FA02490AFB02470AB1020A0C91012E
:1000A0004307430A7100B2020A0C92014307430A54
:1000B0007200B3020A0C93014307430A7300430A18
:1000C000FA02600AFB02600A0008040C3C00FA0213
:1000D000670AFB02670AFC02670A00083309130279
:1000E000030926006509660060092909FF06000A60
:1000F0001202030926006509660060092909FF0646
:10010000000A110203092600650966006509BE029E
:10011000400C9E0143060E0A2909FF06000A6F0AD9
:00000001FF

NOTE: The block of numbers below is the HEX file for Electrolytic Tester-F84 version. Copy and paste it into a text program such as TEXTPAD or NOTEPAD and call it: EtstF84.hex   (for Electro-TesterF84 version). This version is for those who have made their own circuit using a PIC16F84 chip. 
:1000000029209E016E28820734342134223424347E
:1000100011341234163414343134323409308C0033
:100020000C08032086006020860129209F1B0028E1
:100030008C0B102809308D008C0A0C0803208600D8
:1000400060208C0A860129209F1B00288D0B1D280B
:100050000E289F1310306600061A312808306600FB
:1000600008009F172E2886126520861665206520B9
:1000700039289101920193018601000000000000DF
:100080000000000000008619080008309B001030B6
:100090009A009A0B49289B0B4728910A0A301106AF
:1000A000031D43289101920A0A301206031D4328BA
:1000B0009201930A0A301306031D43289301432833
:1000C0009A0B60289B0B6028080004309C009A0B58
:1000D00067289B0B67289C0B6728080033201308B0
:1000E0000320860065208601602029209F1B0028B0
:1000F00012080320860065208601602029209F1BAE
:1001000000281108032086006520860165209E0ACC
:1001100040301E0603190E2829209F1B00286F2837
:00000001FF

IF THE PROJECT DOESN'T WORK
There are 3 separate areas where a fault can develop:
1.
The circuit
2.
The Program
3. Programming the chip. 
If your project doesn't work, you should be happy. This is when you will start to learn electronics. It's only by fixing a fault that you will improve your understanding of electronics.

1.
The Circuit
If you have used one of our kits and built the project on our PC board, you should have little problem with the correctness of the circuit. Most of the problems we have had to date (20 years of Talking Electronics) have been in "junk parts" or home-made PC boards. Many "junk" resistors are 1% or 2% tolerance devices and you must look at our "1% tolerance" web page to correctly identify them.  Home-made PC boards are especially difficult to check as we have found. One board had a track going to the wrong pad and another had a hairline crack in one of the tracks.
There are lots of other faults like un-etched copper between tracks creating shorts, borders around the edge of the board causing a short-circuit. The only solution is to buy a kit and start again. 

2.
The program  
If you have developed your own program, you will have to go to our programming section(s) and follow our guide (using beep etc) until the problem has be located.

3. Programming the chip.
Programming the chip is the most difficult section to investigate. If you have built the Multi-Chip Programmer and burnt a '508A chip previously, (Logic probe for instance), you will know the Programmer works. The most annoying feature of the PIP-02 program is the Watchdog Timer. It is set to ON in the default mode and this means the program will not execute fully
if it is not switched OFF.  You can place the chip in the Programmer and read the "fuses." You can also read the program from the chip and if you have made a (photo)copy of the .hex file from this project, you can compare the two.  

Hopefully, you will have the project working by now. As a last resort, it can be sent to talking electronics for checking. If the chip is faulty we will burn a new one ($10.00) and let you know of any other faults. 
The main point is this. Don't let a faulty project beat you. It must be fixed, before you can go on to the next step. 

USING THE ELECTROLYTIC TESTER

Connect the earth clip to the negative rail of the equipment you are testing and place the E-Z clip on the positive of the electrolytic you are testing. Press button "A" on the 5x7 project and the program will charge the electrolytic and measure how long it takes to discharge. The display will give a readout in "u" (microfarad). If the reading is lower than expected, it could be due to the surrounding circuitry affecting the reading or a dry electro. Remove it, connect the test leads directly and push button "A" to re-test.

This concludes the project but it should be just the starting point for you to design another project around the 5x7 Display. The first thing you will need is the Experimenter MkIII PC board and some components. Click HERE to buy the PC board.

There are lots of different projects that can be interfaced to the 5x7 Display, in a similar way to the Electrolytic Tester. 
Here are three more simple projects:
3-digit customer counter using an infra-red beam
- Timer for sports events
- Count-down counter for slot cars, rocket launching, etc
All these projects need only a few "font-end" components and the 5x7 Display. The Experimenter Board is only used for the first stage of development. Talking Electronics has a range of Designer Boards containing a matrix of holes and lands for building a circuit or you can design a PC board and transfer the parts to the new board. The idea is the parts are removed from the Experimenter Board and it is re-used for the next project.