PV198 - Analog to Digital Conversion One-chip Controllers Dávid Danaj, Marek Vrbka Faculty of Informatics, Masaryk University Content Content Overview Demo Theory Successive Approximation Joystick Application Homework D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 2 / 23 Overview Intro Switch the branch! D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 3 / 23 Overview What is ADC ADC - Analog to Digital Converrter Convert analog signal into digital values D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 4 / 23 Overview What is it used for Everything that needs to transfer analog values into digital values Audio Sensors Video D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 5 / 23 Demo Demo - Heartbeat sensor D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 6 / 23 Demo Demo - Heartbeat sensor D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 7 / 23 Theory How does it work https://www.allaboutcircuits.com/technical-articles/ understanding-the-dynamic-range-specification-of-an-ADC/ D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 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 D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 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 D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 10 / 23 Theory Sampling Rate Nyquist-Shannon theorem ADC sampling frequency must be at least twice the analog signal frequency D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 11 / 23 Theory Dynamic Range D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 12 / 23 Successive Approximation Linear Successive Approximation Algorithm D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 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 D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 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 D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 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 D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 16 / 23 Joystick Joystick D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 17 / 23 Joystick Joystick DO NOT USE 5V D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 18 / 23 Joystick Joystick - Connection (Easy) D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 19 / 23 Joystick Joystick - Connection (Difficult) D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 20 / 23 Application Application Tasks Create an application that reads position of the joystick (both axes) using ADC0 and ADC1 Print position to terminal Write periodic check into while loop if measurement is finished Use PIT to initialize read only once a second Either Write ADC read only using interrupts React to joystick button press D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 21 / 23 Application Steps Initialize (MCUXpresso Configuration Tools might help here) Pins Clocks Peripherals (configure ADC0 and ADC1) Write application code D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 22 / 23 Homework Homework - Use joystick to control LEDs Only use ADC1 peripheral with multiple channels Warning: ADC has special handling of interrupt flags Use the same connection as shown in the difficult slide PTB7 controls green LED, PTB6 controls red LED D. Danaj, M. Vrbka ·PV198 - Analog to Digital Conversion · 23 / 23