Programming the Pulse-Width Modulator for Motor Control (PWMMC) on HC08 Microcontrollers Using MC68HC08MR Series to Demonstrate PWM Techniques

Similar documents
Application Note AN-1187

Timer A (0 and 1) and PWM EE3376

Designing an Induction Cooker Using the S08PT Family

Inverter for the Solar Panel using an MC56F8023. Designer Reference Manual

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

Using the HC08 SCI Module

HT46R14A Single Phase AC Induction Motor Frequency Converter Application

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AP TriCore. Sinusodial 3-Phase Output Generation Using The TriCore General Purpose Timer Array. Microcontrollers

AVR Timer/Counter. Prof Prabhat Ranjan DA-IICT, Gandhinagar

Single Phase Two-Channel Interleaved PFC Operating in CrM Using the MC56F82xxx Family of Digital Signal Controllers

Configuring the FlexTimer for Position and Speed Measurement with an Encoder

Microcontroller for Variable Speed BLDC Fan Control System. T.C. Lun System Engineer, Freescale Semiconductor, Inc.

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

Single Phase Two-Channel Interleaved PFC Operating in CrM

ARM Thumb Microcontrollers. Application Note. Software ISO 7816 I/O Line Implementation. Features. Introduction

Atmel Norway XMEGA Introduction

1/22/16. You Tube Video. Definitions. Duty Cycle: on-time per period (specified in per cent)

Theory of Operation. Figure 1 illustrates a fan motor circuit used in an automobile application. The TPIC kω AREF.

Digital Signal Controller Based Automatic Transfer Switch

Using eflexpwm Module for ADC Synchronization in MC56F82xx and MC56F84xx Family of Digital Signal Controllers

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

HT1632C 32 8 &24 16 LED Driver

DEVELOPMENT OF DEVICES AND METHODS FOR PHASE AND AC LINEARITY MEASUREMENTS IN DIGITIZERS

Freescale Semiconductor, I

Software Real Time Clock Implementation on MC9S08LG32

AN3252 Application note

CHAPTER 11: Flip Flops

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

PLL frequency synthesizer

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

Low-Power Pin Sampling Techniques Using Kinetis L Series

AN1229. Class B Safety Software Library for PIC MCUs and dspic DSCs OVERVIEW OF THE IEC STANDARD INTRODUCTION

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

M68EVB908QL4 Development Board for Motorola MC68HC908QL4

Microcontroller based PWM Inverter for Speed Control of a Three Phase Induction Motor

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

Flexible Active Shutter Control Interface using the MC1323x

IGBT Protection in AC or BLDC Motor Drives by Toshio Takahashi

BLDC Motor Control with Hall Effect Sensors Using the 9S08MP

Allen-Bradley/Rockwell

7 OUT1 8 OUT2 9 OUT3 10 OUT4 11 OUT5 12 OUT6 13 OUT7 14 OUT8 15 OUT9 16 OUT10 17 OUT11 18 OUT12 19 OUT13 20 OUT14 21 OUT15 22 OUT16 OUT17 23 OUT18

Migrating Between MC9S08AC and MCF51AC Flexis Devices

Analog to Digital Conversion of Sound with the MSP430F2013

DP8570A DP8570A Timer Clock Peripheral (TCP)

POCKET SCOPE 2. The idea 2. Design criteria 3

EET272 Worksheet Week 9

AVR449: Sinusoidal driving of 3-phase permanent magnet motor using ATtiny261/461/ bit Microcontrollers. Application Note.

6-BIT UNIVERSAL UP/DOWN COUNTER

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

Comparison of MC9S08QE128 and MCF51QE128 Microcontrollers Scott Pape and Eduardo Montanez Systems Engineering, Freescale Microcontroller Division

Lab Experiment 1: The LPC 2148 Education Board

M68HC08. Microcontrollers. Single Phase AC Induction Motor Control Reference Design. Designer Reference Manual. Freescale Semiconductor, I

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

A Lesson on Digital Clocks, One Shots and Counters

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

A Lesson on Digital Clocks, One Shots and Counters

Evaluating AC Current Sensor Options for Power Delivery Systems

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

HANDLING SUSPEND MODE ON A USB MOUSE

Harmonics and Noise in Photovoltaic (PV) Inverter and the Mitigation Strategies

Section 15. Motor Control PWM

AVR126: ADC of megaavr in Single Ended Mode. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Real Time Clock USB Evaluation Board V3.0

Accurate Measurement of the Mains Electricity Frequency

