DOC PREVIEW
NMT EE 308 - Pulse Accumulator on the HCS12

This preview shows page 1-2 out of 7 pages.

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

Unformatted text preview:

- The 9S12 Pulse Accumultor - ECT_16B8C Block User Guide - Huang, Sections 8.8Pulse Accumulator on the HCS12• A pulse accumulator counts the number of active edges at the input of its channel.• The HCS12 has four 8-bit pulse accumulators, configurable as two 16- bit pulse accumulators. In the following we will discuss the 16-bit pulse accumulator PACA, made up of the two 8-bit pulse accumulators PACN3 and PACN2.• To use the pulse accumulator connect an input to Port T7 (PT7).• The pulse accumulator operates in two modes:1. Event-Count Mode2. Gated Time Accumulation Mode• In Event-Count Mode, the pulse accumulator counts the number of rising or falling edges on Port T7– You can set up the pulse accumulator to select which edge to count– The counts are held in the 16-bit PACA register– On each selected edge the PAIF flag of the PAFLG register is set– When PACA overflows from 0xFFFF to 0x0000, the PAOVF flag of the PAFLG register is set• In Gated Time Accumulation Mode the pulse accumulator counts clock cycles while in the input to Port T7 is high or low– In Gated Time Accumulation Mode the pulse accumulator uses the Timer Clock. To use the pulse accumulator in Gated Time Accumulation Mode you must enable the Timer Clock by writing a 1 to the TEN bit of TSCR– You can set up the pulse accumulator to count while PT7 is high or to count while PT7 is low– The clock for the pulse accumulator is the bus clock divided by 64– With an 24 MHz bus clock, the clock frequency of the pulse accumulator is 375 kHz, for a period of 2.67 μs– For example, if the pulse accumulator is set up to count while Port T7 is high, and it counts 729 clock pulses, then the input to Port T7 was high for 729 x 2.67 μs = 1.94 msThe Pulse Accumulator• The pulse accumulator uses PT7 as an input– To use the pulse accumulator make sure bit 7 of TIOS is 0 (otherwise PT7 used as output compare pin)– To use the pulse accumulator make sure bits 6 and 7 of TCTL3 are 0 (otherwise timer function connected to PT7)• The pulse accumulator uses three registers: PACTL, PAFLG, PACA• To use the pulse accumulator you have to program the PACTL register• The PAFLG register has flags to indicate the status of the pulse accumulator– You clear a flag bit by writing a 1 to that bit• The count value is stored in the 16-bit PACA register– You may write a value to PACA– Suppose you want an interrupt after 100 events on PT7– Write -100 to PACA, and enable the PAOVI interrupt– After 100 events on PT7, PACA will overflow, and a PAOVI interrupt will be generated0 PAEN PAMOD PEDGE CLK1 CLK0 PAOVI PAI PACTL0x00600 0 0 0 0 0 PAOFV PAIF PAFLG0x0061PAEN: 1= Enable PAPAMOD: 0=Event count mode 1=Gated time accumulator modePEDGE: 0=Falling edge (event) High enable (gated) 1=Rising edge (event) Low enable (gated)PAI: 0=Interrupt disabled 1=Interrupt enabled PAOVI: 1=Enable interrupt, when edge on PT7 If PEDGE=0, interrupt on falling edge If PEDGE=1, interrupt on rising edgeThe 16-bit PACA register is at address 0x0062The Pulse Accumulator PACA• Here is a C program which counts the number of rising edges on PT7:#include "hcs12.h"#include "DBug12.h"#define PACA *(unsigned int *) 0x62; /* pulse accumulator*/int start_count,end_count,total_count;main(){int i;TIOS = TIOS & ~0x80; /* PT7 input */TCTL3 = TCTL3 & ~0xC0 /* Disconnect IC/OC logic from PT7 */PACTL = 0x50; /* 0 1 0 1 0 0 0 0 *//* | | | | | *//* | | | | \_ No interrupt on edge *//* | | | \___ No interrupt on OV *//* | | \___________ Rising Edge *//* | \_____________ Event Count Mode *//* \____________ Enable PACA (16 bit)*/start_count = PACA;for (i=0;i<10000;i++) ; /* Software Delay */end_count = PACA;total_count = end_count - start_count;DB12FNP->printf("Total counts = %d\r\n",total_count);}The Pulse Accumulator PACA• Here is a C program which determines how long the input on PA7 ishigh:#include "hcs12.h"#include "DBug12.h"#define PACA *(unsigned int *) 0x62; /* pulse accumulator */int start_count,end_count,total_count;main(){int i;TSCR = 0x80; /* Turn on timer clock */TIOS = TIOS & ~0x80; /* PT7 input */TCTL3 = TCTL3 & ~0xC0 /* Disconnect IC/OC logic from PT7 */PACTL = 0x60; /* 0 1 1 0 0 0 0 0 *//* | | | | | *//* | | | | \_ No interrupt on edge *//* | | | \___ No interrupt on OV *//* | | \_____ Count while input high *//* | \_______ Gated Counter Mode *//* \_________ Enable PACA (16 bit mode) */start_count = PACA;while ((PTT & 0x80) == 0) ; /* Wait input goes high */while ((PTT & 0x80) == 0x80) ; /* Wait input goes low */end_count = PACA;total_count = end_count - start_count;DB12FNP->printf("Total clock cycles = %d\r\n",total_count);}Review for Final Exam• Numbers– Decimal to Hex (signed and unsigned)– Hex to Decimal (signed and unsigned)– Binary to Hex– Hex to Binary– Addition and subtraction of fixed-length hex numbers– Overflow, Carry, Zero, Negative bits of CCR• Programming Model– Internal registers – A, B, (D = AB), X, Y, SP, PC, CCR• Addressing Modes and Effective Addresses– INH, IMM, DIR, EXT, REL, IDX (Not Indexed Indirect)– How to determine effective address• Instructions– What they do (HCS12 Core Users Guide)– What machine code is generated– How many cycles to execute– Effect on CCR– Branch instructions – which to use with signed and which with unsigned• Machine Code– Reverse Assembly• Stack and Stack Pointer– What happens to stack and SP for instructions (e.g., PSHX, JSR)– What happens to stack and SP for interrupt– What happens to stack and SP when program leaves an interrupt service routine• Assembly Language– Be able to read and write simple assembly language program– Know basic psuedo-ops – e.g., equ, dc.b, ds.w– Flow charts• C Programming– Setting and clearing bits in registers PORTA = PORTA | 0x02; PORTA = PORTA & ~0x0C;– Using pointers to access specific memory location or port. * (unsigned char *) 0x0400 = 0xaa; #define PORTX (* (unsigned char *) 0x400)• Interrupts– Interrupt Vectors (and reset vector)_ How to set interrupt vector in assembly_ How to set interrupt vector in C– How do you enable interrupts (specific mask and general mask)– What happens to stack when you receive an enabled interrupt– What happens when you leave ISR with RTI instruction?– What setup do you need to do before enabling interrupts?– What do you need to do in interrupt


View Full Document

NMT EE 308 - Pulse Accumulator on the HCS12

Documents in this Course
Load more
Download Pulse Accumulator on the HCS12
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 Pulse Accumulator on the HCS12 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 Pulse Accumulator on the HCS12 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?