PV198 - Pulse Width Modulation One-chip Controllers Dávid Danaj, Marek Vrbka Faculty of Informatics, Masaryk University Content Content Overview Modes of Operation Tasks Homework D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 2 / 15 Overview Intro Switch the branch! D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 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 D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 4 / 15 Overview What is it used for Motol control Audio amplifiers Digital lightning D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 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 D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 6 / 15 Overview FRDM-K66F PWM capabilities FlexTimer Module (FTM) 4 instances 2 - 8 channels Timer/PWM Module (TPM) 2 instances 2 channels D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 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 D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 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 D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 9 / 15 Modes of Operation Output Compare Generate timed pulses with programmable position, polarity, duration and frequency D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 10 / 15 Modes of Operation Edge-Aligned PWM Leading edge is aligned with the beginning of the period D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 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 D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 12 / 15 Tasks Tasks Create an application that turns on Blue LED with 20% intensity Use TPM or FTM peripheral Update your application to turn on Green and Red LED with 20% intensity (notice that TPM is not available) D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 13 / 15 Tasks Stepper motor demo Which mode can we use to get 4 signals as shown in the picture? D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 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 D. Danaj, M. Vrbka ·PV198 - Pulse Width Modulation · 15 / 15