MICROPROCESSOR TECHNICS II

Similar documents
Course Introduction. Content 20 pages 3 questions. Learning Time 30 minutes

Microcontroller: Timers, ADC

Microprocessor & Interfacing Lecture Programmable Interval Timer

I hope you have completed Part 2 of the Experiment and is ready for Part 3.

Topics Introduction to Microprocessors

Hello, and welcome to this presentation of the FlexTimer or FTM module for Kinetis K series MCUs. In this session, you ll learn about the FTM, its

Designing with STM32F3x

Sensorless PMSM Field-Oriented Control on Kinetis KV and KE

CprE 288 Introduction to Embedded Systems (Output Compare and PWM) Instructors: Dr. Phillip Jones

DASL 120 Introduction to Microcontrollers

Peripheral Link Driver for ADSP In Embedded Control Application

Hardware Flags. and the RTI system. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Hello and welcome to this Renesas Interactive Course that provides an overview of the timers found on RL78 MCUs.

LM4: The timer unit of the MC9S12DP256B/C

Iowa State University Electrical and Computer Engineering. E E 452. Electric Machines and Power Electronic Drives

Hashemite University Faculty of Engineering Mechatronics Engineering Department. Microprocessors and Microcontrollers Laboratory

System Board 6219 MAXREFDES89#: MAX14871 Full-Bridge DC Motor Driver MBED Shield

Training Schedule. Robotic System Design using Arduino Platform

ARDUINO / GENUINO. start as professional. short course in a book. faculty of engineering technology

EE 314 Spring 2003 Microprocessor Systems

ME 461 Laboratory #2 Timers and Pulse-Width Modulation

ME 461 Laboratory #3 Analog-to-Digital Conversion

Embedded Robotics. Software Development & Education Center

MICROPROCESSORS A (17.383) Fall Lecture Outline

νµθωερτψυιοπασδφγηϕκλζξχϖβνµθωερτ ψυιοπασδφγηϕκλζξχϖβνµθωερτψυιοπα σδφγηϕκλζξχϖβνµθωερτψυιοπασδφγηϕκ χϖβνµθωερτψυιοπασδφγηϕκλζξχϖβνµθ

ECE251: Tuesday October 3 0

SPI Slave to PWM Generation

EMBEDDED SYSTEM DESIGN FOR A DIGITAL MULTIMETER USING MOTOROLA HCS12 MICROCONTROLLER

Lab 5 Timer Module PWM ReadMeFirst

Using the HCS08 TPM Module In Motor Control Applications

MICROCONTROLLER TUTORIAL II TIMERS

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

32-bit ARM Cortex-M0, Cortex-M3 and Cortex-M4F microcontrollers

Measuring Distance Using Sound

µtasker Document µtasker Hardware Timers

Grundlagen Microcontroller Counter/Timer. Günther Gridling Bettina Weiss

COSC 3215 Embedded Systems Laboratory

ME 461 Laboratory #5 Characterization and Control of PMDC Motors

M16C/26 APPLICATION NOTE. Using The M16C/26 Timer in PWM Mode. 1.0 Abstract. 2.0 Introduction

Low Cost PMSM Sensorless Field-Oriented Control Based on KE02

Timer A (0 and 1) and PWM EE3376

uc Crash Course Whats is covered in this lecture Joshua Childs Joshua Hartman A. A. Arroyo 9/7/10

ELCT 912: Advanced Embedded Systems

Lab 7 ADC Apr

EE251: Thursday October 25

Hello, and welcome to this presentation of the STM32 Digital Filter for Sigma-Delta modulators interface. The features of this interface, which

8253 functions ( General overview )

Real Time Embedded Systems. Lecture 1 January 17, 2012

EE 308 Lab Spring 2009

Roland Kammerer. 13. October 2010

GUJARAT TECHNOLOGICAL UNIVERSITY

EE445L Fall 2014 Quiz 2A Page 1 of 5

