AN2475 Freescale Semiconductor / Motorola, AN2475 Datasheet

no-image

AN2475

Manufacturer Part Number
AN2475
Description
Generating a PWM Signal Modulated by an Analog Input Using the MC68HC908QY4 Microcontroller
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Application Note
AN2475/D
3/2003
Generating a PWM Signal
Modulated by an Analog
Input Using the
MC68HC908QY4
Microcontroller
By: Alfredo Olmos
Introduction
MC68HC908QY/QT Family of Microcontrollers
Andre Vilas Boas
Marcus Serra Espindola
Brazil Semiconductor Technology Center
Jaguariuna, S.P., Brazil
This document addresses the use of the internal timer and analog-to-digital
converter (ADC) modules of the MC68HC908QY/QT Family of microcontrollers
(MCUs). In the application, an analog signal is converted to a digital word
through the ADC to set the duty cycle of a pulse-width modulated (PWM)
signal. The PWM duty cycle varies from 0 to 100% in accordance with the
voltage applied at the ADC input. Hence, the PWM signal corresponds to the
digital conversion of the analog input. The PWM signal is fed back to build a
close-loop system for providing voltage regulation in a simple, very flexible
way.
The MC68HC908QY/QT Family is a member of the low-cost, high-performance
M68HC908 Family of 8-bit FLASH MCUs. The M68HC08 Family is a complex
instruction set computer (CSIC) with a Von Neumann architecture. All MCUs in
the family use the enhanced M68HC08 central processor unit (CPU08) and are
available with a variety of modules, memory sizes and types, and package
types.
Features of the MC68HC908QY4 include:
Freescale Semiconductor, Inc.
For More Information On This Product,
4 Kbytes of in-application programmable FLASH and 128 bytes of
random-access memory (RAM)
2-channel 16-bit timer with selectable input capture, output compare,
and PWM
Easy to use high-performance HC08 CPU
Trimmable internal oscillator with ±5% accuracy
4-channel 8-bit ADC
Go to: www.freescale.com
© Motorola, Inc., 2003

Related parts for AN2475

AN2475 Summary of contents

Page 1

... Freescale Semiconductor, Inc. Application Note AN2475/D 3/2003 Generating a PWM Signal Modulated by an Analog Input Using the MC68HC908QY4 Microcontroller By: Alfredo Olmos Andre Vilas Boas Marcus Serra Espindola Brazil Semiconductor Technology Center Jaguariuna, S.P., Brazil Introduction This document addresses the use of the internal timer and analog-to-digital converter (ADC) modules of the MC68HC908QY/QT Family of microcontrollers (MCUs) ...

Page 2

... Freescale Semiconductor, Inc. AN2475/D • • • • • Analog-to-Digital Converter (ADC) The 8-bit, 4-channel ADC module is only available on the MC68HC908QY2, MC68HC908QT2, MC68HC908QY4, and MC68HC908QT4. Features include: • • • • • • Voltage Conversion When the input voltage to the ADC equals V $FF (full scale) ...

Page 3

... Buffered and unbuffered PWM signal generation Programmable TIM clock input with 7-frequency internal bus clock prescaler selection Free-running or modulo up-count operation Toggle any channel pin on overflow TIM counter stop and reset bits Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Timer Interface Module (TIM) 3 ...

Page 4

... Freescale Semiconductor, Inc. AN2475/D Unbuffered PWM The PWM pulses are unbuffered because changing the pulse width requires Signal Generation writing the new pulse width value over the old value currently in the TIM channel registers. An unsynchronized write instruction to the TIM channel registers for changing the pulse width value could cause incorrect operation for up to two PWM periods ...

Page 5

... The current path through the off transistor is now open. The diode will be forward biased, thus maintaining a closed current loop through the load. Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Application Circuit illustrates the PWM waveform the diode, inductor, and shunt 5 ...

Page 6

... Freescale Semiconductor, Inc. AN2475/D GREEN LED Figure 2. Duty Cycle Modulation versus Analog Input Voltage 6 Generating a PWM Signal Modulated by an Analog Input Using the MC68HC908QY4 Microcontroller For More Information On This Product PTB0 TIMER MC68HC908QY4 PTB1 ADC RED LED Figure 1. Application Circuit 2 ...

Page 7

... PWM resolution limit altering the source by code taking into account the trade- off between system resolution and minimum period attainable. MOTOROLA Generating a PWM Signal Modulated by an Analog Input For More Information On This Product, Figure Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com Software Description 4. AN2475/D 7 ...

Page 8

... Freescale Semiconductor, Inc. AN2475/D ERROR STATUS! YES TURN OFF GREEN LED AND TURN ON RED LED SET RESOLUTION (D) TO ~6% INCREMENT PERIOD NO YES YES PERIOD = $FF? 8 Generating a PWM Signal Modulated by an Analog Input Using the MC68HC908QY4 Microcontroller For More Information On This Product, START PWM INITIALIZATION PERIOD < ...

Page 9

... MOTOROLA Generating a PWM Signal Modulated by an Analog Input For More Information On This Product, Comments -------------------------------------------- Included OSCTRIM setting Included Period variation Cleaned up to match new coding standard Initial data entry Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Software Listing Copyright (c) Motorola 2002 9 ...

Page 10

... Freescale Semiconductor, Inc. AN2475/D ;******************************************************************************************* ;* Code Starts Here ;******************************************************************************************* org FlashStart Init: mov #initCfg1,CONFIG1 IntOsc: lda #initCfg2 sta CONFIG2 ;* Configure oscillator trim value lda TRIMLOC sta OSCTRIM ;* Enable ADCH3 continuous convertion mov #initAD,ADSCR ;* Optionally, select ADC ch 1 and 2 by using the instruction below ...

