Previous Next



This program was originally written by Ben Greenblatt in assembly. The gist of the program remains the same with only one difference: this tutorial is now written in Codevision AVR C compiler. For more information regarding the general idea behind digital capacitance meter (DCM), please consult Ben Greenblatt’s tutorial in asm.

The system developed in this example is a digital capacitance meter (DCM). It is capable of reading capacitances in the range 1nF~200nF. A measurement is initiated whenever a key is pressed on the keyboard, and the output is sent to the PC through the UART. The circuit used is shown in figure 1. The capacitor to be measured is place in an RC circuit.
When the voltage on the capacitor reaches



The analog comparator triggers an interrupt. The analog comparator is hooked to the input capture function of Timer1. The time needed to charge the capacitor is stored in the Timer 1 Capture Register. Since the charging of the capacitor follows theequation

Vc=Vcc(1-e t/RC),

it takes t=RC seconds to trigger the interrupt. At R=16k and a clock divider value of 64, one clock tick represents one nF.

Previous Next