Diode Theory Binary Outputs: LEDs A diode allows current to flow in only one direction. A diode consists of a semiconductor pn junction: In Silicon, the number of free electrons is a constant: np n i 2 1.5 10 10 2 In p-type silicon, you dope the silicon with Boron, with a typical doping of 10 14 atoms per cc p p 10 14 n p n i 2 p 2.25 106 In n-type silicon, the doping is Phosphorus, resulting in n n 10 14 p n 2.25 10 6 At the pn junction, some electrons and holes are created through thermal electrons. This is a small number, however, so assume it's zero. If electrons and holes are not created, current can only flow by electrons and holes flowing towards the pn junction (where they combine and disappear). Assume the current is flowing from the p-side to the n-side (the left figure below.) In this case, you are using majority carriers, so there are approximately 10 14 charge carriers. Now, assume the current is flowing from the n-side to the p-side. In this case, you are using minority carriers, resulting in only 2.25 10 6 charge carriers. If the diode has a resistance of 1 when using majority carriers (current p to n), it has a resistance of 44M when using minority carriers (!). A diode only allows current to flow from p to n Current Flow Current p n p n holes electrons electrons holes Low Z High Z majority carriers: # charge carriers = 10 14 minority carriers: # charge carriers = 10 6 1 September 6, 2017
Sidelight: The above discussion is a little off when dealing with reverse biased diodes. There are actually two types of current flow: drift current like what's described above, and electron-hole generation in the depletion zone, which is ignored in the above discussion. When forward biased, the number of electrons created in the depletion zone is so small you can ignore it. The depletion zone is small to begin with, and there just aren't that many electron-hole pairs created. When reverse biased, the drift current sees 44M. It doesn't take much to dominate electron-hole generation actually becomes the dominant term for current flow. So, you actually do get a little more current when reverse biased than the above discussion suggests. You can use this 'feature' to your advantage... If you reverse bias a diode, the current flow is related to temperature. This is one way to build a temperture sensor. If you bombard the diode with radiation, current flow will increase as the radiation kicks electrons out of their covalent bonds. This is one way to build a light sensor (photo-transistor) as well as a radiation sensor. With the latter, you can actually see this with an LED. Reverse bias an LED and measure the current flow. Shine a like LED on that LED. The current will increase. 2 September 6, 2017
Binary Outputs Using an LED 1W Star LED, 10mm 0.5W White LED, and Piranah RGB LED Light Emitting Diodes (LED's) can be used to display the status of an output pin on the PIC chip. LED's Are diodes, allowing current to only flow in one direction, They convert current to light.(light is proportional to current flow), and They are very fast, capable of over 1000 flashes per second. The LEDs that are in room 211 are as follows: Part # Color Current Typical Vf Typical mcd Wavelength (nm) Price ea 1W White Star LED 350mA 3.4V 100 lm n/a $1.55 0.5W 10mm White LED 100mA 3.3V 25 lm n/a $0.30 Piranah RGB LED Red 20mA 1.8V 8000 mcd 630 nm $0.31 Green 20mA 3.0V 8000 mcd 525 nm Blue 20mA 3.0V 8000 mcd 470 nm V f is the turn-on voltage for this LED. If the first diode is on, the ideal diode model would have a 3.4V drop across the diode. Typical mcd refers to the efficiency of the diode (mcd is a unit of light intensity). Wavelength is the average wavelength of the light from the LED (a more precise definition of the color than the term 'red'). Note that the PIC processor can only output 25mA. To drive the white LEDs at full power, you'll need to add an amplifier (coming up later when we talk about transistors). A PIC can drive these at a lower brightness level (25mA). Also note that the actual voltage across the diode varies with the current as show in the following figure. Since this is a diode, the VI characteristics are exponential in nature: (from ECE 321) I d I dss exp 1 V d nv T This is shown for a Germanium diode, silicon diode, and three LEDs with Vf = 1.7V, 2.8V, and 4.0V. As a rough approximation, the voltage across the diode is almost constant when Id > 0. This isn't exact, but it is close and makes analysis a lot easier. 3 September 6, 2017
Id 30 20 10 0 0 1 2 3 4 5 6 Vd Two types of circuits are used to drive the LED - depending upon whether you want to output a '1' or '0' to turn on the LED: PIC Output Pin R Id + - Vf PIC Output Pin R Id +5 + - Vf 1 = 'ON' 0 = 'Off' 0 = 'ON' 1 = 'Off' R is selected to set the brightness of the LED when turned on. 4 September 6, 2017
Example: Determine the brightness of a red LED when connected to +5V through a 1k resistor: Solution: Assuming an ideal diode, the current flowing is I d 5V 1.8V 1k 3.2mA The brightness for this LED is then Brightness 3.2mA 20mA 8000mcd 1280mcd Example: Design a circuit which outputs 100mcd from a green LED Solution: The required current flow is I d 100mcd 8000mcd 20mA I d 0.25mA This sets R: Assuming an ideal diode, I d 5V 3.0V R R 8000 More Fun with RGB LEDs If you mix a red, green, and blue LED, you can make other colors by mixing them. (RGB are the primary colors in light). If you can adjust the brightness of each one with N grey levels, you are able to output N 3 combinations. The Piranah LEDs combine three LEDs in a single package as follows. Using three resistors, you can turn on and off each LED separately with a PIC processor. RC2 RC1 RC0 Ir Ig Ib Rr Rg Rb 1.8V 3.0V 3.0V red green blue Piranah Package Connection to a PIC 5 September 6, 2017
Problem 1: LED Flashlight. Design a system which allows you to output 4 different colors based upon which button you press: RB0 All lights off RB1 Red light on RB2 Green light on RB3 Blue light on Define "on" to be 20mA. Hardware Solution: Connect the Pirannah LED to the PIC board as follows. Pick the three resistors so that 20mA is flowing when the output pin is 5V. Software Solution: ; --- Flashlight.asm ---- ; This program drives an RGB flashlight based upon the button pressed COLOR equ 0 #include <p18f4620.inc> Loop: org 0x800 call Init movf COLOR,W btfsc PORTB,0 ; if RB0 pressed, color = 000 (off) 0 btfsc PORTB,1 ; if RB1 pressed, color = 001 (blue) 1 btfsc PORTB,2 ; if RB2 pressed, color = 010 (green) btfsc PORTB,3 ; if RB3 pressed, color = 100 (red) 4 movwf COLOR ; send the color to PORTC movff COLOR, PORTC goto Loop Init: movwf clrf movwf clrf return end 0xFF TRISB TRISC 0x0F ADCON1 COLOR 6 September 6, 2017
Problem #2: Make the LEDs only 25% on (2000 mcd each). Hardware Solution: Change the resistor. Software Solution: Change the code so that each pin is high 1/4th of the time. ; --- Flashlight.asm ---- ; This program drives an RGB flashlight based upon the button pressed COLOR equ 0 CNT1 equ 1 #include <p18f4620.inc> Loop: org 0x800 call Init clrf PORTC ; Turn off the lights for three counts call Wait call Wait call Wait movf COLOR,W btfsc PORTB,0 ; if RB0 pressed, color = 000 (off) 0 btfsc PORTB,1 ; if RB1 pressed, color = 001 (blue) 1 btfsc PORTB,2 ; if RB2 pressed, color = 010 (green) btfsc PORTB,3 ; if RB3 pressed, color = 100 (red) 4 movwf COLOR ; send the color to PORTC movff COLOR, PORTC call Wait ; Turn on for one count Init: goto movwf clrf movwf clrf return Loop 0xFF TRISB TRISC 0x0F ADCON1 COLOR Wait: Loop: movwl 250 movwf CNT1 decfsz goto return end CNT1,F Loop ; waste 25,005 clocks (2.5ms) 7 September 6, 2017
If you change the code so that the lights are 5% on (PORTB), 20% (PORTC), and 90% (PORTD), it looks like the following. Note that it looks like the LEDs are variable brightness. Assembler Code - Modified so that PORTB is on 5% of the time, PORTC is on 20% of the time, PORTD is on 90% of the time On an oscilloscope, you can see this better; Signal for 5% Duty Cycle: 8 September 6, 2017
Signal for 20% Duty Cycle: Signal for 90% Duty Cycle: 9 September 6, 2017