ECE3120: Chapter 8 Timer Functions Pulse Accumulator - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

ECE3120: Chapter 8 Timer Functions Pulse Accumulator

Description:

Can be used to latch the value of IC registers and the pulse accumulators to ... The action of latching can be periodic or only once. ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 24
Provided by: xubi
Category:

less

Transcript and Presenter's Notes

Title: ECE3120: Chapter 8 Timer Functions Pulse Accumulator


1
ECE3120 Chapter 8- Timer FunctionsPulse
Accumulator
  • Dr. Xubin He
  • http//iweb.tntech.edu/hexb
  • Email hexb_at_tntech.edu
  • Tel 931-3723462, Brown Hall 319

2
Pulse Accumulator
  • The HCS12 standard timer system has a 16-bit
    pulse accumulator PACA.
  • The HCS12 ECT system has four 8-bit pulse
    accumulators (PAC3PAC0).
  • Two adjacent 8-bit pulse accumulators can be
    concatenated into a 16-bit pulse accumulator.
  • PAC3 and PAC2 can be concatenated into the 16-bit
    PACA whereas PAC1 and PAC0 can be concatenated
    into the 16-bit PACB.
  • There are four possible pulse accumulator
    configurations
  • Two 16-bit pulse accumulators PACA and PACB
  • One 16-bit pulse accumulator PACA and two 8-bit
    pulse accumulators PAC1 and PAC0
  • One 16-bit pulse accumulator PACB and two 8-bit
    pulse accumulators PAC3 and PAC2
  • Four 8-bit accumulators PAC3PAC0
  • Four 8-bit pulse accumulators PAC3PAC0 are
    sharing the signal pins PT3PT0.
  • When concatenated into 16-bit pulse accumulators,
    PACA shares the PT7 pin whereas PACB shares the
    use of PT0 pin.

3
Pulse Accumulator Operation Modes
  • Event counting mode. The 16-bit PACA can operate
    in this mode and count the number of events
    arrived at the PT7 pin. The 16-bit PACB and all
    four 8-bit pulse accumulators can operate only in
    this mode.
  • Gated accumulation mode. The 16-bit PACA can also
    operate in this mode. As long as the PT7 signal
    is active (can be high or low), the PACA counter
    is clocked by a free-running E ? 64 signal.
  • The active edge of the PACB and PAC3PAC0 are
    identical to those of IC0 and IC3IC0,
    respectively. Therefore, one needs to use the
    TCTL4 register to select the active edges for
    these pulse accumulators.

4
(No Transcript)
5
(No Transcript)
6
Interrupt Sources for Pulse Accumulators
  • The 16-bit PACA has two interrupt sources
    PT7-edge and PACA counter overflow.
  • Only two (PAC3 and PAC1) of the 8-bit pulse
    accumulators can generate interrupt.
  • These two pulse accumulators can interrupt
    whenever their counters overflow.
  • PACB can interrupt the MCU whenever its upper
    8-bit counter overflows.


7
Registers Related to Pulse Accumulators
  • The operation of the 16-bit PACA is controlled by
    the PACTL register. The contents of this register
    are shown in Figure 8.27.
  • PACA has a 16-bit counter which comprises of PAC3
    and PAC2. This 16-bit counter can be accessed by
    using the name PACNT.
  • The status of the PACA is recorded in the PAFLG
    register.
  • The operation of the PACB is controlled by the
    PBCTL register.
  • The status of PACB is recorded in the PBFLG
    register.
  • Each of the 8-bit pulse accumulators can be
    enabled by setting a proper bit in the ICPAR
    register.
  • Each of the 8-bit pulse accumulator also has a
    holding register (PA3HPA0H).
  • The user can prevent the 8-bit pulse accumulators
    from counting further than FF by setting the
    PACMX bit of the ICSYS register.

8
(No Transcript)
9
(No Transcript)
10
(No Transcript)
11
(No Transcript)
12
  • Example 8.13 Suppose that certain events are
    converted into pulses and connected to the PT7
    pin. Write a program that enables the PACA to
    generate an interrupt to the MCU when N events
    have occurred.
  • Solution By writing the 2s complement of N, the
    PACA will interrupt the MCU when the nth event
    arrives

include "c\miniide\hcs12.inc" N equ 1350 org
1500 lds 1500 set up stack
pointer movw paov_isr, UserPAccOvf set up
PAOV interrupt vector ldd N place the 2s
complement in PACNT coma comb addd 1
std PACNT movb 52,PACTL enable
PACA, event counting mode, active edge is
rising cli enable PAOV interrupt swi pao
v_isr movb PAOVF,PAFLG clear the PAOVF
flag rti end
13
Procedure for Measuring Signal Frequency Using
the PA Function
  • Step 1
  • Connect the signal to the PT7 pin.
  • Step 2
  • Set up the PACA to operate in event counting
    mode.
  • Step 3
  • Use one of the output-compare functions to create
    a 1-second time interval or call the library
    delay function. (Or use the modulus down
    counter).
  • Step 4
  • Use a memory location to keep track of the number
    of times that the PACNT overflows.
  • Step 5
  • Enable the PAOV interrupt.
  • Step 6
  • Disable the PAOV interrupt at the end of one
    second.
  • The frequency of the unknown signal is given by
    the following equation
  • frequency paov_cnt 216 PACNT
  • The assembly and C programs for measuring signal
    frequency is in the following pages

