Tutorial Introduction

Similar documents
Tutorial Introduction

Point System (for instructor and TA use only)

Laboratory Exercise 4

Hello and welcome to this presentation of the STM32L4 Analog-to-Digital Converter block. It will cover the main features of this block, which is used

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

o The 9S12 has a 16-bit free-running counter to determine the time and event happens, and to make an event happen at a particular time

Assignment 3: 68HC11 Beep Lab

Introduction to Mechatronics. Fall Instructor: Professor Charles Ume. Analog to Digital Converter

ECE 3610 MICROPROCESSING SYSTEMS: A SPEECH RECORDER AND PLAYER. Using the Polling I/O Method

Ocean Sensor Systems, Inc. Wave Staff, OSSI F, Water Level Sensor With 0-5V, RS232 & Alarm Outputs, 1 to 20 Meter Staff

M68HC11 Timer. Definition

N3ZI Digital Dial Manual For kit with Serial LCD Rev 3.04 Aug 2012

16 Stage Bi-Directional LED Sequencer

LCD Triplex Drive with COP820CJ

NS8050U MICROWIRE PLUSTM Interface

FRQM-2 Frequency Counter & RF Multimeter

Digital (5hz to 500 Khz) Frequency-Meter

Scans and encodes up to a 64-key keyboard. DB 1 DB 2 DB 3 DB 4 DB 5 DB 6 DB 7 V SS. display information.

RF4432 wireless transceiver module

Overview of BDM nc. The IEEE JTAG specification is also recommended reading for those unfamiliar with JTAG. 1.2 Overview of BDM Before the intr

Lecture-47 INTEL 8085A INTERRUPT STRUCTURE

N3ZI Digital Dial Manual For kit with Backlit LCD Rev 4.00 Jan 2013 PCB

Integrated Circuit for Musical Instrument Tuners

Ocean Sensor Systems, Inc. Wave Staff III, OSSI With 0-5V & RS232 Output and A Self Grounding Coaxial Staff

BASCOM-TV. TV Code Features: ICs supported: BASCOM versions:

Lab 3: Timer and Clock

DDS VFO CONSTRUCTION MANUAL. DDS VFO Construction Manual Issue 1.1 Page 1

Table of Contents Introduction

Microcontrollers. Outline. Class 4: Timer/Counters. March 28, Timer/Counter Introduction. Timers as a Timebase.

Counter/timer 2 of the 83C552 microcontroller

MUHAMMAD NAEEM LATIF MCS 3 RD SEMESTER KHANEWAL

SWITCH: Microcontroller Touch-switch Design & Test (Part 2)

LED Array Board.

Design and Implementation of Timer, GPIO, and 7-segment Peripherals

AN1324 APPLICATION NOTE

8 DIGITAL SIGNAL PROCESSOR IN OPTICAL TOMOGRAPHY SYSTEM

Sample BD Tech Concepts LLC

Fast Quadrature Decode TPU Function (FQD)

Hello and welcome to this training module for the STM32L4 Liquid Crystal Display (LCD) controller. This controller can be used in a wide range of

[Krishna*, 4.(12): December, 2015] ISSN: (I2OR), Publication Impact Factor: 3.785

8-BIT MCU WITH SINGLE VOLTAGE FLASH MEMORY, DATA EEPROM, ADC, TIMERS, SPI

2-Way Multiplexed LCD Drive and Low Cost A D Converter. Using V F Techniques with COP8 Microcontrollers AN-673

Entry Level Tool II. Reference Manual. System Level Solutions, Inc. (USA) Murphy Avenue San Martin, CA (408) Version : 1.0.

Review : 2 Release Date : 2019 Last Amendment : 2013 Course Code : SKEE 2742 Procedure Number : PK-UTM-FKE-(0)-10

RF4432F27 wireless transceiver module

A/D and D/A convertor 0(4) 24 ma DC, 16 bits

Published in A R DIGITECH

Data Conversion and Lab (17.368) Fall Lecture Outline

AVRcam Code Commentary. Version 1.3

Experiment 7 Fall 2012

35058-TE. PLJ-6LED-A LED Frequency Display Module Manual

COSC3215. Input Capture Output Compare

TV Synchronism Generation with PIC Microcontroller

STA2051E VESPUCCI 32-BIT SINGLE CHIP BASEBAND CONTROLLER FOR GPS AND TELEMATIC APPLICATIONS 1 FEATURES. Figure 1. Packages

Senior Design Project: Blind Transmitter