7-41 POWER FACTOR CORRECTION

DKWF121 WF121-A B/G/N MODULE EVALUATION BOARD

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Push-Pull FET Driver with Integrated Oscillator and Clock Output

AVR315: Using the TWI Module as I2C Master. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

STEPPER MOTOR SPEED AND POSITION CONTROL

Transformerless UPS systems and the 9900 By: John Steele, EIT Engineering Manager

Real-Time Clock. * Real-Time Computing, edited by Duncan A. Mellichamp, Van Nostrand Reinhold

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

WS2811. Signal line 256 Gray level 3 channal Constant current LED drive IC. Feature. Applications. General description

ET-BASE AVR ATmega64/128

Digital to Analog Converter. Raghu Tumati

DS1307ZN. 64 x 8 Serial Real-Time Clock

A simple RF/Microwave frequency counter

Motor Control using NXP s LPC2900

Automatic Impedance Matching for MHz NFC Antennas

Information Board User s Guide

RS - SPM. Serial parallel translator module

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Serial Communications

A Digital Timer Implementation using 7 Segment Displays

AN2680 Application note

DRM for Driver Information System on S12G128. Reference Design

Chapter 6 PLL and Clock Generator

AN141 SMBUS COMMUNICATION FOR SMALL FORM FACTOR DEVICE FAMILIES. 1. Introduction. 2. Overview of the SMBus Specification. 2.1.

UM0708 User manual. STM8Sxxx three-phase BLDC motor control software library V1.0. Introduction

AVR311: Using the TWI Module as I2C Slave. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

PCM Encoding and Decoding:

Small Hardware Development and Prototyping Board for the SX28

AN4646 Application note

RENESAS TECHNICAL UPDATE

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Interfacing To Alphanumeric Displays

FEATURES DESCRIPTION. PT6321 Fluorescent Display Tube Controller Driver

Transcription:

Freescale Semiconductor Application Note AN2876 Rev. 1.0, 07/2005 Programming the Pulse-Width Modulator for Motor Control (PWMMC) on HC08 Microcontrollers Using MC68HC08MR Series to Demonstrate PWM Techniques By Jorge Zambada Tinoco RTAC Americas Mexico 2005 Introduction This document is intended to serve as a quick reference for an embedded engineer to get the pulse-width-modulation (PWM) module up and running for any HC08 MCU that includes this module. Basic knowledge about the functional description and configuration options will give the user a better understanding on how the PWM module works. This application note provides an example that demonstrates one use of the PWM module within the HC08 Family of microcontrollers. The examples mentioned are intended to be modified to suit the specific needs for any application. The complete software files for the example described in this document is available as AN2876SW.zip free-of-charge from the Freescale Semiconductor web site: http://freescale.com Freescale Semiconductor, Inc., 2005. All rights reserved.

PWM Module PWM Module The PWM module included in the MC68HC08MR Series of microcontrollers is a motor-control-oriented pulse-width modulator capable of generating three complementary PWM pairs or six independent PWM signals. A 12-bit timer PWM counter is common to all six channels. PWM resolution is one clock period for edge-aligned operation and two clock periods for center-aligned operation. The clock period is dependent on the internal operating frequency (f OP ) and a programmable prescaler. The highest resolution for edge-aligned operation is 125 ns (f OP = 8 MHz) and the highest resolution for center-aligned operation is 250 ns (f OP = 8 MHz). Some of the features of the PWM module are: Three complementary pairs or six independent PWM signals on six output pins Edge-aligned PWM signals or center-aligned PWM signals PWM signals polarity control 20-mA current sink capability on PWM pins Manual PWM output control through software Programmable fault protection (two FAULT input pins on the MR8 and four FAULT input pins on the MR16/32) Complementary mode featuring: Dead-time insertion Separate top/bottom pulse-width correction via current sensing (three pins on MR16/32) or programmable software bits (on all MR MCUs) Registers Description The main PWM module registers are: 1. The Configuration Register (CONFIG) Determines the alignment of the PWM signals (bit 7 EDGE) Selects the top and bottom PWM polarities (bits 6:5 BOTNEG, TOPNEG) Enables or disables the complementary fashion (bit 4 INDEP) 2. The PWM Control Register 1 (PCTL1) Disables or re-enables the PWM pins in banks X and Y (bits 7:6 DISX, DISY) 1 Enables or disables PWM counter overflow interrupts (bit 5 PWMINT) Flags a PWM counter overflow (bit 4 PWMF) Configures the current correction bits (bits 3:2 ISENS1, ISENS0) 2 Loads prescaler, modulus, and PWM values to the working registers (bit 1 LDOK) Enables the PWM module (bit 0 PWMEN) Notes: 1. For for details concerning disable mapping, see the Fault Protection section of the data sheet. 2. The current distortion correction feature is not covered in this application note. Refer to the Output Control section of the data sheet. 3. The number of fault pins depends on the device and package. See the Pin Assignments section of the data sheet. 2 Freescale Semiconductor

