EE 308 - LAB 8

More on the HC12 Timer Subsystem

Connect one of your debounced switches to Input Capture 2 (Port T, Bit 2), as shown below:


  
Figure 1: Circuit to measure speed of button pushing.
\begin{figure}
\begin{center}
\epsfig{file=lab07_fig1.eps, width=6in}\end{center}
\end{figure}

The right part of Figure 1 is what the signal to IC2 will look like if you push the pushbutton twice.

1.
Write a program to use the HC12 to measure the time TR between the two falling edges of the signal in Figure 1. Set the prescaler so you can measure time differences up to 250 ms.

It is inconvenient to have to stop the HC12 and look at a memory location to determine what your result was. D-Bug12 has built in routines to write information to the terminal. This is documented in the application note Using the Callable Routines in D-Bug12 included with your HC12 board. In your program, TR should be a sixteen-bit unsigned number. D-Bug12 provides a C-like printf() function you can use to print information to the screen. The information below shows some examples of how to do this.

To use the D-Bug12 routines you will have to include the header file DBug12.h. This can be downloaded from the EE 308 homepage.

Here is a program to print hello, world to the terminal:

#include "DBug12.h"

main()
{
    DBug12FNP->printf("hello, world\n\r");
}

Here is a program to print an unsigned number to the screen in both hexadecimal and decimal:

#include "DBug12.h"

main()
{
    unsigned int x;

    x = 0xf000;
    DBug12FNP->printf("Hex:  %x, Decimal:  %u\n\r",x,x);
}

Add to your program a printf() function to print out the result - the number of timer ticks between pushes of the button. (Do not try to calculate the actual time as a floating point number. When you use floating point numbers the programs will be too large to load into the HC12 without using expanded memory.) You should write your program as an infinite loop so that after pressing the button twice your program will print out the result, the go wait for the next two presses.

2.
Test your program on your EVBU. See how fast you can push the switch twice.

3.
Add a TOC7 interrupt routine to generate a 500 Hz pulse width modulated signal on the OC1 pin. The duty cycle of the signal should be determined from the three least significant bits of Port B, according to this table:

PB2:0 Duty Cycle PCB:0 Duty Cycle
000 20% 100 60%
001 30% 101 70%
010 40% 110 80%
011 50% 111 90%

Show that your program works by displaying the output of the OC1 pin on the logic analyzer. While the 500 Hz signal is being generated, you should be able to measure your push-button time.

4.
Add to your program a routine for incrementing Port A using the real time interrupt as you did in Lab 7. You should simultaneously display the Port A output on LEDs and the OC1 pin output on the logic analyzer. You should still be able to measure you push-button time.



Bill Rison, <rison@ee.nmt.edu >
Tue Mar 2 1999

© 1999, New Mexico Tech