EE 308 -- LAB 6
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. Your program should use interrupts to catch the time of the falling edges.

  2. 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 integer to the serial port */
            {   
                char i;
                unsigned char t,c[6];
            
                for (i=3;i>=0;i--)
                {
                    t = (n&0x0f);
                    if (t < 10)
                        c[i] = t + 48;
                    else
                        c[i] = t + 55;
    
                    n = n >> 4;
                }
                c[4] = 0x0d;
                c[5] = 0x0a;
                for (i=0;i<6;i++)
                {
                    while (!(SCSR&0x80)) ;
                    SCDR = c[i];
                }
    }
    

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

  4. 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.

  5. 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 >
Fri Feb 23 1996
© 1996, New Mexico Tech