Chapter 4: One-Shots, Counters, and Clocks

Section bit Analog-to-Digital Converter (ADC)

0 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 1 1 Stop bits. 11-bit Serial Data format

Single Axis Position Controller

Digital Clock. Perry Andrews. A Project By. Based on the PIC16F84A Micro controller. Revision C


Chapter 18. DRAM Circuitry Discussion. Block Diagram Description. DRAM Circuitry 113

Low-Cost Voice Recognition

Design and implementation (in VHDL) of a VGA Display and Light Sensor to run on the Nexys4DDR board Report and Signoff due Week 6 (October 4)

Noise Detector ND-1 Operating Manual

Hello, and welcome to this presentation of the STM32 system window watchdog. It will cover the main features of this peripheral used to detect

Using on-chip Test Pattern Compression for Full Scan SoC Designs

AN4178 Application note

Logic Devices for Interfacing, The 8085 MPU Lecture 4

Special Applications Modules

UHF REMOTE RECEIVER INSTALLATION & PROGRAMMING

CPE 323: MSP430 LCD_A Controller

C Module Description

Dave Jones Design Phone: (607) Lake St., Owego, NY USA

IS01BFRGB LCD SmartDisplay from NKK Switches Simple implementation featuring the ATmega88PA from Atmel Complete software solution

A MISSILE INSTRUMENTATION ENCODER

Ambient Controller ACC 101 Operating manual

Real-time Chatter Compensation based on Embedded Sensing Device in Machine tools

Experiment # 4 Counters and Logic Analyzer

PHYS 3322 Modern Laboratory Methods I Digital Devices

Analog-to-Digital Conversion (Part 2) Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

Menu. 68HC12 Timer Block Diagram EEL 3744 EEL Input Capture (IC)

A summary of all menu lines available in self-diagnostic mode is shown below.

D R M A X - 2 DDS FREQUENCY SYNTHESIZED DRM MW TRANSMITTER. User s Guide (Please read carefully before using for the first time!)

The University of Texas at Dallas Department of Computer Science CS 4141: Digital Systems Lab

Step 1 - shaft decoder to generate clockwise/anticlockwise signals

Introduction to PIC Programming

802DN Series A DeviceNet Limit Switch Parameter List

Sample BD Tech Concepts LLC

Nixie Clock Type Quattro'

82C55A CHMOS PROGRAMMABLE PERIPHERAL INTERFACE

IT T35 Digital system desigm y - ii /s - iii

Segment LCD Driver Datasheet SLCD V 2.10

MODEL 2018 OPERATION MANUAL Firmware Version

XTAL Bank DDS Version 0.02 Sept Preliminary, highly likely to contain numerous errors

Product Update. JTAG Issues and the Use of RT54SX Devices

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science. EECS 150 Spring 2000

Analog-to-Digital Converter

Sequential Logic and Clocked Circuits

Transcription:

Tutorial Introduction PURPOSE - To explain how to configure and use the Timebase Module OBJECTIVES: - Describe the uses and features of the Timebase Module. - Identify the steps to configure the Timebase Module. - Write a program to configure the Timebase Module to generate periodic interrupt events. CONTENT: - 13 pages - 2 questions - 1 off-line programming exercise LEARNING TIME: - 20 minutes PREREQUISITES: - 68HC08 CPU training module Welcome to this tutorial on the 68HC08 Timebase Module (TBM). This tutorial describes the features and configuration of the TBM. Please note that on subsequent pages, you will find reference buttons in the upper right of the content frame that access additional content. Upon completion of this tutorial, you ll be able to describe the uses and features of the TBM. You ll also be able to configure the TBM to generate periodic events like auto-wake up from the low-power STOP mode. The recommended prerequisite for this tutorial is the 68HC08 CPU training module. Click the Forward arrow when you re ready to begin the tutorial.