PWM Module 3. The PWM Control Register 2 (PCTL2) Selects the PWM CPU load frequency (bits 7:6 LDFQ1:LDFQ0) Selects the PWM register used for the current correction when achieved by software (bits 4:2 IPOL1:IPOL3) 2 Selects the prescaler for the PWM clock frequency (bits 1:0 PRSC1:PRSC0) 4. The Fault Control Register (FCR) Enables or disables the fault interrupts of each fault input (bits 7, 5, 3, 1 FINT4:FINT1) 3 Selects the fault operating mode of each fault input (bits 6, 4, 2, 0 FMODE4:FMODE1) 3 5. The Fault Status Register (FSR) Reflects the fault pin logic level (bits 7, 5, 3, 1 FPIN4:FPIN1) 3 Flags when a fault input as been asserted (bits 6, 4, 2, 0 FFLAG4:FFLAG1) 3 6. The Fault Acknowledge Register (FTACK) Acknowledges the fault input flags when asserted (bits 6, 4, 2, 0 FTACK4:FTACK1) 3 7. The PWM Output Control Register (PWMOUT) Selects the PWM output control, either manually or by the PWM generator (bit 6 OUTCTL) Determines the PWM pin logic level when configured as manual control (bits 5:0 OUT6:OUT1) 8. The PWM Counter Register (PCNTH:PCNTL) Displays the 12-bit up/down counter (center aligned) or up-only counter (edge aligned) 9. The PWM Counter Modulo Register (PMODH:PMODL) Holds a 12-bit unsigned number that determines the maximum count for the up/down or up-only counter 10. The PWM 1:6 Value Registers (PVAL1H:L, PVAL6H:L) Holds a 16-bit signed value that determines the duty cycle of the PWM 11. The Dead-Time Write-Once Register (DEADTM) which: Holds an 8-bit value that determines the number of PWM cycles to turn off the PWM pairs when configured in complementary fashion 12. The PWM Disable Mapping Write-Once Register (DISMAP) Holds an 8-bit value that determines which PWM pins will be disabled if an external fault or software disable occurs 1 Notes: 1. For for details concerning disable mapping, see the Fault Protection section of the data sheet. 2. The current distortion correction feature is not covered in this application note. Refer to the Output Control section of the data sheet. 3. The number of fault pins depends on the device and package. See the Pin Assignments section of the data sheet. Freescale Semiconductor 3

Application Example Application Example In this example PWM application, a three-phase AC induction motor will be driven by the microcontroller using an inverter topology. As shown in the Schematics section of this document, the PWM pins are connected to the gate driver IC. This gate driver is used to convert the MCU voltage levels to the required gate-to-source voltages of the switching transistors. The IGBTs used for this example are in the range of 10 V to 20 V typically. As a protection scheme, there is a sense resistor, where its voltage drop will represent the total current fed to the motor s coils. An amplifier and comparator will generate a FAULT signal to protect the power stage and the motor against an overcurrent condition. With this topology, a set of duty cycle values are stored in FLASH as constants in order to generate the waveform shown in Figure 1. 250, PWM 200, 150, 100, 50, PWM Pair 1-2 PWM Pair 3-4 PWM Pair 5-6 0, 1 6 11 16 21 26 31 36 41 46 51 56 61 Time Figure 1. Third Harmonic Waves When these waveforms are fed into the inverter transistors, the currents seen by the motor coils appear as shown in Figure 2: 300 200 Current 100 0-100 1 4 7 10131619222528313437404346495255586164 Coil A Coil B Coil C -200-300 Time Figure 2. Coil Currents 4 Freescale Semiconductor

