Lec_9 Analog Interfacing PDF
Document Details
Uploaded by StrongNovaculite3414
Tags
Summary
This document is lecture notes about analog interfacing in embedded systems. It discusses concepts including analog and digital signals, analog interfacing, and signal conditioning. The document also provides examples of microcontroller components and circuits for signal conversion and conditioning.
Full Transcript
CSE211s Introduction to Embedded Systems Fall 2024 Analog Interfacing Analog Interfacing Overview Analog and Digital Signals Basics of ADC & DAC (ATD & DTA) Conversion Analog Interfacing Signal Conditioning Example...
CSE211s Introduction to Embedded Systems Fall 2024 Analog Interfacing Analog Interfacing Overview Analog and Digital Signals Basics of ADC & DAC (ATD & DTA) Conversion Analog Interfacing Signal Conditioning Example: STM32F401RE Analog Module (only ADC) Typical Microcontroller Components MCU ROM Digital IO LEDs – LCDs Switches,relays The CPU Keypads … Internet RAM Analog IO Sensors - Actuators Wired/Wireless Clocks Communication Timer(s) Limit switches – UART SPI – I2C Photo detectors Bleutooth, Wi-Fi – PWM … Other Digital Ethernet Devices Analog Signals and Embedded Systems ▪ Embedded systems often need to measure values of physical variables which commonly are time-continuous. ▪ Transducers measuring physical variables produce analog values, usually in volt, not suitable for digital computers. Temperature Pressure Other – Thermometer (do you have a fever?) – Blood pressure monitor ̶ Touch screen – Thermostat in fridges and freezers – Altimeter controller – Car engine cooler – Car engine controller ̶ ECG, EEG – Chemical reaction monitor – Scuba dive computer ̶ Breathalyzer – Tsunami detector Light/infrared/ultraviolet intensity – Digital camera Acceleration – IR remote control receiver – Air bag controller – Tanning bed – Vehicle stability – UV monitor – Video game remote Rotary position Mechanical strain – Wind gauge – Knobs 4 Analog & Digital Signals Q: Signals in practice are analog so why converting signals to digital form? A: Digital computers made it possible to apply sophisticated numerical algorithms in many fields like automatic control and signal processing that was not possible by analog electronics. Digital signals are suitable for: ▪ Storage ▪ Processing ▪ Communications Continuous/Discrete-time & Digital Signals 1.25 Analog signal x(t): Discrete 1 Digital Defined for all real t: 𝑡 ∈ ℛ Continuous 0.75 Discrete-time signal 𝒙(𝒏): 0.5 Defined only at discrete time instants 𝑡 = 𝑛𝑇 0.25 where 𝑛 integer 𝑛 ∈ ℤ, and 𝑇 is the constant 0 sampling time. -0.25 𝑥(𝑛) = 𝑥(𝑛𝑇) -0.5 Digital signal xd(n): -0.75 When x(n) takes only discrete values i.e., -1 quantized because of the finite number of digits -1.25 0 1 2 3 4 5 6 7 8 9 10 used, the signal is called digital signal. k A Digital Control Loop MCU A digital controller performs the control action through three steps: 1. Sample the system variable(s), usually the process output(s), through ATD (, ADC, or A/D). 2. Process the measured sample(s) and compute the required control action according to the built-in control algorithm based on the given system model and control specifications. 3. Output the control action to the system actuator(s) through DTA (, DAC, or D/A) ATD/DTA Conversion Analog Value: Determines the range of operation 𝑉𝐻 Range: 𝑉𝐿 → 𝑉𝐻 Polarity: 𝑉𝐿& 𝑉𝐻 same sign ⎯→ Unipolar different signs → Bipolar Δ Digital Value: Number of bits: 𝑛 Number of levels: 𝑁 = 2𝑛 If bipolar: 2’s complement or sign & magnitude 𝑉𝐿 Resolution: The ability to differentiate between very close values. 𝑉𝐻 − 𝑉𝐿 Range Range Δ= 𝑛 = 𝑛 = Measured as: 2 −1 2 −1 𝑁−1 ATD: The smallest sensed change in the analog input reflected as a change of ±1 of the output binary value As the resolution 𝛿 is defined relative to the range: Δ 1 relative to the range 𝛿 = , then 𝛿 = Range 2𝑛 −1 DTA: The change in the analog output corresponding to a change of ±1 of the input binary value relative to Resolution simply is the number of bits 𝑛. the range ATD Converter Analog reference voltages V VL H Start SC Conversion End of 𝑽+ 𝑰𝑵 EOC Conversion Analog B0 input 𝑽− 𝑰𝑵 ATD.. Digital. output Bn-1 The SC signal triggers the conversion process. Clock When conversion is complete, the EOC is asserted to indicate that the digital output is ready. DTA Converter Analog reference voltages VH VL Write 8 8 6 B0 6 4 VOUT Internal Latch 4 2 0 0 1 2 3 4 k 5 6 7 8 9 DTA.. 2 0 0 2 4 k 6 8 10 Analog Digital output. input Bn-1 Every Write pulse stores the new binary input value to the DTA latch, so its output is held constant until the next Write pulse; Zero-Order-Hold ZOH. ATD Conversion Example Analog input voltage value: If the digital value from the ATD is D, then its analog input is: 𝑉𝐻 − 𝑉𝐿 𝑉𝐼𝑁 = 𝑉𝐿 + × 𝐷 = 𝑉𝐿 + Δ × 𝐷 2𝑛 − 1 If 𝑉𝐿 is zero, then 𝑉𝐼𝑁 = Δ × 𝐷. Example: A 12-bit A/D converter with reference voltages 𝑉𝐿 = 0.5𝑉 and 𝑉𝐻 = 3.5𝑉, what is the corresponding input voltage for digital value 100? Solution: 3 𝑉𝐼𝑁 = 0.5 + 12 × 100 = 0.573𝑉 2 −1 Signal Conditioning Circuit Usually, the sensor’s output voltage range V1→ V2 differs from the range of the ATD VL→ VH. Example: A thermocouple is used to measure water temperature from 0 to 100oC. It outputs voltage from 10 to 100 mV corresponding to this water temperature range. The 8-bit ATD has input range 0 to 10 V. In such case, the maximum input voltage to the ATD is 0.1 V which is one hundredth its full range. Only the least three bits may change corresponding to the full range of temperature change, resulting in unacceptable measurement. So, we need an analog circuit to translate the sensors output of millivolts to fit that of the ATD to make use of the full range of the ATD. This range-translation circuit is a called signal conditioning circuits. The sensor’s output in some infrequent cases comes in the form of current or charge, so we need to convert it to voltage to suit the ATD input. Signal Conditioning Circuit (Range Translation) Signal range translation formula in general contains gain and bias. 𝑉𝐼𝑁 Signal 𝑉𝑂𝑈𝑇 Sensor Conditioning ATD 𝑉1 → 𝑉2 Circuit 𝑉𝐿 → 𝑉𝐻 The signal conditioning circuit input from sensor is 𝑉𝐼𝑁 in the range 𝑉1 → 𝑉2 , and its corresponding output is 𝑉𝑂𝑈𝑇 in the range 𝑉𝐿 → 𝑉𝐻 , 𝑉𝐻 − 𝑉𝐿 The translation formula: 𝑉𝑂𝑈𝑇 = 𝑉𝐿 + × (𝑉𝐼𝑁 − 𝑉1 ) = 𝐴𝑉𝐼𝑁 − 𝐴𝑉1 − 𝑉𝐿 𝑉2 − 𝑉1 ATD Range 𝑉𝐻 − 𝑉𝐿 The amplifier gain is: 𝐴= = Sensor′s Range 𝑉2 − 𝑉1 The bias is: 𝐵 = 𝐴𝑉1 − 𝑉𝐿 Signal Conditioning: Amplification & Bias 25 Sensor output After amplification After bias 20 15 Volts 10 5 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Sensed Variable Inputs to ADC ▪ Single-Ended ▪ Input voltage is referenced to ground. ▪ Differential ▪ Use two inputs, and measure difference between them Very good noise immunity Some sensors offer differential outputs e.g., Wheatstone Bridge ▪ Multiplexing ▪ Typically share a single ADC among multiple inputs ▪ Need to select an input, allow time to settle before sampling Select Inputs ▪ Signal Conditioning ▪ Amplify and filter input signal ▪ Protect against out-of-range inputs with clamping diodes 17 Sample and Hold Devices ▪ Some ATD converters require the input analog signal to be held constant during conversion e.g., successive approximation devices. Sampling switch Output Signal Analog Input Hold Close switch to sample Signal Capacitor signal value. Open switch to hold last signal value. ▪ A “sample and hold” circuit performs this operation ▪ Many A/D converters include a sample and hold circuit 18 MCU Analog Modules Features ATD: DTA: 1) Available number of on-chip ATD 1) Available number of on-chip DTA modules modules and the number of multiplexed input signals 2) Available number of analog input pins 2) Available number of analog output pins 3) Range of the analog input signal 3) Range of the analog output signal 4) Resolution (number of bits) 4) Resolution (number of bits) 5) Single-ended/Differential inputs 6) Interrupt capabilities 5) Interrupt capabilities STM32F401RE ANALOG MODULE 20 STM32F401RE Analog Module The STM32F401RE has one ADC (ADC1), and no DAC. Topic Outlines: Features Initialization & Configuration Operation Example application Reset State Right after reset: All peripherals are disabled. The alternate functions are not active. The IO ports are configured in input floating mode. 22 STM32F401RE ADC Features The STM32F401RE has a successive approximation analog-to-digital converter with the following features: Resolution: Configurable resolution: 12-bit, 10-bit, 8-bit or 6-bit Range: VREF– ≤ VIN ≤ VREF+ : 1.8 V ≤ VREF+ ≤ VDDA VREF – = VSSA Number of inputs: Up to 16 external analog input channels. (+Three internal sources for temperature, battery voltage, …) Sampling time: Programmable sampling time Trigger Source: Trigger options ̶ By software ̶ By hardware A signal from a timer: TIM1, TIM2, TIM3, TIM4 or TIM5 An external line EXTI line11 Digital result: The 12-, 10-, 8- or 6-bit result of the ADC is stored into a left or right-aligned (justified) 16-bit data register. Interrupt generation capability: At the end of conversion EOC, or voltage is outside the programmed thresholds. Conversion mode: Single-shot, continuous, or scan mode (automatic conversion is performed on a selected group of analog inputs.) DMA capability: The ADC can be served by the DMA controller. Modes of Conversion Single conversion mode: (CONT bit in ADC_CR2 is 0) Single conversion mode the ADC does one conversion which is started by software or hardware. Continuous conversion mode: (CONT bit in ADC_CR2 is 1) In continuous conversion mode, the ADC starts a new conversion as soon as it finishes one. A conversion is started by software or hardware. Scan mode: (SCAN bit in the ADC_CR1 is 1) This mode is used to scan a group of analog channels. 25 Initialization & Configuration The following steps are example of initializing and configuring the ADC for a single conversion on a single channel: 1. Power on the ADC. (Set the ADON bit in the ADC_CR2 register.) 2. Select GPIO for the port and configure the port pin for analog input. (Set the value of the two bits corresponding to the pin in the port’s mode register GPIOx_MODER to 11) The 16 available pins for analog input are PORTA0-7, PORTB1,2, and PORTC0-5 only. 3. Select single conversion mode (Set the continuous bit CONT to 0, bit1 in ADC_CR2) 4. Select one conversion, (Set channel sequence length field L[3:0] to 0000, bits 23: 20 in ADC_SQR1) 5. Select input channel. (Write the channel number (0 to 15) in ADC_SQRx, SQ1[4:0]; 1st conversion in the sequence) 6. Select trigger source. ̶ By software: (Set the SWSTART bit in the ADC_CR2 register.) ̶ By hardware: (Selected by a nonzero value in the EXTEN[1:0] in ADC_CR2, event is selected by EXTSEL[3:0]) Once the ADC is triggered either by software or hardware, the ADC starts conversion and when complete it asserts the end of conversion flag (EOC) and places the digital value in the ADC_DR register 26 Configuration Optional Programmable sampling time: The ADC samples the input voltage for a number of ADCCLK cycles selected using the SMP[2:0] bits in the ADC_SMPR1 and ADC_SMPR2 registers. Each channel can be sampled with a different sampling time. The total conversion time is calculated as follows: Tconv = Sampling time + 12 cycles Example: With ADCCLK = 30 MHz and sampling time = 3 cycles: Tconv = 3 + 12 = 15 cycles = 0.5 μs with clock at 60 MHz External trigger (hardware): A signal from a timer: TIM1, TIM2, TIM3, TIM4 or TIM5 timer An external line EXTI line11 27 Operation The conversion starts by either: 1. Software: By setting the SWSTART bit in the ADC_CR2 register 2. Hardware: By external trigger from either: ̶ Timer capture ̶ EXTI line, if the EXTEN[1:0] control bits are different from 0. Once the conversion of the selected channel is complete: The converted data are stored into the 16-bit data register ADC_DR. Right alignment of 12-bit data Left alignment of 12-bit data The end of conversion flag EOC (ADC status register ADC_SR bit1) is set. – An interrupt is generated if the end of conversion interrupt enable EOCIE (ADC_CR1 bit7) is set. Mbed Analog Input Example This program turns on a led (alarm) if the analog input exceeds 0.3V. #include "mbed.h" AnalogIn ain(Analog Input Pin); //analog input pin initialization DigitalOut led(Output Pin); int main() { while (1){ if(ain > 0.3) { led = 1; } else { led = 0; } } } Mbed Analog Output Example This program outputs a 10-step ramp (for loop) with f = 1kHz. (10kHz for 1 step with 10 steps for the ramp = 1kHz total signal frequency). The output port is again initialized in the second line of the program. #include "mbed.h" AnalogOut signal(Analog Output Pin); //analog output pin initialization int main() { while(1) { for(float i=0.0; i