Control register tscr1 address 0046 bit 7 timer

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: system control register (TSCR1) – Address: $0046 – Bit 7: Timer Enable (0 disable; 1 enable) 7: Timer Enable (0 disable; enable) • Counter starts from $0000 when TEN is first set to 1. 1. • TCNT cannot otherwise be set HCS12 Timer Systems Timer Systems • Timer Interrupt Flag (TFLG2) – Address $004F – Bit 7: timer overflow flag (TOF) • • • • Goes HI (‘1’) when TCNT overflows (from FFFF to 0000) HI when TCNT overflows (from FFFF to 0000) Can be polled by software to catch overflow Can activate an interrupt if enabled Bit set TOF to clear TOF flag set TOF to clear TOF flag Cannot set TOF to 1 Can be done with in interrupt service routine HCS12 Timer Systems HCS12 Timer Systems • Timer system control register 2 (TSCR2) – Address: $004D – Bit 2:0 prescale factor – Bit 7: timer overflow interrupt (TOI) 7: timer overflow interrupt (TOI) • Enables interrupt when TOF goes high • TOF interrupt service vector: $FFDE:$FFDF, where interrupt will look for addr to begin service subroutine HCS12 Timer Systems Timer Systems • Avoid using STORE instruction to set control bits. using STORE instruction to set control bits. –Could modify other bits in that register –Use bit_set/clear instructions to set specific bit instructions to set specific bits • EX: Two input capture events occur at counts Two input capture events occur at counts $0037 and $FB20, if fclk=2MHz and prescale bits PR=011, how much time between two events? HCS12 Timer Systems HCS12 Timer Systems • EX: Assume fclk=2MHz and PR was set to 001, clk how many TOFs will occur in one minute? • EX: Write code to use timer for 0.5 msec delay Write code to use timer for msec delay at fclk=8 MHz. HCS12 Timer Systems Timer Systems • Other timer functions timer functions – Input capture Capture/store free running timer value when (counter) rising/falling (configurable) edge occurs on assigned pin (PortT) – Output compare compare Generate output signal (high, low, pulse, periodic wave) to desired specifications. – Pulse Accumulator Count pulse (clock cycles) on a specific input pin. Timer Interrupts Timer & Interrupts • Design HC12 system where timer overflow HC12 system where timer overflow (TOF) creates highest priority interrupt possible possible. Software: Hardware: Timer & Interrupts Interrupts • Connect a microcontroller to 64 addressable sensors with 1-bit output (Y/N). Software poll sensors. Generate interrupt if sensor output =1 longer than 1msec. Assume hardware timer can be set to overflow (TOF) at 1msec & TOF is an output pin....
View Full Document

Ask a homework question - tutors are online