TBM Capabilities Generates periodic interrupts at user selectable rates - Independent of the 68HC08 timer system - Clocked directly from external crystal - Software programmable at 1 Hz, 4 Hz, 16 Hz, 256 Hz, 512 Hz, 1024 Hz, 2048 Hz, or 4096 Hz - Can operate as a low-power real-time clock Can be enabled in STOP mode - Allows periodic auto wake-up from STOP mode - Eliminates external circuitry - Provides very low-power operation in micro-amps Let s begin this tutorial with a review of the TBM capabilities. You can use the 68HC08 TBM to generate periodic interrupts at user selectable rates. This is useful for running periodic diagnostics, servicing peripherals, performing maintenance, or any other regularly scheduled event. You could use the output compare function of the timer system to generate a periodic interrupt, but this method includes some software overhead. Because the TBM operates independently of the timer system, it doesn t require any overhead. Using the TBM also keeps the timer channels available for the application. In the 68HC908GP and GR product families, the TBM is clocked directly from the external crystal and not the oscillator output. MCUs with the Internal Clock Generator (ICG), such as the 68HC908KX product family, operate slightly differently than what is described in this tutorial. Check the product documentation for more information about specific differences. When the clock source is a 32 khz crystal, the TBM can be configured to generate periodic interrupts at a wide range of frequencies between1 Hz and 4096 Hz. Also, the TBM can generate timing events like those used in digital watches. With simple software, you can use the TBM as a low-power, cost-efficient, real-time clock. As an example, the TBM can be configured to generate an interrupt once per second. The TBM interrupt service routine would update seconds, minutes, hour, day, and year variables stored in RAM or non-volatile memory. The TBM can be very useful in low-power applications. To minimize current consumption and to extend battery life, the 68HC08 can be placed in STOP mode to stop the on-chip oscillator. For example, a battery operated application may enter STOP mode to wait for user input, such as from a keypad. The 68HC08 incorporates keyboard interrupt circuitry to eliminate the resistors and gating required to implement a keypad interrupt. Other battery operated applications may require the MCU to periodically wake-up to check status, take a sensor reading, or perform a diagnostic before returning to low-power STOP mode. During STOP mode, none of the on-chip peripherals are operating since they don t have a clock source. Therefore, an external interrupt or reset is normally required to wake up from this mode and resume normal operation. The TBM can be enabled to operate directly from the crystal during STOP mode. Using the auto wake-up capability of the TBM, the CPU can wake-up from STOP mode without any external circuitry, reducing system cost.

Timebase Control Register (TBCR) TBON Timebase Enabled 1 = Timebase enabled 0 = Timebase disabled and the counter initialized to 0s The Timebase enabled bit, TBON, is a read/write bit that enables the TBM. When the TBM is not needed, you can turn the Module off to reduce power consumption. The TBM counter can be initialized by clearing and then setting this bit. Reset clears the TBON bit. The Timebase interrupt flag, TBIF, is a read-only bit that is set when the Timebase counter rolls over. When Timebase interrupts are enabled, a value of 1 in this bit position indicates that an interrupt is pending. Timebase acknowledge bit, TACK, is a write-only bit that always reads as 0. Writing 1 to this bit clears the TBIF bit. Writing 0 to this bit has no effect. The Timebase interrupt enabled bit, TBIE, is a read/write bit that enables Timebase interrupts. When this bit is set to 1, the TBM will generate an interrupt when the TBIF bit is set. Reset clears the TBIE bit. The Timebase rate selection bits, TBR2-TBR0, are read/write bits that select the rate of periodic interrupts. Note that you should not change the values of these bits while the Timebase Module is enabled. The TBTST pin is not implemented. You can use the OSCSTOPEN bit in the CONFIG register to configure the TBM to operate during STOP mode. If the OSCSTOPEN bit is set, the TBM continues to be clocked directly from the crystal after execution of the STOP instruction. If this bit is cleared, the TBM will not operate in STOP mode.

Timebase Rate Selection The table shows the different bit codes for the Timebase rate selection bits (TBR2-TBR0). This rate selection table is based on a 32.768 khz external clock. As you can see, we can generate frequencies between 1 Hz and 4096 Hz. Changing the external clock will generate sub-multiples of these frequencies.

TBM Block Diagram TBON CGMXCLK 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2048 8192 32768 TBR2 TBR1 TBR0 8 16 32 64 128 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 TBIF Now, let s review TBM operations using the TBM block diagram. The TBM generates a periodic interrupt by dividing the external crystal frequency, CGMXCLK. The counter is made up of 15 divider stages that are initialized to 0 when the TBON bit is cleared. Eight of the 15 stages are user-selectable with the Timebase rate selection bits (TBR2-TBR0). As we discussed earlier, the rate selection bits enable you to select one of eight periodic interrupt rates. The counter starts counting when the TBON bit is set. When the TBM has counted up to the the tap selected by TBR2-TBR0, the TBIF bit is set. If the TBIE bit is set, an interrupt request is sent to the CPU. The TBIF flag is cleared by writing a 1 to the TACK bit. Note that the first interrupt that is generated after enabling the Timebase Module will occur at approximately half of the overflow period. Subsequent events will occur at the exact period.