EE445L Fall 2015 Quiz 2 Page 1 of 5

5 Channel Multifunctional PWM Controller. HomLiCon LCH5T. Technical Specifications

EE445L Fall 2012 Final Version B Page 1 of 7

Monitoring Temperature using LM35 and Arduino UNO

When to use an FPGA to prototype a controller and how to start

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

Microcontrollers: Lecture 3 Interrupts, Timers. Michele Magno

P89LPC935 ADC/DAC Tutorial

USB4. Encoder Data Acquisition USB Device Page 1 of 8. Description. Features

DNT24MCA DNT24MPA. Low Cost 2.4 GHz FHSS Transceiver Modules with I/O. DNT24MCA/MPA Absolute Maximum Ratings. DNT24MCA/MPA Electrical Characteristics

3.3V regulator. JA H-bridge. Doc: page 1 of 7

FlexTimer and ADC Synchronization

arxiv:physics/ v1 [physics.ed-ph] 19 Oct 2004

Generating DTMF Tones Using Z8 Encore! MCU

Arduino Microcontroller Processing for Everyone!: Third Edition / Steven F. Barrett

Temperature Monitoring and Fan Control with Platform Manager 2

Design and Implementation of AT Mega 328 microcontroller based firing control for a tri-phase thyristor control rectifier

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

FABO ACADEMY X ELECTRONIC DESIGN

Embedded Hardware Design Lab4

Using Z8 Encore! XP MCU for RMS Calculation

Using FTM, PDB, and ADC on KE1xF to Drive Dual PMSM FOC and PFC

READ THIS FIRST: *One physical piece of 8.5x11 paper (you may use both sides). Notes must be handwritten.

EE 109 Midterm Review

Using the Z8 Encore! XP Timer

MC9S08MP16 High Speed BLDC Sensorless Drive Petr Staszko Freescale Czech System Laboratories Roznov pod Radhostem, Czech Republic

Technical Brief FAQ (FREQUENCLY ASKED QUESTIONS) For further information, please contact Crystal Semiconductor at (512) or 1 (800)

EE 308 Apr. 24, 2002 Review for Final Exam

Programming and Interfacing

ME 333 Assignment 7 and 8 PI Control of LED/Phototransistor Pair. Overview

CSE 3215 Embedded Systems Laboratory Lab 5 Digital Control System

EE445L Fall 2015 Quiz 2A Solution Page 1

General Purpose Controller Software for Controls Lab

XGATE Library: PWM Driver Generating flexible PWM signals on GPIO pins

Freescale Semiconductor Application Note. Document Number: AN3467 Rev. 0, 05/2007

Timer/Counter with PWM

DNT90MCA DNT90MPA. Low Cost 900 MHz FHSS Transceiver Modules with I/O

Hello, and welcome to this presentation of the STM32L4 comparators. It covers the main features of the ultra-lowpower comparators and some