Page 11

... Period if so ;Decrement PWM value ;Verify if ADC value is lower than ;Reg Low Limit -> Decrement Period if so ;Verify if Period is at high limit ;Go to Error Status if so ;Increment period ;Set PWM Duty Cycle to ~ 50% Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Software Listing 11 ...

Page 12

... Freescale Semiconductor, Inc. AN2475/D stx TCH0L RegRes: lda TMODL Lsra lsra lsra lsra sta PWMLim lda #$FF bra WaitReg Error: bclr PTB0,PTB bset PTB1,PTB bra Error ;******************************************************************************************* ;* Interruptions ;******************************************************************************************* Dummy: rti ;******************************************************************************************* ;* Start of Vectors Definitions ;******************************************************************************************* org $FFDE fdb Dummy org $FFE0 fdb Dummy org $FFF2 ...

Page 13

... Flash ;Last Flash location ;ADC vector ;Keyboard vector ;Timer overflow vector ;Timer channel 1 vector ;Timer channel 0 vector ;IRQ vector ;SWI vector ;Reset vector Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Register and Bit Definitions for MC68HC908QY4 Motorola does not assume any 13 ...

Page 14

... Freescale Semiconductor, Inc. AN2475/D ;**** Input/Output (I/O) Ports ;* PTA: equ $00 ; bit numbers for use in BLCR, BSET, BRCLR, and BRSET AWUL equ 6 PTA5: equ 5 PTA4: equ 4 PTA3: equ 3 PTA2: equ 2 PTA1: equ 1 PTA0: equ 0 ; bit position masks mAWUL: equ %01000000 mPTA5: equ %00100000 mPTA4: ...

Page 15

... B input pull up enable bit 2 ;Port B input pull up enable bit 1 ;Port B input pull up enable bit 0 ************************************************* ;Keyboard status and control register ;Keyboard flag ;Keyboard acknowledge ;Keyboard interrupt mask ;Keyboard triggering sesitivity Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Register and Bit Definitions for MC68HC908QY4 15 ...

Page 16

... Freescale Semiconductor, Inc. AN2475/D ; bit position masks mKEYF: equ %00001000 mACKK: equ %00000100 mIMASKK: equ %00000010 mMODEK: equ %00000001 KBIER: equ $1B ; bit numbers for use in BCLR, BSET, BRCLR, and BRSET AWUIE: equ 6 KBIE5: equ 5 KBIE4: equ 4 KBIE3: equ 3 KBIE2: equ 2 KBIE1: ...

Page 17

... B ;Mode select bit A ;Edge/level select bit B ;Edge/level select bit A Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Register and Bit Definitions for MC68HC908QY4 17 ...

Page 18

... Freescale Semiconductor, Inc. AN2475/D TOV1 equ 1 CH1MAX equ 0 ; bit position masks mCH1F: equ %10000000 mCH1IE: equ %01000000 mMS1B: equ %00100000 mMS1A: equ %00010000 mELS1B: equ %00001000 mELS1A: equ %00000100 mTOV1 equ %00000010 mCH1MAX equ %00000001 TCNTH: equ $21 TCNTL: equ $22 TMODH: equ ...

Page 19

... COP ;Break disable COP ;Break flag control register Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Register and Bit Definitions for MC68HC908QY4 19 ...

Page 20

... Freescale Semiconductor, Inc. AN2475/D ; bit numbers for use in BCLR, BSET, BRCLR, and BRSET BCFE: equ 7 ; bit position masks mBCFE: equ %10000000 INT1: equ $FE04 ; bit numbers for use in BCLR, BSET, BRCLR, and BRSET IF5: equ 6 IF4: equ 5 IF3: equ 4 IF1: equ ...

Page 21

... For More Information On This Product, Comments -------------------------------------------- Initial data entry ;Config1 Register value CONFIG1 is a write once register - 1 disable COP Watchdog - 0 disable STOP instruction - 0 4096 cycle STOP recovery - 0 long COP timeout Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Constants and variables definitions Copyright (c) Motorola 2002 21 ...

Page 22

... Freescale Semiconductor, Inc. AN2475/D initCfg2: equ %00000000 ; |||||||| ; |||||||+-RSTEN ; ||||||+--R ; |||||+---R ; ||||+----OSCOPT0 - 0 Set oscillator option as internal ; |||+-----OSCOPT1 - 0 Set oscillator option as internal ; ||+------R ; |+-------IRQEN ; +--------IRQPUD initAD: equ %00100011 ; |||||||| ; |||||||+-CH0 ; ||||||+--CH1 ; |||||+---CH2 ; ||||+----CH3 ; |||+-----CH4 ; ||+------ADCO ; |+-------AIEN ; +--------COCO initTim: equ %00110000 ; |||||||| ; |||||||+-PS0 ; ||||||+--PS1 ; |||||+---PS2 ; ||||+----0 ; |||+-----TRST ; ||+------TSTOP ; |+-------TOIE ...

Page 23

... TIM overflow flag bit ;Upper Limit Period value set ;by user ;Lower Limit Period value set ;by user ;Target Reg. Value set by user ;Minimum Period Value set by user ;PWM Duty Cycle resolution limit (or D) ;PWM Duty Cycle Using the MC68HC908QY4 Microcontroller Go to: www.freescale.com AN2475/D Conclusion 23 ...

Page 24

... Motorola and the Stylized M Logo are registered in the U.S. Patent and Trademark Office. digital dna is a trademark of Motorola, Inc. All other product or service names are the property of their respective owners. Motorola, Inc Equal Opportunity/Affirmative Action Employer. © Motorola, Inc. 2003 AN2475/D Rev. 0 3/2003 Go to: www.freescale.com ...

Related keywords