TBM Interrupt Vector Source TimeBase ADC Conv. Complete Keyboard Pin SCI Trans. Complete SCI Transmitter Empty SCI Input Idle SCI Receiver Full SCI Receiver Overrun SCI Noise Flag SCI Framing Error SCI Parity Error SPI Transmitter Empty SPI Receiver Full SPI Overflow SPI Mode Fault TIM2 Overflow TIM2 Channel 1 TIM2 Channel 0 TIM1 Overflow TIM1 Channel 1 TIM1 Channel 0 PLL IRQ SWI Reset Vector Address $FFDC - $FFDD $FFDE - $FFDF $FFE0 - $FFE1 $FFE2 - $FFE3 $FFE4 - $FFE5 $FFE6 - $FFE7 $FFE8 - $FFE9 $FFEA - $FFEB $FFEC - $FFED $FFEE - $FFEF $FFF0 - $FFF1 $FFF2 - $FFF3 $FFF4 - $FFF5 $FFF6 -$FFF7 $FFF8 - $FFF9 $FFA - $FFFB $FFFC - $FFFD $FFFD - $FFFF Flag TBIF COCO KEYF TC SCTE IDLE SCRF OR NF FE PE SPTE SPRF OVRF MODF TOF CH1F CH0F TOF CH1F CH0F PLLF IRQF None None Mask TBIE AIEN IMASKK TCIE SCTIE ILIE SCRIE ORIE NEIE FEIE PEIE SPTIE SPRIE ERRIE ERRIE TOIE CH1IE CH0IE TOIE CH1IE CH0IE PLLIE IMASK1 None None Priority 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 The TBM has its own interrupt vector to eliminate polling for the interrupt source. The vector map shown is for the 68HC908GP32 MCU. Check the device technical data book to determine the specific vector address for different 68HC08 derivatives. Note that the TBM has the lowest priority as its periodic rate is relatively slow.

Question With the TBM enabled and the TBIE bit set to 0, what happens when the TBM counter rolls over? Click on your BEST choice. a) The TBON bit is set to 1 b) The TBIF bit is set to 1 c) The TBIF bit is cleared d) A TBM interrupt is generated e) a and d f) b and d Let s review what we ve discussed so far with a couple of questions to check your understanding of the material. With the TBM enabled and the TBIE bit set to 0, what happens when the TBM counter rolls over? Click on your best choice. Answer: When the TBM counter rolls over, it sets the TBIF flag to 1. Note that in this example, TBM interrupts are disabled because the TBIE bit is set to 0.

Question Using a 32.768 KH crystal for the external clock source, what value do you need to set the Timebase rate selection bits to in order to generate an event every 62.5 ms? Select the values for TBR2-TBR0. Click on your choice. a) 010 b) 101 c) 011 d) 001 Using a 32.768 khz crystal for the external clock source, what values do you need to set the Timebase rate selection bits to in order to generate an event every 62.5 ms? Select the values for TBR2-TBR0. Click on your choice. Answer: An event rate of 62.5 ms gives an event frequency of 16 Hz. Dividing the clock frequency by the event frequency yields a divider value of 2048. You can select this divider value by setting TBR2- TBR0 to 010.

Programming Exercise Write a program to configure the TBM to generate a periodic signal. - Generate a 1 Hz square signal. - Use port C of the 68HC908GP32 MCU for output. - Set XTAL = 4.9152 MHz. - Enable TBM interrupts. Write a subroutine to initialize the MCU out of reset. Write an interrupt service routine. - Acknowledge Timebase interrupt. - Toggle port C. - Reset Timebase counter. Now that we ve discussed how to configure the TBM, let s write a program to generate a periodic signal. For this example, let s generate a 1 Hz square signal using port C of the 68HC908GP32 MCU for the output. Use a Timebase rate, XTAL, of 4.9152 MHz and enable Timebase interrupts. In addition to your main program, write two subroutines. Use one subroutine to initialize the MCU out of reset. Use a second subroutine as an interrupt service routine. In the interrupt service routine, acknowledge the Timebase interrupt, toggle port C, and reset the Timebase counter. Take a moment to review the exercise instructions. When you re finished writing your program, click the Forward arrow to continue the tutorial and review the exercise solution.