Application Example As an example, a 60-Hz signal with these shapes will be generated by the microcontroller using the PWM at a 15.625 khz. This frequency is just above the audible noise level and low enough to avoid electrical noise generation. The number of PWM cycles to achieve a 60 Hz signal would be: 15.625 khz/60 Hz = 260.4167 For convenience, a power-of-two value of 256 PWM cycles can be used. At this point, a table of 256 duty cycle values is needed to generate a 60-Hz signal with a PWM frequency of 15.625 khz, but there is a trade-off between the number of different duty cycle values and the CPU usage. Therefore, a different PWM load frequency will be used to relieve the CPU. With a PWM load frequency of each 4 PWM cycles, a table of 256 / 4 = 64 values is to be stored in FLASH for each PWM pair and CPU use is reduced significantly. Another important parameter, known as dead-time insertion, must be considered on these applications. The dead-time value will depend on the motor coil s characteristics, the layout, and the gate driving circuitry. For this particular example, a dead-time value of 2 microseconds is inserted between the turn off of a channel (e.g., PWM 1) and the turn on of its complementary channel (e.g., PWM 2) to prevent a short circuit condition. That value can be computed as follows: PWM module input clock (8 MHz with prescaler of 1) * 2 µs = 16. Freescale Semiconductor 5

Application Example Schematics VCC VCC START/STOP 1 2 4.00 MHz 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 U1 VREFH RST VDDA VSSA OSC2 OSC1 CGMXFC IRQ PWM1 PWM2 PWM3 PWM4 PWM5 PWM6 U2 MCU - PWM1 MCU - PWM2 MCU - PWM3 MCU - PWM4 MCU - PWM5 MCU - PWM6 28 PTA3/ATD3 27 PTA2/ATD2 26 PTA1/ATD1 25 PTA0/ATD0 PTB6/TCH1B 24 PTB5/TCH0B 23 VSS 22 VDD 21 PTB4/TCH1A 20 PTB3/TCH0A 19 PTB2/TCLKA 18 PTB1/TxD 17 PTB0/RxD 16 15 PTC0/FAULT1 MC68HC908MR8CP PWM1 PWM2 PWM3 PWM4 PWM5 PWM6 12 11 10 9 8 7 VCC U3 Sense Input 1 MCU - FAULT Saf e Lev el Amplif ier & Comparator 2 3 VCC Gate Drivers AC LINE AC NEUTRAL PWM1 PWM2 PWM3 PWM4 PWM5 PWM6 MOTOR COIL A MOTOR COIL B MOTOR COIL C Sense Resistor Figure 3. Example Schematic for Three-Phase Inverter Code and Explanation The following C code is an example using an MC68HC908MR8 microcontroller. This code configures and uses the PWM module to start and stop a three-phase AC induction motor. The software consists of the following steps: Initialize the PWM module. Check the input pin. If the pin is open, the motor is stopped. If the switch is closed, the motor is continuously running. The PWM duty cycles are reloaded continuously so that the output frequency seen by the motor coils is a three-phase sinusoid 60-Hz signal on a PWM frequency of 15.625 khz. See the flowchart in Figure 4. 6 Freescale Semiconductor

Application Example PWM Interrupt Clear ISR Flag Switch Closed? NO Load 0% PWM Duty Cycles YES Load New PWM Duty Cycles from Sine Table Update Sine Table Pointer Use new stored duty cycles (LDOK = 1) Return from Interrupt Figure 4. PWM Interrupt Service Routine Flowchart 1. Initialization Routine Following these steps, the user will be able to use the PWM for a typical motor application. 1.1 Configure the PWM fashion and polarity CONFIG = 0x01; /* Center aligned mode enabled, all PWM pins in positive polarity, complementary mode enabled, COP disabled */ Freescale Semiconductor 7

