Hardware Basics 2024 PDF
Document Details
Uploaded by RationalNihonium
University of Pécs
Dr. Tukora Balázs
Tags
Summary
This document is a presentation on hardware basics, suitable for undergraduate-level engineering and information technology students. It covers topics such as I/O pins, digital logic, circuit families, and communication methods.
Full Transcript
Hardware basics for the subject Programming Autonomous Systems Dr. Tukora Balázs University of Pécs, Faculty of Engineering and Information Technology Contents I/O pins of the Arduino Uno board, Raspberry Pi 3 board, Parallax Basic Stamp 2 (Sumo...
Hardware basics for the subject Programming Autonomous Systems Dr. Tukora Balázs University of Pécs, Faculty of Engineering and Information Technology Contents I/O pins of the Arduino Uno board, Raspberry Pi 3 board, Parallax Basic Stamp 2 (SumoBot) board Digital logic basics Recalling some topics we learnt in Digital Logic Design Digital and analog signals Boolean algebra Time-independent (combinational) logic – logic gates Sequential logic – latches and flip-flops Logic families Logic families and their characteristics – TTL, CMOS Special outputs – Open collector and open drain Some electronic components and their usage Resistors, capacitors, diodes, transistors, LEDs, operational amplifiers, comparators etc… Contents Input How to use switches on digital inputs What is signal bouncing and how to solve it Output Connecting LEDs to outputs with various methods Driving servo motors with PWM Powering How to power microcontrollers Connecting circuits with more than one power sources Controlling high-current/voltage circuits Low battery voltage indicator with operational amplifier and Zener diode Interfacing 3.3V and 5V logics Communication with periferals and other microcontrollers UART, I2C, SPI Analog input and output DAC, ADC, examples Arduino Uno board pinout 5V and 3.3V regulated power out 6 analog input pins ADCs with 10-bit resolution 14 digital input/output pins 5V 0-0.8V: logic 0 2-5V: logic 1 max 20mA/pin providing/sinking max 200mA/all pins pins with PWM capability Communication ports Serial SPI I2C Raspberry Pi 3 Model B+ board pinout 5V and 3.3V regulated power out 40-pin GPIO header (general-purpose input/output) 26 digital I/O pins 3.3V max 16mA/pin providing/sinking max 50mA/all pins pins with PWM capability No analog inputs Communication ports Serial SPI I2C Parallax Basic Stamp 2 (SumoBot) I/O pins Vin=6V, Vdd=5V 16 digital I/O pins 5V Source/sink current per I/O: 20mA/25mA Source/sink current per unit: 40mA/50mA per 8 I/O pins PWM capability Pseudo-sin wave out RC circuit time measurement Dedicated connectors 2 for servo motors (Vin for power) 2 for light sensors 2 for IR proximity sensors Serial / I2C communication Digital logic basics Analog and digital signals Analog signal Continuous signal that represents physical measurements Uses continuous range of values to represent information Digital signal Continuous signal that is a representation of a sequence of discrete values Logic signal is a digital signal where the discrete values have two possible values Exact voltage values are not important, only their class (1 or 0) Simply called „digital” Digital logic circuits Combinational logic (time-independent logic) The output is a pure function of the present input only Sequential logic In which the output depends not only on the present input but also on the history of the input Boolean algebra Variables with two values: 0 (false), Laws Axioms 1 (true) Commutativity of AND, OR 𝐴∙0=0 Basic operations: 𝐴∙𝐵 =𝐵∙𝐴 𝐴∙1=𝐴 Conjunction (AND) Associativity of AND, OR 𝐴+0=𝐴 0∙0=0 𝐴∙ 𝐵∙𝐶 = 𝐴∙𝐵 ∙𝐶 𝐴+1=1 0∙1=0 Distributivity 𝐴 ∙ 𝐴ҧ = 0 1∙0=0 𝐴 𝐵+𝐶 =𝐴∙𝐵+𝐴∙𝐶 𝐴 + 𝐴ҧ = 1 1∙1=1 𝐴+ 𝐵∙𝐶 = 𝐴+𝐵 𝐴+𝐶 𝐴∙𝐴=𝐴 Disjunction (OR) De Morgan’s laws 𝐴+𝐴=𝐴 0+0=0 𝐴 ∙ 𝐵 ∙ 𝐶 = 𝐴ҧ + 𝐵ത + 𝐶ҧ 𝐴Ӗ = 𝐴 0+1=1 𝐴 + 𝐵 + 𝐶 = 𝐴ҧ ∙ 𝐵ത ∙ 𝐶ҧ 1+0=1 1+1=1 Negation (NOT) 0ത =1 1ത = 0 Logic gates A typical combinational logic: 1-bit full adder Adding in binary class system: A 0 B 0 Cin 0 0 Cout 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 = A B Cin Cout = AB + ACin + BCin Basic sequential logic circuits: latches and flip-flops S-R latch D flip-flop J-K flip-flop T flip-flop Circuit families Circuit families TTL CMOS Transistor-Transistor Logic Complementary Metal-Oxide Made with biolar junction transistors Semiconductor Made with field effect transistors, MOSFETs TTL NOT gate CMOS NOT gate Bipolar Junction Transistors (BJT) Let’s recall what bipolar junction transistors are… In digital electronics, they can be considered as current-controlled switches The IB current is much smaller than the controlled IC or IE currents MOSFETS MOSFET stands for metal-oxide semiconductor field-effect transistor Unlike BJT which is ‘current controlled’, the MOSFET is a voltage controlled device. Very high input impedance -> very low (no) control current needed The MOSFET can be damaged by built up electrostatic charges! N-Channel – The source is connected to ground. To turn the MOSFET on, we need to raise the voltage on the gate. To turn it off we need to connect the gate to ground. P-Channel – The source is connected to the power rail (Vcc). In order to allow current to flow the Gate needs to be pulled to ground. To turn it off the gate needs to be pulled to Vcc. Depletion Mode – It requires the Gate-Source voltage ( Vgs ) applied to switch the device “OFF”. Enhancement Mode – The transistor requires a Gate-Source voltage ( Vgs ) applied to switch the device “ON”. Despite the variety, the most commonly used type is N-channel enhancement mode. Circuit families TTL CMOS + supply voltage: Vcc = 5V+-0.25V + supply voltage: Vdd = 3-15V - supply voltage (ground): Vee - supply voltage (ground): Vss Bigger voltage region: ideal for battery-powered gadgets Higher noise immunity Circuit families TTL CMOS Approximately constant (some mW) Power consumption rises with power dissipation (consumption) frequency, very low at unchanging conditions (10nW-) That’s why no power switch is needed for the TV remote controller TTL CMOS Circuit families – conclusions, remarks If there are no special requirements (e.g. high frequency), CMOS is a better choice over TTL 3.3V circuits consume less power than 5V circuits, that’s why modern chips use 3.3V (or less), but the 5V TTL level has remained as an I/O standard CMOS ICs work on the 5V TTL level, but TTL and CMOS circuits cannot be connected directly because of the different voltage regions (see later) 3.3V low voltage TTL (LVTTL) also exists Circuit families – most popular TTL CMOS 74xx (the original) 74HCxx 74LSxx (Low-Power Schottky) 2-6V, 8ns propagation delay, 2mW / gate, up to 25MHz, 8ns propagation delay, 7400 NAND gate fan-out: 50+, up to 35MHz, the outputs can provide about 20mA fan-out: 10, 1mA needed on the inputs, 40xx outputs can sink up to 16mA (enough to light an 3-15V, LED), but they can source only about 2mA. To 30ns propagation delay, switch larger currents you can connect a up to 1MHz, transistor. fan-out: 50 the maximum current on outputs is about 5mA with a 6V supply, or 10mA with a 9V supply (just enough to light an LED) Special outputs of TTL and CMOS circuits Open Collector (TTL) or Open Drain (CMOS) outputs The collector (drain) of the output transistor is left free – we have to „finish” it Logic level shifter from 5V to 12V Wired AND connection Input Switch on digital inputs We switch between logic 0 and 1 (0V and 3.3V, 5V) An input, if not connected to anything, is „floating” and has no particular logical state Positiv logic: switch on->1 off->0 Negativ logic: switch on->0 off->1 The resistor protects the battery from shortcut Internal pull-up resistor Arduino and Rapsberry Pi have internal pull-up resistors on their digital inputs -> no need to use external resistor -> simply connect the switch between the input and the GND Must be enabled from code pinMode(XXX, INPUT_PULLUP); on Arduino Switch bounce When the contact surfaces of a switch are getting close to each other, sparks form between them Instead of a single transition, a lot of pulses appear, the signal is „bouncing”. Debouncing With an S-R latch (two NAND gates) and an SPDT (Single Pole Double Throw) switch Debouncing By means of an RC low-pass filter and a Schmitt-trigger inverter We charge the capacitor when open the switch and discharge it when close the switch -> this smoothes out the signal The Schmitt-trigger inverter switches on/off at different levels -> this cleans up the remaining Input/output voltage without hysteresis noise Schmitt-triggered input/output (not inverted) Software debounce Use the Basic Stamp „Button” command – it arranges everything Write your own solution if using Arduino or Rasberry Pi Check the switch periodically having a time between reads that is greater than the maximum expected bounce time Wait till the disappearing of the bounce whenever the switch changes its state while True: inputValue = GPIO.input(18) if (inputValue == False): do something time.sleep(0.3) Output Using LEDs MUST NOT connect an LED to the power without current limiting resistor! It’s a diode, not a lamp with internal resistance The amount of „forward voltage” drops in it when operated at a certain current Calculating the resistance: 𝑉 = 5𝑉 𝐼𝐿𝐸𝐷,𝑡𝑦𝑝 = 20𝑚𝐴 𝑉𝐿𝐸𝐷,𝑡𝑦𝑝 = 2𝑉 𝑉𝑅 5𝑉−2𝑉 3𝑉 𝑅= = = = 150Ω 𝐼 20𝑚𝐴 0.02𝐴 For safety chose 220Ω Or try an online calculator Resistor color codes Standard resistor values E12 series 10% tolerance 1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2 x1Ω, x10Ω, x100Ω etc. E24 series 5% tolerance 1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1 x1Ω, x10Ω, x100Ω etc. E48 (2%), E96 (1%), E192 (0.5%) with more and more values LED on digital output Directly connected, if enough current can be sourced/sunk on the output The microcontroller „sinks” current The microcontroller „sources” current LED on digital output If more current is needed, insert a driver circuit… 74HC04 LED on digital output …or use a transistor to switch the LED on/off We can also use up the output transistor of an open collector output 2N2222 LED on digital output For even more current (some Amps) use a MOSFET (but 240V AC needs a relay!) A simple example circuit with switch, gate and LED Either the microcontroller or the switch can turn on the LED Via the P1 input pin we can monitor the status of the circuit (input) 7 segment LED display Displays numbers 0..9 Connect each LED to an output, or use a „BCD to 7 segment decoder” LED light intensity adjusting using PWM PWM = Pulse Width Modulation We cannot adjust the current of a digital output but the average current with turning on/off it repeatedly The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Servo motor control with PWM A servo motor is a standard DC motor with a reduction gear and an inertial feedback control Three inputs: Vcc (5V+), GND, Control (5V) With PWM we can turn the shaft to a desired direction. This direction is hold while the control pulses are kept repeating The width of the pulse determines the turning angle There are angle limits, e.g. +-60 degrees or +-90 degrees Continuous rotation servo: This servo rotates forward or backwards instead of moving to a position. The pulse width determines the speed: 1ms: full speed backwards 2ms: full speed forward Powering Powering Our devices need regulated 5V Via the USB port The Raspberry Pi requires 2A, so a 0.5A USB 2.0 PC port is not enough (USB 3.2 type C: 3A) A 2.5A power supply adapter is recommended, but the power consumption depends on the built circuit too. Using a 7-12V power supply or battery The 12V power jack on the Arduino and Basic Stamp 2 is connected to a built-in 5V regulator (that converts the 12V to 5V) For Raspberry Pi use a DC/DC stepdown converter, like A1385 (6-23V to 5V, 3A) If you need 5V to your project, up to 1.5A you can use a 7805 power regulator (7-25V to 5V) Be careful with the heat! If Vin=12V, Iout=1A then P=(12-5)*1=7W power dissipates. Use a heat sink. Multiple power sources – normal cases If multiple power supplies are used (no matter if the voltages are the same or not) keep the positive supply lines separated, connect the ground from each power source. Multiple power sources – extreme cases If you need to completely isolate the controlling and controlled curcuits (e.g. because of high current), separate the grounds too and use an opto-isolator 240V control To switch a 240V device, use a relay or solid state relay (SSR) High voltage is generated by the coil when the current flow is interrupted. 240V ~ The diode avoids damaging the transistor (lets the current flow away) Relay Battery low voltage level indicator An operational amplifier (op-amp) in open-loop mode We divide the input voltage by the potentiometer switches between the two saturated states: +Vcc, – If R*=80Kohm and the battery voltage drops below Vcc 7V, Vout turns to 0V and the LED starts lighting R* Vout A Zener diode in the reverse mode, starts conducting when a certain specified voltage (VZ) is reached -> it „keeps” VZ Interfacing Interfacing 3.3V and 5V circuits Different standard voltage levels on inputs / outputs Interfacing 3.3V and 5V circuits The input reads the state of output properly if the input high region includes the output high region the input low region includes the output low region We can connect the 3.3V outputs directly to 5V TTL inputs… but in other cases we have to check the levels… and shift them if necessary. There are several ways to do it. Interfacing 3.3V and 5V circuits Bidirectional level converter (one direction at a time!) 3.3V to 5V 3.3V pin low -> S low, G high -> MOSFET on -> 5.5V pin low 3.3V pin high -> S, G high -> MOSFET off -> 5.5V pin pulled up to high by the resistor 5V to 3.3V 5V pin low -> 3.3V pin pulled to 0.7V by the substrate diode -> MOSFET on -> 3.3V pin low 5V pin high -> S pulled up to high, MOSFET off Interfacing 3.3V and 5V circuits Use a gate with open drain output… …or a level converter IC or board e.g. for the I2C bus …or search the internet for various solutions https://www.newark.com/pdfs/techarticles/microchip/3_3vto5vAnalogTipsnTricksBrchr.pdf https://next-hack.com/index.php/2017/09/15/how-to-interface-a-5v-output-to-a-3-3v- input/ etc. Communication Communication with other devices With digital signals via GPIO pins Asynchronous serial communication with UART (universal asynchronous receiver- transmitter) Simply called „serial communication” Communication with other devices Serial Peripheral Interface (SPI) Synchronous, full duplex Bus-like connection of one master and one or more slaves MISO (Master In Slave Out) - A line for sending data to the Master device MOSI (Master Out Slave In) - The Master line for sending data to peripheral devices SCK (Serial Clock) - A clock signal generated by the Master device to synchronize data transmission. The SS (Slave Select) pins determine which device the Master is currently communicating with. Not needed if we’ve got only one slave Communication with other devices I2C [I-squared-C] or I2C [I-two-C] Inter- Integrated Circuit Bus Short-distance connection, typically on a single circuit board SCL is the clock line which is designed to synchronize data transfers. SDA is the line used to transmit data. Each device on the I2C bus has a unique address, up to 255 devices can be connected on the same bus. Pullup resistors needed (Open Drain) Built-in on Arduino board Analog Analog input Arduino has analog inputs with analog-to-digital converters (ADC) Raspberry Pi: Use an external ADC, like the MCP3008 8 channels, 10bit, SPI communication Analog input examples Light intensity detection with photo Temperature measuring with the resistor (photocell) TMP36 sensor PDV-P8001 No additional components needed Resistance range: 200KΩ (dark) to 10KΩ V+ = 2.7V to 5.5V (10 lux brightness) 10K Analog output Use a digital-to-analog converter (DAC) MCP4725: 1 channel, 12bit, I2C communication The cheapest way to create analog signal: build a resistor ladder Pin0 (right): the most significant bit (MSB), Pin7 (left): the least significant bit (LSB) The analog voltage may drop if we drive another circuit. That’s why we use a voltage follower op.amp. LM324 References References The Microcontroller Application Cookbook by Matt Gilliland, Woodglen Press, 2000 Industrial Control Student Workbook, Parallax Inc, 1999 and countless sites, tutorials and pictures on the Internet…