DOC PREVIEW
NMT EE 308 - The MC9S12 Pulse Width Modulation Subsystem

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2010The MC9S12 Pulse Width Modulation Subsystem• The MC9S12 PWS subsystem allows you to control up to eight devices by adjustingthe percentage of time the output is active.• We will discuss 8-bit, high polarity, left-aligned modes.• Different types of devices need different PWM periods.• The hard part of setting up the PWM subsystem is figuring out how to set up theMC9S12 to get the perio d you want.• Once you determine the perio d in seconds, convert this to clock cycles:Period in cycles = Period in seconds × 24, 000, 000 cycles/sec• Once you have period in clock cycles, figure out how to get this value (or close to thisvalue) using the following:Period =(PWMPERx × 2Nif PCLKx == 0PWMPERx × 2N +1× M if PCLK0x == 1• Find values of PWMPERx, N and (if using clock mode 1) M.• Choose PWMPERx to be fairly large (typically 100 or greater).• For channels 0, 1, 4 and 5, N is set using the PCKA bits of register PWMPRCLK, and M isset by the eight-bit register PWMSCLA.• For channels 2, 3, 6 and 7, N is set using the PCKB bits of register PWMPRCLK, and M isset by the eight-bit register PWMSCLB.• For example, to get a 10 ms period on Channel 0:Period in cycles = 10ms × 24, 000, 000 cycles/sec = 240, 000Cannot use clock mode 0. The largest number of cycles possible using clock mode 0 is255 ×27= 32,640Using clock mode 1:240, 000 = PWMPER0 × 2N +1× MLet PWMPER0 = 100. Then we get the following:1EE 308 Spring 2010N M0 12001 6002 3003 1504 755 37.56 18.757 9.375Since M has to be less than 256, we can use N = 3 or N = 4.For N = 3, M = 150:PWMCLK = PWMCLK | 0x01; // Clock mode 1 for Channel 0PWMPRCLK = (PWMPRCLK & ~0x4) | 0x03; // N = 3 for Channel 0PWMSCLA = 150 // M = 150 for Channel 0PWMPER0 = 100;2EE 308 Spring 2010Interdependence of clocks for Channels 0, 1, 4 and 5• The clocks for Channels 0, 1, 4 and 5 are interdependent• They all use PCKA and PWMSCLA• To set the clock for Channel n, you need to set PCKA, PCLKn, PWMSCLA (if PCLKn == 1) and PWMPERn where n = 0, 1, 4 or 52PCKA201PCLK0CLK001CLK1PCLK1Clock Select for PWM Channels 0 and 124 MHz ClockSame for Channels 4 and 5 PWMSCLA3EE 308 Spring 2010PWM Channels 2, 3, 6 and 7• PWM channels 2, 3, 6 and 7 are similar to PWM channels 0, 1, 4 and 5• To set the clock for Channel n, you need to set PCKB, PCLKn, PWMSCLB (if PCLKn == 1) and PWMPERn where n = 2, 3, 6 or 7220101Clock Select for PWM Channels 2 and 3PCKBPCLK2PCLK3CLK2CLK324 MHz Clock PWMSCLBSame for Channels 6 and 74EE 308 Spring 2010Using the MC9S12 PWM1. Choose 8-bit mo de (PWMCTL = 0x00)2. Choose high p olarity (PWMPOL = 0xFF)3. Choose left-aligned (PWMCAE = 0x00)4. Select clock mode in PWMCLK:• PCLKn = 0 for 2N,• PCLKn = 1 for 2(N +1)× M,5. Select N in PWMPRCLK register:• PCKA for channels 5, 4, 1, 0;• PCKB for channels 7, 6, 3, 2.6. If PCLKn = 1, select M• PWMSCLA = M for channels 5, 4, 1, 0• PWMSCLB = M for channels 7, 6, 3, 2.7. Select PWMPERn, normally between 100 and 255.8. Enable desired PWM channels: PWME.9. Select PWMDTYn, normally between 0 and PWMPERn. ThenDuty Cycle n =PWMDTYnPWMPERn× 100%Change duty cycle to control speed of motor or intensity of light, e tc.10. For 0% duty cycle, choose PWMDTYn = 0x00.5EE 308 Spring 2010Program to use the MC9S12 PWM System/** Program to generate 15.6 kHz pulse width modulation* on Port P Bits 0 and 1** To get 15.6 kHz: 24,000,000/15,600 = 1538.5** Cannot get exactly 1538.5** Use 1536, which is 2^9 x 3** Lots of ways to set up PWM to achieve this. One way is 2^3 x 192* Set PCKA to 3, do not use PWMSCLA, set PWMPER to 192**/#include "hcs12.h"main(){/* Choose 8-bit mode */PWMCTL = 0x00;/* Choose left-aligned */PWMCAE = 0x00;/* Choose high polarity on all channels */PWMPOL = 0xFF;/* Select clock mode 0 for Channels 1 and 0 (no PWMSCLA) */PWMCLK = PWMCLK & ~0x03;/* Select PCKA = 3 for Channels 1 and 0 */PWMPRCLK = (PWMPRCLK & ~0x4) | 0x03;/* Select period of 192 for Channels 1 and 0 */PWMPER1 = 192;PWMPER0 = 192;/* Enable PWM on Channels 1 and 0 */PWME = PWME | 0x03;PWMDTY1 = 96; /* 50% duty cycle on Channel 1 */PWMDTY0 = 46; /* 25% duty cycle on Channel 0 */while (1){ /* Code to adjust duty cycle to meet requirements */ }}6EE 308 Spring 2010Analog/Digital Converters• An Analog-to-Digital (A/D) converter converts an analog voltage into a digital number• There are a wide variety of methods used for A/D convertersExamples are:– Flash (Parallel)– Successive Approximation– Sigma-Delta– Dual Slope Converter• A/D converters are classified according to several characteristics– Resolution (number of bits) — typically 8 bits to 24 bits– Speed (number of samples per second) — several samples/sec to several billionsamples/sec– Accuracy — how much error there is in the conversion• High-resolution converters are usually slower than low-resolution converters• The MC9S12 has a 10-bit successive approximation A/D converter (which can be usedin 8-bit mode)• The MC9S12 uses an analog multiplexer to allow eight input pins to connect to theA/D converter7EE 308 Spring 2010Comparator• A comparator is used in many types of A/D converters.• A comparator is the simplest interface from an analog signal to a digital signal• A comparator compares two voltage values on its two inputs• If the voltage on the + input is greater than the voltage on the - input, the output willbe a logic high• If the voltage on the + input is less than the voltage on the - input, the output will bea logic lowIf Vin > Vref then Vout = VccIf Vin < Vref then Vout = 0VREFVOUTINVCCV8EE 308 Spring 2010Flash (Parallel) A/D Converter• A flash A/D conve rter is the s implest to understand• A flash A/D converter compares an input voltage to a large number of reference voltages• An n-bit flash converter uses 2n-1 comparators• The output of the A/D converter is determined by which of the two reference voltagesthe input signal is between,• Here is a 3-bit A/D converterVin5 V+−+−+−+−+−+−+−4.375 V3.750 V3.125 V2.500 V1.875 V1.250 V0.625 V0.000 VDout9EE 308 Spring 2010Flash A/D Converter• A B-bit Flash A/D converter requires 2B-1 comparators• An 8-bit Flash A/D requires 255 comparators• A 12-bit Flash A/D converter would require 4,095 comparators– Cannot integrate 4,095 comparators onto an IC• The largest flash A/D converter is 8 bits• Flash A/D converters can sample at several billion samples/sec10EE 308 Spring 2010A/D Converter Resolution and Quantization• If the


View Full Document

NMT EE 308 - The MC9S12 Pulse Width Modulation Subsystem

Documents in this Course
Load more
Download The MC9S12 Pulse Width Modulation Subsystem
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The MC9S12 Pulse Width Modulation Subsystem and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The MC9S12 Pulse Width Modulation Subsystem 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?