Solution - MCU Initialization * ------------------------------------------------------------------- * 68HC908GP32 Initialization * ------------------------------------------------------------------- MOV #%00001011,CONFIG1 ; Configure the CONFIG1 Register ; \\\\\\\\ COP Module disabled ; \\\\\\\ STOP Instruction Enabled ; \\\\\\ Stop mode recovery after 4096 CGMXCLK cycles ; \\\\\ LVI operates in 5V mode ; \\\\ LVI module enabled ; \\\ LVI module Resets enabled ; \\ LVI disabled during STOP mode ; \ COP time period 262,128 cycles MOV #%00000011,CONFIG2 ; Configure the CONFIG2 Register ; \\\\\\\\ Internal Bus Clock used as a source for SCI ; \\\\\\\ Oscillator enabled to operate during Stop Mode ; \\\\\\ Voltage regulator ON (Vdd > 3.6v) ; \\\\\ Unimplemented CLRA ;Initialize the Accumulator LDHX #ENDRAM ;Stack Pointer -> End of RAM TXS ; (H:X -> SP) ; END MCU Initialization Let s review the exercise solution beginning with the MCU initialization subroutine. You can use this subroutine as a template for all of the programs you write. This subroutine initializes the MCU using the CONFIG1 and CONFIG2 registers. Recall that these registers can be configured only once after reset to avoid inadvertently changing the MCU configuration during an application. Therefore, configuring these registers should be the first step when starting. For this example, we use CONFIG1 to disable the COP so that we don t have to feed the counter to avoid reset. We also enable the STOP instruction and enable the LVI to operate at 5V. In CONFIG2, we select the internal bus clock as the source for the serial communication. We also enable the oscillator to operate during stop mode so that we can use the TBM periodic wake-up feature. Note that the configuration of the CONFIG2 register is not critical for this application. Alternatively, we could use the default initialization for this example. The next instruction, CLRA, initializes the accumulator to avoid uninitialized register warnings in the simulator/debugger, although this may not be necessary in your application. The next two instructions redirect the stack pointer to the end of the RAM. Remember that in order to keep compatibility with the HC05 family, the HC08 family automatically initializes the stack pointer to $00FF after reset.

Solution - Main Program * ------------------------------------------------------------------- * Application * ------------------------------------------------------------------- MOV #$FF,DDRC ; Enable Port C as output MOV #%00000110,TBCR ; Program the Time Base Register ; \\\\\\\ Time Base Module ON ; \\\ \ Enable Time Base Interrupt ; \\\ Select Timebase Rate (Div 2^15) ; @XTAL=4.9152MHz -> Freq=150Hz MOV #COUNT,Counter ; Initializes counter CLI ; Enable Interrupts ; END Application BRA * ; Waits for interrupt Next, compare your main program with the one provided in the solution. This section of code is where we start to work with the Timebase Module. To generate a 1Hz square signal, we have to toggle the output every 500ms. To measure 500ms with a 4.9152MHz crystal, we need to use the higher rate divisor of 2^15, or a value of 32,768. Dividing the frequency by 32,768 gives us 150 events per second, or 75 events to generate 500ms. In order to facilitate the process, we measure the events using interrupts. We ll configure port C to output the square signal. Next, configure the Timebase register. Enable the Timebase interrupt, select the default Timebase rate, and turn the Module on. We need a counter to count the 75 events before we toggle the output. Reserve one byte in RAM for this counter and initialize it using a value of 75. Finally, we enable interrupts with CLI and wait for the TBM interrupt.

Solution - Interrupt Service Routine TBM_Int_Serv: BSET TACK,TBCR ; Acknowledge TB Interrupt DEC Counter BNE Exit ; Decrements COUNTER and exits ; if NOT Zero COM PORTC ; If counter=0 -> Toggle Port C : (time = 0.5 secs) MOV #COUNT,Counter ; Resets COUNTER Exit: RTI ; END TBM_Int_Serv In the interrupt service routine, we check whether it s time to toggle the output. To do this, we first acknowledge the Timebase interrupt to avoid reentering after RTI. Next, we decrement the counter and check whether it has reached a value of zero. If not, we exit the subroutine and wait for the next event. If the counter has reached a value of zero, this means that 500 msecs have elapsed. We then toggle port C, reinitialize the counter to 75, and start over again.

Tutorial Completion - Timebase Module Uses and Capabilities - Timebase Configuration In this tutorial, you ve had an opportunity to learn typical uses and capabilities of the 68HC08 Timebase Module. You ve learned how to configure and use the TBM Module and demonstrated this by writing a program to generate a 1khz square wave.