Application Example 1.2 Initialize the PWM counter modulus to have a frequency of 15.625 khz The software initializes the PLL 1 to speed up the operating frequency to the maximum of 8 MHz with the external crystal of 4.00 MHz. In this step, the prescaler is also selected. PMOD = 0x0100; /* With a FOP of 8MHz, the PWM Frequency would be: Fbus 8 MHz PWM Frequency = --------------- = --------- = 15.625 khz 2 x PMODH:L 2 x 256 The 2 factor of the divisor is because a center-aligned operation is used, so the PWM counter counts up and down. */ PCTL2 = 0x80; /* Reload PWM values every 4 PWM cycles. Select a prescaler by 1 */ 1.3 Initialize the disable mapping registers. When a FAULT occurs, turn off every PWM output. Configure the FAULT1 pin as automatic operation without interrupts. DISMAP = 0xFF; /* Disable all PWM pins when a FAULT occurs */ FCR = 0x01; /* Fault 1 in Automatic mode without interrupts */ 1.4 Select a dead-time of 2 microseconds. This value depends on the power electronics topology, the layout and the motor characteristics. DEADTM = 0x10; /* Deadtime of 2 us. This is dependent of the hardware topology */ DEADTM = Fbus x 2 us = 8 MHz x 2 us = 16 */ 1.5 Initialize the duty cycle registers to the minimum value of 0%. In the complementary mode, it is sufficient to load duty cycle values to the odd PWM channels. PVAL1 = 0x0000; /* Minimum duty cycle for pair PWM1:2 */ PVAL3 = 0x0000; /* Minimum duty cycle for pair PWM3:4 */ PVAL5 = 0x0000; /* Minimum duty cycle for pair PWM5:6 */ 1.6 Load data to the working registers by setting the LDOK bit and enable the PWM module by setting the PWMEN bit. Enable PWM interrupts to reload duty cycle registers with new values. PCTL1 = 0x22; /* Load data to buffers by setting the LDOK bit and Enable PWM Interrupts */ PCTL1 = 0x01; /* Enable the PWM module by setting the PWMEN bit */ Because an interrupt-based algorithm is being implemented, the global interrupt enable mask must be cleared as follows: EnableInterrupts; /* asm CLI; */ 1. PLL module is not covered in this application note. Refer to the Clock Generator Module section of the data sheet. 8 Freescale Semiconductor

Considerations 2. Interrupt Service Routine (ISR) From this point on, the code execution is performed inside the PWM interrupt service routine. The ISR: 2.1 Clears PWM interrupt flag. PCTL1 &= ~(0x10); /* Clear PWM Interrupt Flag */ 2.2 Reloads the PWM value registers with the next duty cycle value stored in a constant table. The value to be stored depends on the state of the push button. If it is read as logic 0, a value from the table is stored in the PWM channels, and if it is read as logic 1, a value of 0x0000 (0% duty cycle) is stored in the channels. if ((PTA & 0x08) == 0x00) /* Check external switch connected to PTA3 */ { PVAL1 = PHASE_A[TableIndex]; PVAL3 = PHASE_B[TableIndex]; PVAL5 = PHASE_C[TableIndex]; } else { PVAL1 = 0x0000; /* Minimum Duty Cycle on PWM1:2 pair */ PVAL3 = 0x0000; /* Minimum Duty Cycle on PWM1:2 pair */ PVAL5 = 0x0000; /* Minimum Duty Cycle on PWM1:2 pair */ } 2.3 Updates the TableIndex variable, which is used to point to the next value to be stored in the PWM channels. It is restarted when a maximum value of 64 is reached. TableIndex++; /* Update Table Index */ if (TableIndex == 64) { TableIndex = 0; /* Reset Table Index */ } 2.4 Sets the LDOK bit to use the new stored values. PCTL1 = 0x02; /* Load new PWM values */ Considerations This example code was developed using Metrowerks CodeWarrior IDE version 3.0 for HC08, and was expressly made for the MC68HC908MR8 in the DIP package. Changes to the code may be required to for use with other MCUs because pin availability differ for among devices. Table 1 shows the available pins for each member and package option for the MC68HC08MR Series of MCU. Freescale Semiconductor 9

Conclusion Table 1. PWM Pin Availability Pins PWM Pins 1 6 PWM GND Pin FAULT1 FAULT2 FAULT3 FAULT4 ISENS Pins Microcontroller MR4/8 MR16/ 32-Pins LQFP 28-Pins DIP/SOIC Yes No Yes No No Yes No Yes No Yes No No No No 64-Pin QFP Yes Yes Yes Yes Yes Yes Yes 56-Pin Yes Yes Yes Yes Yes Yes Yes Conclusion This document describes how to use the PWM module to drive a three-phase AC induction motor with an MC68HC908MR8 microcontroller. For further information on how an application of this type is implemented in detail, visit the Freescale Semiconductor web site: http://freescale.com. References Refer to the following documents for more information on subjects in this application note. AN2876SW.zip: Complete software files for the example described in this application note MC68HC908MR8 data sheet MC68HC908MR32 data sheet AN1712: Get Your Motor Running with the MC68HC708MP16 AN2154: Low-Cost, 3-Phase, AC Motor Control System with Power Factor Correction Based on MC68HC908MR32 AN2355: Sensorless BLDC Motor Control on MC68HC908MR32 Software Description DRM007: BLDC Motor Control Board for Industrial and Appliance Applications Freescale Semiconductor s Motor Control Automotive Application page 10 Freescale Semiconductor