PV198 - Analog to Digital Conversion One-chip Controllers Daniel Dlhopolček, Marek Vrbka, Jan Koniarik, Oldřich Pecák, Tomáš Rohlínek, Ján Labuda, Jan Horáček, Matúš Škvarla Faculty of Informatics, Masaryk University 5/2023 Content Content Overview Demo Theory Successive Approximation Joystick Application Homework ·PV198 - Analog to Digital Conversion ·5/2023 2 / 23 Overview Intro Switch the branch to Week_05! Discussion of HW4 ·PV198 - Analog to Digital Conversion ·5/2023 3 / 23 Overview What is ADC ADC - Analog to Digital Converter Convert analog signal into digital values ·PV198 - Analog to Digital Conversion ·5/2023 4 / 23 Overview What is it used for Everything that needs to transfer analog values into digital values Audio Sensors Video ·PV198 - Analog to Digital Conversion ·5/2023 5 / 23 Demo Demo - Heartbeat sensor ·PV198 - Analog to Digital Conversion ·5/2023 6 / 23 Demo Demo - Heartbeat sensor ·PV198 - Analog to Digital Conversion ·5/2023 7 / 23 Theory How does it work https://www.allaboutcircuits.com/technical-articles/ understanding-the-dynamic-range-specification-of-an-ADC/ ·PV198 - Analog to Digital Conversion ·5/2023 8 / 23 Theory Sampling resolution Smallest incremental voltage that can be recognized and thus causes a change in the digital output Expressed as the number of bits output by the ADC https://www.electricaltechnology.org/2019/02/analog-to-digital-converter-adc.html ·PV198 - Analog to Digital Conversion ·5/2023 9 / 23 Theory Quantization Error Difference between analog value and rounded digital value (rounding error) Change in analog value smaller than the step of the digital value is ignored The quantization error is 0.5 least significant bit for the ADC ·PV198 - Analog to Digital Conversion ·5/2023 10 / 23 Theory Sampling Rate Nyquist-Shannon theorem ADC sampling frequency must be at least twice the analog signal frequency ·PV198 - Analog to Digital Conversion ·5/2023 11 / 23 Theory Dynamic Range ·PV198 - Analog to Digital Conversion ·5/2023 12 / 23 Successive Approximation Linear Successive Approximation Algorithm ·PV198 - Analog to Digital Conversion ·5/2023 13 / 23 Successive Approximation Linear Successive Approximation Algorithm Vin = 2.1V Vref = 3.3V 3-bit resolution Step Digital code DAC output Output Comparator Digital output 1 100 1.65V 1 1|00 2 110 2.475V 0 10|0 3 101 2.0625V 1 101 ·PV198 - Analog to Digital Conversion ·5/2023 14 / 23 Successive Approximation Linear Successive Approximation Algorithm Vin = 1.16V Vref = 3.3V 5-bit resolution Step Digital code DAC output Output Comparator Digital output 1 2 3 4 5 ·PV198 - Analog to Digital Conversion ·5/2023 15 / 23 Successive Approximation FRDM-K66F ADC Linear successive approximation algorithm with up to 16-bit resolution Single or continuous conversion Can work in low-power modes HW trigger to start conversion HW average function Conversion complete interrupt DMA support ADC16 - MCUXpresso SDK API Reference Manual ·PV198 - Analog to Digital Conversion ·5/2023 16 / 23 Joystick Joystick ·PV198 - Analog to Digital Conversion ·5/2023 17 / 23 Joystick Joystick DO NOT USE 5V ·PV198 - Analog to Digital Conversion ·5/2023 18 / 23 Joystick Joystick - Connection (2 ADCs) ·PV198 - Analog to Digital Conversion ·5/2023 19 / 23 Joystick Joystick - Connection (1 ADC, 2 channels) ·PV198 - Analog to Digital Conversion ·5/2023 20 / 23 Application Application Task Create an application that reads position of the joystick (both axes) using ADC0 and ADC1 Print position to terminal Initialize read only once a second Use periodic check in main while loop to detect finished measurement When finished: Read ADC using interrupts React to joystick button press Warning ADC16_SetChannelConfig triggers a conversion. ·PV198 - Analog to Digital Conversion ·5/2023 21 / 23 Application Steps 1. Initialize (MCUXpresso Configuration Tools) 1.1 Pins 1.2 (Clocks) 1.3 Peripherals (ADC0, ADC1) 2. Write application code ·PV198 - Analog to Digital Conversion ·5/2023 22 / 23 Homework Homework Use joystick to control LED’s brightness Only use ADC1 peripheral with multiple channels Use the 1 ADC, 2 channels connection X-axis (PTB7) controls green LED Y-axis (PTB6) controls red LED ADC value 0 = 0 % duty cycle (= LED OFF) ADC value MAX = 100 % duty cycle (= LED fully ON) Warning ADC has special handling of interrupt flags! ·PV198 - Analog to Digital Conversion ·5/2023 23 / 23