LaserPING Rangefinder Module (#28041)

02 Digital Input and Output

Temperature Monitoring and Fan Control with Platform Manager 2

CHAPTER 4 HARDWARE DEVELOPMENT OF STATCOM

Prototyping Unit for Modelbased Applications

Castle Creations, INC.

Instrument Cluster Display. Grant Scott III Erin Lawler Mike Carlson

Lecture 7: Analog Signals and Conversion

Pulse Generation. Pulsout. 555 Timer. Software version of pulse generation Pulsout pin, Period

Transcription:

AGH University of Science and Technology Faculty of Computer Science, Electronics and Telecommunication Department of Electronics MICROPROCESSOR TECHNICS II Tutorial 5 Combining ADC & PWM Mariusz Sokołowski English translation: Paweł Russek http://www.fpga.agh.edu.pl/upt2 13.11.2017

1. INTRODUCTION 1.1. GOAL The main objective of this tutorial is to make student familiar with: the correct initialization procedure of AD converter, the Pulse-Width Modulation (PWM) mode of TPM timer, a technics of combining functions of different peripheral devices with the examples of AD converter used for light detector and PWM module used for an LED intensity control, the noise filtering that is gained thanks to an averaging technics and reference signal of 10 Hz in Kinetis L series of microcontroller from Freescale Semiconductor. 1.2. REQUIREMENTS Hardware and software platforms: PC with Keil s uvision v.5 development software installed, the FRDM-KL46Z microcontrollers development kit from Freescale Semiconductor. Prerequisites: fundamental concepts of Digital Electronics, fundamental ideas from the course of Microprocessors Technics part 1. Literature: Lecture materials: Timers and Analog Interfacing. KL46 Sub-Family Reference Manual, Freescale Semiconductor. Kinetis L Peripheral Module Quick Reference, Freescale Semiconductor.

2. ANALOG TO DIGITAL CONVERTER The microcontroller MKL46Z256VLL4, which is the heart of FRDM-KL46Z development kit, offers the multichannel, 16-bit Analog-to-Digital Converter (ADC) as its standard peripheral (Fig. 1). Figure 1. A block diagram of the Analog to Digital Converter All ADC inputs can be configured as single-ended inputs that measure voltage with respect to the VREFL signal (typically GND). Some inputs (DADP0..3 on Figure 1) can work as differential inputs (with respect to DADM0..3). These input s properties impact a binary format and resolution (bit-width) of ADC results. There are 8, 10, 12, and 16-bit modes, and the results are unsigned data for single-ended measures. Respectively, there are 9, 11, 13, and 16-bit modes, and the results are U2-coded signed data for differential measures. The

reference voltage for ADC (VREFH) is 3.3V on the FRDM-KL46Z board. Please remember, to not exceed the 3.3V value on the ADC inputs. The calibration is the very first step that must be conducted before an ADC can be used for voltage measurements. In your program code, a procedure of the calibration should be preceded by a set-up of the appropriate values in microcontroller s registers. The preparation of your program code for the tutorial exercise goes as follows. Change the definition of CLOCK_SETUP symbol to 1 in the system_mkl46z4.c file. For that selection, the clock configuration for the microcontroller is: o 8 MHz reference clock for the MCG module, o 48 MHz core clock, o 24 MHz bus clock. Enable the module clock for the ADC in the SIM->SCGC6 register. Select the source of the ADC conversion clock, its divider ratio, and the long conversion time in the ADC0->CFG1 (ADICLK, ADIV, ADLSMP). Choose appropriate parameters to provide a conversion clock that does not exceed 4 MHz. Enable the support for the long sample time (ADC0->CFG1[ADLSMP]), select the additional long sample time, and allow 2 additional ADCK cycles to total conversion time to allow higher speed conversion clocks (ADC0->CFG2[ADLSTS:ADHSC]). Select an external reference voltage in ADC0->SC2[REFSEL]. Enable hardware averaging and select the maximum samples averaged in ADC0->SC3[AVGE:AVGS]. Set ADC0->SC3[CAL] to start calibration. The selection of the channel number, conversion mode (single, continuous), compare parameters, result precision, and input mode (single-ended, differential) are not necessary for calibration. Put your code in a waiting loop to allow the calibration to finish; check the eadc0->sc3[cal] bit for 0 to detect that the calibration completed. Check the bit ADC0- >SC3[CALF] is clear to ensure that the calibration was successful. If CALF is set, the error should be handled; for example the calibration procedure should be repeated. On success, the calibration results have to be processed and the results have to be written to appropriate ADC registers. The procedure is as follows: Declare and clear uint16_t variable Add all values in the ADC0->CLPx registers up. Divide the result by 2. Set the most significant bit of the result. Write the result to the ADC0->PG register. Add all values in the ADC0->CLMx registers up. Divide the result by 2. Set the most significant bit of the result. Write the result to the ADC0->MG register The ADC is calibrated and ready to work now, but some other parameters have to be set additionally. Perform the following steps in your program code:

Select the input clock as Bus clock/2, set the clock divide ratio to 1, enable the long sample time, and 12-bit resolution mode in ADC0->CFG1 Enable interrupt in the ADC0->SC1[0][AIEN]. Other ADC parameters, like the software triggering of a conversion (ADTRG=0 in ADC0->SC2), are set to their default values after the Reset signal and there is no need to set them in the program. The measurement is triggered by a software when the input channel number is written to the ADC0->SC1[0][ADCH] field. The conversion result is available in the ADC0->R[0] register when the conversion complete flag is set in the SC1[0] register (ADC0->SC1[0][COCO]). 3. PWM MODE OF THE TPM TIMER The TMP timers of Kinetis L microcontrollers (TPM0, TPM1, and TPM2) provide six channels that can be used in various working modes. Here, we will focus our attention on the Pulse Width Modulation (PWM) working mode of the TMP. Other working modes of TPMs are introduced in more details by Tutorial 5 of the laboratory course. For the reference, Table 1 presents all the modes of TMP channels. Table 1. TPM working modes

We will put our attention to "Edge-aligned PWM" and "Center-aligned PWM" modes in Table 1. The first mode regards pulse width modulation that is synchronized to a pulse edge. The other mode is pulse width modulation that is synchronized to a pulse center (see lecture notes for detailed explanation). We will choose the "Edge-aligned PWM" in this laboratory exercise. Add the following steps to your program code to initialize the TPM0 timer: Enable the port D and E modules clock in the SIM->SCGC5 register. Enable TMP0 module clock in the SIM->SCGC6 register. Select the TMP0 clock source in SIM->SOPT2[TPMSRC:PLLFLLSEL]. We will use "MCGFLLCLK clock or MCGPLLCLK/2" and "MCGPLLCLK clock with fixed divide by two" in this exercise. Select up counting mode of the TMP0 counter and set the clock divider to 128 in TPM0->SC[CPWMS:PS] Set a range of the TMP0 counter to 4095 (this corresponds to 12-bit range) in the TPM0->MOD register. Choice the "Edge-aligned PWM High-true pulses" in channel 2 of TMP0 in TPM0->CONTROLS[2].CnSC (see Table 1 for right bit values) Specify the "Edge-aligned PWM Low-true pulses" in channel 5 of TMP0 in TPM0->CONTROLS[5].CnSC (see Table 1 for right bit values) Set the PWM duty cycle to 0 in TPM0->CONTROLS[x].CnV for both channels. Enable TMP0 counter in TPM0->SC[CMOD]. 4. EXERCISE Use the red and green LEDs and the light sensor of FRDM-KL46Z to develop the application: Measures the voltage on the collector of the Q1 fototransistor (Fig. 2) and presents the value on LCD display of FRDM-KL46Z (use all four digits of the LCD). The light sensor input is connected to pin PTE22, which corresponds to channel 3 of ADC0. Use an interrupt to collect ADC data. The channel 2 of TPM0, which is in the "Edge-aligned PWM High-true pulses" mode, controls the red LED, and its brightness is proportional to the ambient light intensity (it is brighter in the light). The channel 5 of TPM0, which is in the "Edge-aligned PWM High-true pulses" mode, controls the green LED, and its brightness is reverse proportional to the ambient light intensity (it is brighter in the dark). Change the TMP0 mode from the "Edge-aligned PWM" to "Center-aligned PWM". 5. HOMEWORK 1. Use the SysTick timer to generate 100ms interrupt and implement light measure averaging in your program. Display average value on the LCD. 2. Uses ADC0 to measure the VREFH reference voltage. Display the measured value on LCD. 3. Uses ADC0 to measure the voltage from the temperature sensor that is embedded in the microcontroller. Display the value on LCD.

Figure 2. The light sensor of FRDM-KL46z.