Basic Knowledge of Electricity and Electronics for Embedded Systems´ Programmers 1 Elementary Electricity Concepts Ohm´s Law: • • Current = Electromotive Force / Resistance => I = E/R • NOTE: An ideal voltage source (E) is considered to have ZERO internal resistance, that is, for an analysis of resistance accross its terminals it is a short circuit. E = 12 Volts Series Circuit and Kirchoff´s Voltage Law The Three Rules of a Series Circuit: • • • I=? Current has the same value at any point within a series circuit The values of the resistances of individual components add up to the total circuit resistance. Rt = R1 + R2 + R3 Voltage drops across the individual component resistances add up to the total applied voltage. E = V1 + V2 + V3 R=2 KΩ V1=? E = 12 V R1 = 2 K I=? R 2= 2 K R3 = 2 K V3=? Resistive Divider – Class Exercise 2 Elementary Electricity Concepts Parallel Circuits and Kirchoff´s Current Law • A parallel Circuit provides two or more paths or branches for circuit current. The Three Rules of a Parallel Circuit: • • • The same voltage is applied across each individual branch The total current is equal to the sum of the individual branch currents. E The equivalent (or effective) resistance is equal to 12 V the applied voltage divided by the total current, and this value is always less than the smallest resistance contained in any one branch. I total R1 3Ω R2 4Ω R3 6Ω I1 I2 I3 I total = I1 + I2 + I3 Req = E / I total 1/Req = 1/R1 +1/R2 +1/R3 3 DC and AC Voltage and Current DC voltage/Current • Batteries • Electronic Equipment Power Supplies convert AC voltage/current to DC voltage/current • Usually Low Power Low Voltage Circuits • Current Flows in Only One Direction V t AC Voltage/Current • Provided by Electricity Companies • Normal Illumination, Medium and High Power Equipment are usually driven by AC Voltage/Current • Current flows cyclically in both directions of the circuit. • Vrms= 0.707 * Vpeak (0.707 * 179 V peak = 127Vrms) • frequency(f) = 1/T => 60 Hz • Phase -> 0 degrees to 360 degrees +V V peak = 179V t -V T 4 Capacitor 1 Capacitor E S R=1K 2 10 V C 1uF Vc • Opposes changes in Voltage Between Its terminals. • Stores Electric Charge • Can be used to minimize (filter) the ripple of analog signals • Can be used to supply high instantaneous current to circuits • Together with a Resistor can be used to delay signals Switch in 1 Switch in 2 Vc T = RC (Time to reach 63.2 % of Final Value During Charge) or 36.8% of Initial Value During Discharge T – Seconds; R – Ohms; C - Farads 5 Inductor Inductor • Opposes Changes in Current accross its terminals. • Made by Winding a Conductor around a core (magnetic material or insulated material) Vr 1 E I S 2 10 V R=1K L 1uH • Inductance measured in Henries Switch in 1 • Used in Transformers to Isolate one Power Source from another. • Used in Transformers to Convert from one voltage Range to Another and in Tuned LC Communication circuits. Switch in 2 Vr T = L/R (Time to reach 63.2 % of Final Value) or 36.8% of Initial Value T – Seconds; R – Ohms; L - Henries 6 Class Exercise -1 Draw a scheme with a resistor and a push button switch to reset a microcontroller. Consider a time constant of 20 ms (the time required to reach 63% of the maximum voltage) for a resistor of 100 Kohms. Calculate the capacitor required. • In scheme 1 the signal is normally at high (3 volts) and goes to zero volts when the push button key is pressed (RESET AT LOW) • In scheme 2 the signal is normally at zero volts and goes to 3 volts when the push button key is pressed. (RESET AT HIGH) Draw a scheme with an ON-OFF switch (without central pole) that will indicate to the microcontroller that when in position A, that pin will be at zero volts (LOW) and when in position B it will be at 3 volts (HIGH). 7 Reactance and Impedance • The opposition to AC voltage changes offered by a capacitance (Xc or capacitive reactance measured in ohms) • Xc = 1 / (2π f C) ; f = frequency (Hz); C = Capacitance in Farads C Xc R θ Xc (R2+Xc2) Z= Inductive Reactance • The opposition to AC current changes offered by an inductor (Xl or inductive reactance measured in ohms) • Xl = 2π f L ; f = frequency (Hz); L = Inductance in Henries R Capacitive Reactance R=8Ω Z= (R2+Xl2) Xl=5Ω R θ Xl Impedance and Vectorial Addition • The combined opposition to current changes by resistance, inductance and capacitance is called impedance and is represented by the symbol Z. R, L, C circuit: Z= (R2+(Xl-Xc)2) 8 How can an AC Signal “Cross” a Capacitor? + 5V Vin = AC Signal –> f = 1 MHz 4V C = 1 uFarad R1 Xc = 1 / (2π f C) Xc = 1/ (2 x 3.14 x 1 x 0 106 x1x C 2V 0 10-6) Xc = 1/ (2x3.14) ohms Vin Xc R2 Vout Xc = 0.16 ohms Xc = ALMOST A SHORT CIRCUIT ! THUS, An AC signal can “cross” (or be propagated across) a capacitor, provided the frequency of the AC signal is high enough to make the capacitor impedance very low. On the other hand, the capacitor blocks DC signals (or very low frequency signals) 9 Triple Phase Transformers Transformers in Delta Organisation • Used to convert and Isolate Very High Voltage (from Power Plants) to High Voltage in City Distribution Transformers in Star Organisation • Used to Convert and Isolate from High Voltage to Medium Voltage F1 F2 F3 F1 N F2 F3 10 Power Supplies, No-Breaks, Stabilizers Power Supplies • Convert AC Voltage to DC Voltage • Convert 127V AC to +5V, +12V, -12V, -5V DC No-Breaks • When there is AC Voltage, they Charge a Battery • When there is no AC Voltage, The DC Voltage of the Battery is Converted to AC Voltage to feed the Computer • A computer normally needs a Stabilizer and a No-Break. Stabilizers • Guarantee that AC Voltage Supplied to a Computer is kept within Certain Limits to Avoid Damaging the Computer Note: Common computer No-Breaks do not generate electricity from the battery when there is external power. They just generate electricity when there is no external power. Therefore, if the external power varies its amplitude considerably, it is not good for the computer. Due to this, a stabilizer is needed before the No-Break. 11 Switches, Relays, Solenoids, Power Relays Push Button Take to Class: Off On 1 Switches 1 1 2 C • Some Types Relays, Solenoids • AC (127V) or DC Driven (12V, 5V, etc) – The diode in parallel prevents a high peak voltage accross R when the circuit is opened. Central 2 Pole Three-Phase Power Relays or Solenoids 12V DC 2 Same Types with Multiple Contacts Neutral 127V AC (Phase) LAMP or Equipment R F1 or F2 or F3 Neutral F1 Return F1 F2 Return F2 F3 Return F312 Debouncing When a switch (any type) changes state (on -> off or off -> on), it presents a mechanical bouncing which generates a signal similar to the one shown at the right. 5V R 5V 1 C S Microcontroller 2 The resistor R is needed because the signal S can not be left “floating” in na undefined state when the switch changes from state 1 to 2. Without debouncing the signal can generate several interrupts (or status changes) corresponding to just one action. Debouncing consists in “Filtering” the signal S so that a proper operation of the switch action is sensed. Debouncing can be done in hardware of software Δt Read Key (should be stable) Δt Techniques that can be used: -If status loop: after first status change, program timer and after elapsed time read key status. -If Interrupt: on first interrupt program timer which will interrupt after elapsed time. Then read key status. 13 Logic Circuits using Switches and Relays 14 Grounding Grounding Reference • Safety Ground • Two Equipments(circuits) can communicate either using commom mode signals or differential signals. The most common are common mode signals. In this case a common reference wire is established and voltages are related to that common wire, which is usually termed Ground wire. Safety ground is a wire employed to connect metalic parts of the equipment to the earth´s ground. This is done to prevent accidents by persons touching metalic parts with voltage levels (due to defective parts) Neutral Wire • Comes from the street transformer (where is earth grounded) but can not be used for safety ground. A separate safety ground is required. Equip. A Signals Common (ground) Equip. B Hot Wire Neutral Safety Ground Equip. Signals Equip. B A Common (ground) Safety ground 15 Volt – Ohm - Meter (VOM) or Multimeter 16 V.O.M Measurements 17 Some Common Electronic Devices Diode • V Vz Used to establish a certain reference voltage in a circuit section, almost independently of the reverse current flow across it. Reverse voltage depends on the type of zener diode. (direct voltage drop is 0.65 V) XTAL Crystal • Used to allow current in just one direction, to rectify AC waveforms. When current flows in the correct direction, voltage drop across it is approximately 0.65V, almost independently of the current. When voltage is reversed, it acts like an enormous resistor. A LED is also a diode but the voltage drop across its terminals is usually 1.5 Volts, instead of 0.65 Volts. Zener Diode • Current flow Used to provide highly accurate clock oscillators Light Dependant Resistor (LDR) • Resistance varies according to light A B 18 Diode Voltage x Currrent Characteristics 19 Class Exercise -2 Draw the output waveform for the circuit below 0 Sinusoidal Vout ? Generator 20 Class Exercise -3 Common LEDs (Light Emmitting Diodes) can be turned “ON” with a current between 5mA and 10mA. Microcontrollers Can Have Currents in Output pins between 2mA and 20ma when in “LOW” Level (IOL) and currents between 2mA and 10mA when in “HIGH” level (IOH). Note that when the output pin of the microcontroller is at 0 volts level the current flows into the pin and when it is at 3 volts, the current flows out of the pin. In order to protect the Microcontroller to not exceed its output current and also to protect the LED to not exceed the current across its terminals, a resistor in series with the LED is used. Draw a scheme to connect a LED to an output pin of a microcontroller, turning the LED “ON” when the output pin is at logic “0” and turning it “ON” when the output pin is at logic “1”. Calculate the resistor to limit the current across the LED to 5 mA. Consider that the power supply is 3 Volts. Remember that there is a voltage drop across the LED when the current is flowing in the correct direction. 21 Remember: Ohm’s Law V IR Kirchoff’s Voltage Law – The V 0 Kirchoff’s Current Law – The I IN I OUT algebraic sum of all voltage rises and voltage drops around a closed loop must equal zero algebraic sum of all currents entering and leaving a node must equal zero Series Equivalent Parallel Equivalent REQ R1 R2 ... RN 1 1 1 1 ... REQ R1 R2 RN 22 Mesh Analysis R4 • First, determine the number of closed loops and then draw the direction of the currents around the loops. 300 R1 • Second, identify the plus and minus voltage on each resistor, according to the currents flowing across them. • Third, traverse the loop associating a plus or minus sign, depending on the the entrance sign, when traversing the loop. 100 20V I1 I3 R2 500 R3 100 R5 200 I2 Loop1: - 20 + 100 (I1-I3) + 500 (I1-I2) = 0 Loop2: 500 (I2-I1) + 100 (I2-I3) + 200 (I2) = 0 Loop3: 300 (I3) + 100 (I3-I2) + 100 (I3-I1) = 0 System with 3 equations – Solve using determinants I1=85.7mA ; I2 = 57.14mA; I3 = 28.57mA 23 Thevenin´s Theorem Thevenin´s Theorem: Any two terminal circuit can be 15 4 replaced by a resistance, equal to the resistance measured across the two terminals, in series with a voltage source, equal to the open circuit voltage accross the two terminals. 25V A 2 B What For ??: => The Key objective is to find a simple circuit that is equivalent to a more complex one. For example: Obtain an equivalent circuit between terminals A and B that is simpler than the circuit on the right: Rth A Vth Step1 : Find Vth. Because the terminals are open, there will be no current flowing through the 4 ohms resistor, and therefore, no voltage drop accross it. So, the open circuit voltage (Vth) will be equal the voltage across the 10 resistor. Thus, by the voltage divider rule: B 15 4 2 A Rth B Vth = 10V. 10 Step2 : Find Rth (the resistance seen looking into terminals A and B). Replacing the voltage source with its ideal 10V internal resistance (zero ohms), we find that: A Rth = 4 + 15 // 2 = 10 B 24 TRANSITOR - PNP Emitter Current Base Collector Bipolar Transistor -PNP Emitter p Base n n Emitter Current Base p Collector Collector Ie = Ic + Ib Bipolar Transistor - NPN Collector Collector n Base p p Base n Emitter Emitter Ie = Ic + Ib Bipolar Transistor Construction • NPN / PNP Block Diagrams Emitter Collector N Base P N Emitter Collector P N P Base 28 Bipolar Transistor Biasing (NPN) FB Emitter - N RB P N Collector + Base + 29 Bipolar Transistor Biasing (PNP) FB RB Emitter P + N Collector P - Base + 30 Transistor Characteristic Curve 90 uA 80 uA 70 uA IC 60 uA Saturation IB Q-Point 50 uA 40 uA 30 uA 20 uA 10 uA 0 uA Cutoff VCE 31 Class ‘A’ Amplifier Curve 90 uA 80 uA 70 uA IC IB 60 uA Saturation 50 uA 40 uA 30 uA 20 uA Q-Point 10 uA 0 uA Cutoff VCE 32 Class ‘B’ Amplifier Curve 90 uA IC IB 80 uA 70 uA 60 uA Saturation 50 uA 40 uA 30 uA 20 uA Q-Point 10 uA 0 uA Cutoff VCE 33 Analyzing The Transistor Operation Region: Conduction, Saturation or Cutt-Off Conduction Region –For any transistor to conduct, two things must occur. The emitter - base PN junction must be forward biased. The base - collector PN junction must be reverse biased. In this region the transistor presents an amplification in current (gain) or “ß”, which relates collector current (Ic) and base current (Ib) according to the following equation: Ic = ß Ib (Equation 1) It is also known that Ie = Ic + Ib (Equation 2) Then: Ie = (ß Ib) + Ib => Ie = (ß + 1) Ib (Equation 3) Cut-Off Region – When Ic is almost zero and the absolute value of the Base-Emitter voltage is lower than 0.65 V (for silicon transistors). When the transistor reaches this region, the equations above are no longer valid. Saturation Region – When Vce is almost zero and the absolute value of the Base-Emitter voltage is larger than 0,65 V (for silicon transistors). When the transistor reaches this region, the equations above are no longer valid. 34 Bipolar Transistor Operation (PNP) •90% of the current carriers passes through the reverse biased base - collector PN junction and enter the collector of the transistor. •10% of the current carriers exit transistor through the base. •The opposite is true for a NPN transistor. 35 Amplifier Operation • The transistor below is biased such that there is a degree of forward bias on the base - emitter PN junction. • Any input received will change the magnitude of forward bias & the amount of current flow through the transistor. RC + 0 Input Signal +VCC + Q1 0 RB Output Signal 36 Amplifier Electric Switch Operation •When the input signal is large enough, the transistor can be driven into saturation & cutoff which will make the transistor act as an electronic switch. •Saturation - The region of transistor operation where a further increase in the input signal causes no further increase in the output signal. •Cutoff - Region of transistor operation where the input signal is reduced to a point where minimum transistor biasing cannot be maintained => the transistor is no 37 longer biased to conduct. (no current flows) Amplifier Electric Switch Operation –Transistor Q-point •Quiescent point : region of transistor operation where the biasing on the transistor causes operation / output with no input signal applied. –The biasing on the transistor determines the amount of time an output signal is developed. –Transistor Characteristic Curve •This curve displays all values of IC and VCE for a given circuit. It is curve is based on the level of DC biasing that is provided to the transistor prior to the application of an input signal. –The values of the circuit resistors, and VCC will determine the location of the Q-point. 38 Some Common Electronic Devices Bipolar Transistor (NPN) e.g.: BC237, BC 337, BC 547, BC 557, 2N2222 (NPN and PNP) MOS Transistor (N type) Source Drain Gate 39 Determining Saturation, Cutoff or Conduction Determine the operation Region of the circuit below: R1 Rc 10K 100K Ic C + 10V B E Ib Vbe Ic = ß x Ib = 100 Ib R1 100K Rc 10K B Ic C E Vce=? Ie Assume Transistor Current Gain = ß = 100 and Vbe = 0.65V Ie = Ic + Ib Simplified Model Ib Vbe + 10V Vce=? Ie Calculating Ib: 10 V = Vbe V + Ib x 100 x 103 (10 – 0.65) V = Ib x 100 x 103 => Ib = .0935 mA Thus Ic = 100 x Ib = 9.35 mA 10 V = Vce + Ic x 10 x 103 => Vce = - 83.5 V < 0V !! In reality Vce does not go negative because when it is almost zero (saturation), the current gain (ß) does not apply any more and Vce sets at 0 volts. Thus the transistor is SATURATED 40 Building Logic Gates with Transistors & Resistors 41 Transformers A transformer is a passive electronics component and consists of a pair of wire coils coupled together with an iron core. The input coil is called the primary coil and the output coil is called the secondary coil. Transformers Transformer Voltages 150 100 Volts 50 Primary 0 0 -50 -100 -150 1 2 3 4 5 6 7 8 Seconday Filters Plot of Transformer Voltages: Left side, primary; Right side, secondary 14 12 Volts 10 8 Series1 6 4 2 0 0 2 4 6 8 10 Power Supply Unrectified 15 10 Unrectified 0 Rectified 15 0 1 2 3 4 5 6 7 8 10 -5 Effect of Filter 0 0 1 2 3 4 5 6 7 8 -5 -15 -10 10 8 Rectifier 6 4 2 0 0 0 -15 Transformer 12 20 10 0 Volts -10 Volts 5 Volts Volts 5 2 4 6 8 Filter 1 2 3 4 5 6 7 8 Full-Wave Rectifier bridge Volts Rectified 20 10 0 0 2 4 6 8 46 Full-Wave Rectifier Volts Rectified 20 10 0 0 2 4 6 8 47 Power Supply Capacitor Filter and Regulator 12V Vem dos Diodos Retificadores IN REGULADOR 5V + 5V DC 7805 OUT TERRA 48 Interface Circuits with the Real World Switches and Relays – already shown Keyboard with No Logic Keyboard with Logic Light Emitting Diodes (LEDs) Seven Segment Displays – can be driven by resistors connected to normal logic – check current Liquid Crystal Displays – 20 or 40 columns by 2 to 4 rows – some have serial interface 49 Example 1 – Driving a 7-Segment Display “Common Anode” +5V v+ v+ Is 8 x 180 R abcdefg abcdefg Is = (5V – 1.5V) / 180R = 20ma 50 Example 1 – Driving a 7-Segment Display “Common Anode” +5V 10K It It 10K v+ v+ Id 8 x 180 R abcdefg abcdefg Id = (5V – 1.5V) / 180R = 20ma 51 Interface Circuits with the Real World O.C. Inverter (7406) Transistor-Transistor Logic (TTL) (5 volts) to other voltages Converters: 7406, 7407 (open collector) Max 232 +12v 0v TTL (5 volts) to RS232C (serial port -> +12V to –12V) converters: MAX 232, +5v 1489, 1488 0v TTL common mode to RS422 Differential mode – Higher speed than RS232 and higher noise immunity -12v I 52 Interface Circuits with the Real World R Digital to Analog (D/A) E Converter 8/12/16-bit Data G Analog Signal I S T Clock E R Analog to Digital (A/D) Converter D/A Analog Signal A/D Clock R E Digital G Data I S T E R 53 Programmable Logic Arrays (PLAs and PALs) F= (A.B) + (A.C.D) + (D.E) + (A.F) + (B.E.F) A B A C D D E A F CI-1 F B E F CI2 CI-3 CI4 O3 = I0.I2./I3 + I3.I5 + /I2.I4 + /I4.I5 + /I5.I1 54 Field Programmable Gate Arrays (FPGAs) 55 FLASH Memory Flash memory is a form of EEPROM that allows multiple memory locations to be erased or written in one programming operation. Normal EEPROM only allows one location at a time to be erased or written, meaning that flash can operate at higher effective speeds when the systems using it read and write to different locations at the same time. All types of flash memory and EEPROM wear out after a certain number of erase operations. Flash memory is made in two forms: NOR flash and NAND flash. The names refer to the type of logic gate used in each storage cell. NOR flash was the first type to be developed, invented by Intel in 1988. It has long erase and write times, but has a full address/data (memory) interface that allows random access to any location. This makes it suitable for storage of program code that needs to be infrequently updated, as in digital cameras and PDAs. Its endurance is 10,000 to 100,000 erase cycles. NOR-based flash is the basis of early flash-based removable media; Compact Flash and SmartMedia are both based on it. NAND flash from Toshiba followed in 1989. It has faster erase and write times, higher density, and lower cost per bit than NOR flash, and ten times the endurance. However its I/O interface allows only sequential access to data. This makes it suitable for mass-storage devices such as PC cards and various memory cards, and somewhat less useful for computer memory. NANDbased flash has led to several much smaller removable media formats, MMC, Secure Digital and Memory Stick. Flash memory forms the core of the removable USB interface storage devices known as keydrives. NOR Flash uses hot electron injection for writing and tunnel release for erasing. NAND Flash uses tunnel injection for writing and tunnel release for erasing. Flash memory is erased through a 56 mechanism called Fowler-Nordheim tunneling - a quantum mechanical tunneling process.