EE 308 -- LAB 7
More on the HC11 Timer Subsystem

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

  
Figure 1: Circuit to measure speed of button pushing.

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 HC11 to measure the time between the two falling edges of the signal in Figure 1. Set the prescaler so you can measure time differences up to 500 ms.

  2. Run your program on the simulator. As in last week's lab, load BUFFALO into the simulator with the command SCRIPT E:\EE308\E.SCR. Set a breakpoint at the first line of your Input Capture 2 interrupt service routine. Set Port A so the Input Capture 2 is high. Start the program running. Stop the program, and change the Port A value so that Input Capture 2 is low. Note the values of TCNT and TIC2. Continue your program. It should stop when your interrupt service routine is called. What are the values of TCNT and TIC2 now? Why?

  3. Attach the following write_to_serial() function to your program. When you call this function with the time you calculated in Part 1, it will print the time on the terminal. Call the function in your program to display the time.

            int write_to_serial(unsigned short n)
            /* Routine to write an unsigned integer to the serial port */
            {   
                char i;
                unsigned char t,c[6];
            
                for (i=3;i>=0;i--)       /* Four nibbles, starting with rightmost */
                {
                    t = (n&0x0f);        /* Isolate right-most four bits */
                    if (t < 10)          /* Convert to ASCII */
                        c[i] = t | 0x30;
                    else
                        c[i] = t + 55;
    
                    n = n >> 4;          /* Pick up next four bits to the left */
                }
                c[4] = 0x0d;             /* Add a CR LF to the end */
                c[5] = 0x0a;
                for (i=0;i<6;i++)        /* Send the 6 bytes out the serial port */
                {
                    while (!(SCSR&0x80)) ; /* Wait until transmitter ready */
                    SCDR = c[i];           /* Send bit to RS-232 transmitter */
                }
            }
    

    Also, add the following two lines of code to the initialization portion of your main program. It initializes the HC11's RS-232 port to 9600 baud.

            SCCR2 = 0x08;      /* Enable RS-232 transmitter */
            BAUD = 0x30;       /* Set RS-232 baud rate to 9600 */
    

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

  5. Add a TOC2 interrupt routine to generate a 1000 Hz square wave on the OC2 pin. Show that it works by displaying the output of the OC2 pin on the logic analyzer. While the 1 kHz signal is being generated, you should be able to measure your push-button time.

  6. Combine your 1000 Hz wave program with the Lab 5 program for incrementing Port B using the RTI. You should simultaneously display the Port B output on LEDs and the OC2 pin output on the logic analyzer. You should still be able to measure you push-button time.



Bill Rison, <rison@ee.nmt.edu >
Tue Feb 24 1997

© 1997, New Mexico Tech