14
include "c\miniide\hcs12.inc" org 1000 oc_c
nt rmb 1 paov_cnt rmb 2 use to keep track of
PACNT overflow count frequency rmb 4 hold the
signal frequency org 1500 lds 1500 movw pao
v_isr,UserPAccOvf set up PAOV interrupt
vector movb 50,oc_cnt prepare to perform 50
OC0 actions ldd 0 std PACNT let PACNT count
up from 0 std paov_cnt initialize PACNT
overflow count to 0 std frequency initialize
frequency to 0 std frequency2 " movb 90,TSC
R1 enable TCNT and fast timer flag
clear bset TIOS,OC0 select OC0
function movb 03,TSCR2 set prescaler to
TCNT to 8 bclr DDRT,80 configure PT7 for
input configure PA function enable PA, select
event counting mode, rising edge of PAI signal
increments the PACNT counter, enable PAOV
interrupt movb 52,PACTL cli enable PAOV
interrupt ldd TCNT
15
sec_loop addd 60000 std TC0 brclr TFLG1,C0F,
wait for 20 ms here ldd TC0 dec oc_cnt bne sec
_loop movb 0,PACTL disable PA
function sei disable interrupt ldd PACNT std
frequency2 ldd paov_cnt std frequency swi pao
v_isr movb PAOVF,PAFLG clear the PAOVF
flag ldx paov_cnt increment PACNT
overflow inx count by 1 stx paov_cnt rti
end
16
Using the PA Function to Measure Pulse Duration
  • Step 1
  • Select gated time accumulation mode, and
    initialize PACNT to 0.
  • Step 2
  • Select the falling edge as the active edge, which
    will enable TACNT to count when the PAI pin is
    high.
  • Step 3
  • Enable the PAI active edge interrupt and wait for
    the arrival of the active edge of PAI.
  • Step 4
  • Stop the pulse accumulator counter when the
    interrupt arrives.
  • To measure long pulse, we need to keep track of
    PA overflow
  • pulse_width (216 paov_cnt) PACNT 64TE
  • Example 8.13 Write a program to measure the
    duration of an unknown signal connected to the
    PAI pin.
  • Solution The assembly program is as follows

17
include "c\miniide\hcs12.inc" org 1000 paov_
cnt ds.b 1 use to keep track of the PACNT
overflow count pulse_width ds.b 3 hold the
pulse width org 1500 movw paov_isr,UserPAccOvf
set up PAOV interrupt vector ldd 0 std PACNT
let PACNT count up from 0 clr paov_cnt
initialize PACNT overflow count to
0 movb 0,TSCR2 set TCNT timer prescaler to
1 movb 72,PACTL bclr DDRT,80 configure
PAI pin for input cli enable PAOV
interrupt brclr PAFLG,PAIF, wait for the
arrival of the falling edge of PAI
movb 0,PACTL disable PA function sei
disable interrupt ldd PACNT std pulse_width1 l
daa paov_cnt staa pulse_width swi
paovISR movb PAOVF,PAFLG inc paov_cnt rti e
nd
18
Modulus Down-Counter
  • Can generate periodic interrupts
  • Can be used to latch the value of IC registers
    and the pulse accumulators to their holding
    registers.
  • The action of latching can be periodic or only
    once.
  • The clock input (E clock) to the modulus down
    counter is prescaled by 1, 4, 8, or 16.
  • The operation of the modulus down counter is
    controlled by the MCCTL register and the status
    of its operation is recorded in the MCFLG
    register.
  • The modulus down counter MCCNT is 16-bit.
  • The MCCNT register has a 16-bit load register,
    which will be reloaded into MCCNT when it
    decrements to 0.
  • When writing a value into MCCNT, the value is
    also written into the load register.

19
(No Transcript)
20
(No Transcript)
21
  • Example 8.17 Write an instruction sequence to
    generate periodic interrupt every 10 ms.
  • Solution One possible value to be written into
    the MCCTL register is C0 which will
  • Enable MCCNT
  • Enable MCCNT interrupt
  • Enable modulus mode
  • Set prescaler to 16
  • The instruction sequence to achieve the desired
    setting is as follows

movb C7,MCCTL movw 15000,MCCNT place the
value that will be decremented to to 0 in
10 ms cli enable interrupt
22
Using Modulus Down Counter to Generate Time Delay
  • It is most convenient to use the non-modulus mode
    to create time delay.
  • Example 8.18 Write a subroutine to create a time
    delay that is a multiple of 10 ms using the
    modulus down counter. The multiple is passed in
    Y. E clock is 24 MHz.
  • Solution By setting the prescaler to 16, the
    value of 15000 will take 10 ms to decrement to 0.
    The following subroutine will create a time delay
    equals to a multiple of 10 ms
  • delayby10ms
  • bset TSCR1,TFFCA enable timer fast flag clear
  • movb 07,MCCTL enable modulus down counter
    with 116 as prescaler
  • movw 15000,MCCNT load the value to be down
    counted
  • brclr MCFLG,MCZF,
  • bclr MCCTL,04 disable modulus down counter
  • dbne y,delay10ms
  • rts
  • Time delays equal to a multiple of 10 ms, 50 ms,
    1 ms, 100ms, and 1s can be created by modifying
    this subroutine.
  • These six delay functions are placed in the
    file delay.asm and can be included in users
    program.

23
Next
  • Pulse Width Modulation
  • Read Chapter 8.10
Write a Comment
User Comments (0)
About PowerShow.com