DOC PREVIEW
NMT EE 308 - Topics for 2nd exam

This preview shows page 1-2-3-25-26-27 out of 27 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 27 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 27 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 27 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 27 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 27 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 27 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 27 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2011 • Topics for Exam 2 • The MC9S12 Pulse Width Modulation System • Huang Sections 8.10 and 8.11 • PWM_8B8C Block User Guide • Analog-to-Digital Converters • Huang Sections 12.1-12.2 o What is PWM o The MC9S12 PWM system o Registers used by the PWM system o How to set the period for PWM Channel 0 o How to set the clock for PWM Channel 0 o Interdependence of clocks for Channels 0 and 1 o PWM Channels 2 and 3 o Using the MC9S12 PWM o A program to use the MC9S12 PWM o Introduction to A/D Converters Topics for Exam 2 (March 30 or April 1?) 1. C Programming (a) Setting and clearing bits in registers • PORTA = PORTA | 0x02; • PORTA = PORTA & ~0x0C; (b) Using pointers to access specific memory location or port. • * (unsigned char *) 0x0400 = 0xaa; • #define PORTX (* (unsigned char *) 0x400) PORTX = 0xaa; 2. Interrupts (a) Interrupt Vectors (and reset vector) • How to set interrupt vectors in C (b) How to enable interrupts (specific mask and general mask) (c) What happens to stack when you receive an enabled interruptEE 308 Spring 2011 (d) What happens when you leave ISR with RTI instruction? (e) What setup do you need to do before enabling interrupts? (f) What do you need to do in interrupt service routine (clear source of interrupt, exit with RTI instruction)? (g) How long (approximately) does it take to service an interrupt? 3. Timer/Counter Subsystem (a) Enable Timer (b) Timer Prescaler • How to set • How it affects frequency of timer clock (c) Timer Overflow Interrupt (d) Input Capture (e) Output Compare (f) How to enable interrupts in the timer subsystem (g) How to clear flags in the timer subsystem (h) Be able to look at registers and determine timer is set up • Which channels are being used • Which are being used for Input Capture, which for Output Compare • How to time differences from Timer count registers 4. Real Time Interrupt (a) How to enable (b) How to change rate (c) How to enable interrupt (d) How to clear flagEE 308 Spring 2011 5. Pulse Width Modulation (a) How to get into 8-bit, left-aligned high-polarity mode (b) How to set PWM period (frequency) • Using Clock Mode 0 • Using Clock Mode 1 (c) How to set PWM duty cycle (d) How to enable PWM channel (e) Be able to look at PWM registers and determine PWM frequency and duty cycleEE 308 Spring 2011 The MC9S12 Pulse Width Modulation Subsystem • The MC9S12 PWS subsystem allows you to control up to eight devices by adjusting the 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 the MC9S12 to get the period you want. • Once you determine the period 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 this value) using the following: PWMPER0 × 2N if PCLK0x == 0 Period = PWMPER0 × 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 is set 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 is set 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, 000 Cannot use clock mode 0. The largest number of cycles possible using clock mode 0 is 255 ×27 = 32,640 Using clock mode 1: 240, 000 = PWMPER0 × 2N+1 ×MEE 308 Spring 2011 Let PWMPER0 = 100. Then we get the following: Since 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 0 PWMPRCLK = (PWMPRCLK & ~0x4) | 0x03; // N = 3 for Channel 0 PWMSCLA = 150 // M = 150 for Channel 0 PWMPER0 = 100;EE 308 Spring 2011 Interdependence 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 5EE 308 Spring 2011 PWM 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 7EE 308 Spring 2011 Using the HCS12 PWM 1. Choose 8-bit mode (PWMCTL = 0x00) 2. Choose high polarity (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. Then Duty Cycle n = (PWMDTYn / PWMPERn) × 100% Change duty cycle to control speed of motor or intensity of light, etc. 10. For 0% duty cycle, choose PWMDTYn = 0x00.EE 308 Spring 2011 Program 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 <hidef.h> /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void main(void) { /* 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 …


View Full Document

NMT EE 308 - Topics for 2nd exam

Documents in this Course
Load more
Download Topics for 2nd exam
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 Topics for 2nd exam 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 Topics for 2nd exam 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?