PV198 - Pulse Width Modulation 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 4/2023 Content Content Overview Modes of Operation Tasks Homework ·PV198 - Pulse Width Modulation ·4/2023 2 / 15 Overview Intro Switch the branch to Week_04! Discussion of HW3 ·PV198 - Pulse Width Modulation ·4/2023 3 / 15 Overview What is PWM PWM – Pulse Width Modulation A method of reducing the average power delivered by an electrical signal, by effectively chopping it up into discrete parts ·PV198 - Pulse Width Modulation ·4/2023 4 / 15 Overview What is it used for Motor control Audio amplifiers Digital lightning ·PV198 - Pulse Width Modulation ·4/2023 5 / 15 Overview How does it work Switching fast enough for the application Changing duty cycle https://commons.wikimedia.org/wiki/File:Duty_Cycle_Examples.png ·PV198 - Pulse Width Modulation ·4/2023 6 / 15 Overview FRDM-K66F PWM capabilities FlexTimer Module (FTM) 4 instances 2-8 channels Timer/PWM Module (TPM) 2 instances 2 channels ·PV198 - Pulse Width Modulation ·4/2023 7 / 15 Modes of Operation Timer/PWM Module (TPM) Modes of operation: Input capture Output compare Edge-Aligned PWM Center-Aligned PWM Combined PWM Combine Input Capture ·PV198 - Pulse Width Modulation ·4/2023 8 / 15 Modes of Operation Input Capture Detects edge in the input signal Configurable rising/falling edge detection Edge sets interrupt flag Read precise time from counter Example: ultrasonic distance sensor demo ·PV198 - Pulse Width Modulation ·4/2023 9 / 15 Modes of Operation Output Compare Generate timed pulses with programmable position, polarity, duration and frequency ·PV198 - Pulse Width Modulation ·4/2023 10 / 15 Modes of Operation Edge-Aligned PWM Leading edge is aligned with the beginning of the period ·PV198 - Pulse Width Modulation ·4/2023 11 / 15 Modes of Operation Center-Aligned PWM Counts up until it reaches MOD and then counts down until it reaches zero The pulse width center is when TPM counter = 0 ·PV198 - Pulse Width Modulation ·4/2023 12 / 15 Tasks Tasks 1. Create an application that turns on Blue LED with 20% intensity Use TPM or FTM peripheral 2. Update your application to turn on Green and Red LED with 20% intensity (notice that TPM is not available) ·PV198 - Pulse Width Modulation ·4/2023 13 / 15 Tasks Stepper motor demo Which mode can we use to get 4 signals as shown in the picture? ·PV198 - Pulse Width Modulation ·4/2023 14 / 15 Homework Homework - Cycle trough HSV Hue color spectrum Write three functions that set intensity for each color Download HSV_RGB.h from the study materials Periodically iterate over all colors updating: H = (H + 1) % 360 Don’t be too fast, if a whole cycle takes less than 10 seconds, tests might not pass If a cycle takes longer than a minute, tests might not pass ·PV198 - Pulse Width Modulation ·4/2023 15 / 15