You will produce a digital capacitance meter (DCM) which is controlled and read over an RS-232 serial line connected to a PC window. The DCM will measure capacitances from 1 to 100 nF and display the capacitance in the window on the PC.
Note that you will be using a different model mcu, the AT90S4414, for this lab. Read the AT90S4414 data sheet.
The approach we will use is to measure the time for a RC circuit to charge to a given level. Since R will be known, we can get C. Specifically, we will use the internal analog comparator as shown in the following diagram. Power for the circuit, Vcc, will come from PortB0. The bit will be set to output and logical 1.
The capacitor shown is the device you are trying to measure. The resistor going to PortB2 should be around 100 ohms. The other three you must choose. If you choose R2, R3, R4 correctly, you can save lots of arithmetic and program logic. Considerations might include choosing R3 and R4 to produce a voltage at PortB3 of (Vcc)(1-e-1) and choosing R2 so that the number of timer0 ticks which occur during the time when the voltage at PortB2 is less than the voltage at PortB3 is easily related to the capacitance. We will supply 10k potentiometers so that you can easily set values for R3 and/or R4.
Your program will have to (in time order):
One way of handling the serial i/o is to have interrupt routines for transmit and receive functions. This scheme allows the fast cpu to perfrom other functions while waiting for the slow serial interface. A demo program shows basic UART transmit and receive interrupt routines for the AT90S4414 mcu. You can use this fragment as a test that the RS232 connnections and terminal program on the PC are correct. The serial port (connector J131) should be connected to COM2 of the PC. You should use a simple terminal program, such as Hyperterminal, on the PC connected to COM2. The terminal program should be set to 9600 baud, no parity, one stop bit, and no flow control.
The UART receive is on PortD0, which should be connected to J132, pin1 (the left pin when the buttons are near you). The UART transmit is on PortD1, which should be connected to J132, pin2. These connections assume a RS232 cable to the PC with straight-through connection.
Note that the 'transmit buffer empty" interrupt is set when the mcu is reset. This means that you must initialize the message pointer before you enable interrupts, or you will get garbage sent to the terminal at each reset.
Write a program which will repeatedly:
Capacitance = xxx nf(CR)(LF)over the J131 serial port to a terminal window on the PC. The
(CR)(LF)represents carriage-return and line-feed characters. The
xxxrepresents a three digit ascii number.
When you demonstrate the program to a staff member, you should exercise the keyboard command typed from the PC and show that the capcitance displayed in the PC window is correct.
Your written lab report should include: