/* Even Better LC Meter, an ATTINY861 based inductanace andCapacitance Meter Version LCM071125I Copyright 2007 Richard Cappels The entire project, including schematic can be found at: www.projects.cappels.org LCD library copyright Peter Fleury ( pfleury@gmx.ch http://homepage.hispeed.ch/peterfleury/) Mr. Fleury's libraries are located at http://homepage.hispeed.ch/peterfleury/avr-software.html The LCD library is included in the distribution of the Even Better LC Meter project with Mr. Fleury's permission. Compiler: 4.1.2 (WinAVR 20070525) The compiler can be downloaded from http://sourceforge.net/ Here is how to connect it: Use an Attiny861, operating with a 4 MHz clock. A crystal is recommended since the clock timing can affect accuracy, and this is designed for a 4.00 MHz clock. Connect an Hitachi 2 line x 16 character display using the HD44780 controller to Port A as described in the port pin assignments below. Displays using the KS0073 controller can be accomodated with a #define statement. accoding to the documetation supplied with Mr. Flery's library, at the URL noted above. A comparitor based LC oscilator drives the T0 input on the ATTINY861. The output of a comparitor based LC oscillator oscillates at the resonant freuency of the LC parallel combiantion. For inductance measurement, a capacitor of .01 uf is used and the resonant frequency is used to calcualte the inductance. When measuring capacitance, an approximate 1 mH inductor in parallel with a precise 1000 pf capacitor is used in parallel with the unknown capacitor and again the capacitance is calculated from the resonant frequency. Using an LM393 comparitor, readings below 20 uH should be suspect. Using an LM399 comparitor, no problems have been observed below 1 uh. Using an LM393 comparitor, readings below about 220 pf should be suspect. Using an LM399 comparitor, no problems have been observed down to 1 pf. Many thanks to Marshall Schaffer for his c tutorial and for his assistance in cleaning some compiler errors in the original projec. */ #include #include #include #include #include "lcd.h" //Global Variables volatile char Data_Ready =0; // Flag for timer0 interrupt to tell freq. measurement when time is up. volatile int counter =0; // Counts the number of timer0 interrupts. volatile double counter0_overflow = 0; // Counts the number of timer1 overflow events. volatile double ioffset; // The measurement offset value. volatile char add_decimal_point; // Flag to tell sendstring routine when to add a decimal point to the display. char numstring[16]; // Array for strings to be displayed. double component_value =0; // This corresponds to an inductor of 1.00 mh to get 1 pf ls digit for capacitance measurement. double raw_component_value; // Results of component calculation before offset is applied. double reference_inductance; // Value of inductance used to calculate capacitance. double ref_reactance = 1000; // Capacitance of .0100 uf capacitor reads 100 nh ls digit for inductance measurement. double numerator = 1e11; // For proper scaling of results in 100 nh/1pf resolution. double frequency =0; double c_calcap; // Value of capacitor used to measure the inductor that is used to measure DUT capacitance. double l_refcap; // Value of capacitor used to measure inductance. char numstring[16]; // Array for strings to be displayed. char calflag; // Used to signal that calibration button has been pushes -when value >0; double coffset; // Offset when making capacitance measurements. double loffset; // Offset when making inductance measurements. void ioinit (void) // Initialize I/O. { //Initialize output port /* I/O Pin assignments: B0 Unused. Input with pullup. B1 Taken low (grounded) to indicate capacitance is being measured. Input with pullup. B2 Taken low (grounded) to zero meter. Input with pullup. B3 Measuring indicator LED. Output. B4 Pin used for Crystal. B5 Pin used for Crystal and Clock Out. B6 Timer 0 input from LC Oscillator circuit. B7 Reset - always reads zero. A0 - A6 Are used for the LCD. A0 Data 4 Display pin 11 Output A1 Data 5 Display pin 12 Output A2 Data 6 Display pin 13 Output A3 Data 7 Display pin 14 Output A4 RS Display pin 4 Output A5 R/W Display pin 5 Output A6 E Display pin 6 Output A7 Unused Input with pullup */ PORTA = 0b10000000; DDRA = 0b01111111; PORTB =0b00000111; DDRB = 0b00001000; lcd_init(LCD_DISP_ON ); lcd_clrscr(); } ISR (SIG_OVERFLOW1) // TIMER1 Interrupt Service { if (counter ==0 ) Data_Ready = 0xFF; else; {counter --;} } ISR (SIG_OVERFLOW0) // Counter0 Interrupt Service { counter0_overflow++; } void led_on (void) //Take PORTB, bit 3 high to light LED. { PORTB =0b00001111; } void led_off (void) //Take PORTB, bit 3 low to turn LED off. { PORTB =0b00000111; } void EEPROM_write(unsigned char ucAddress, unsigned char ucData) //EEPROM write routine from Atmel ATTINY861 datasheet { /* Wait for completion of previous write */ while(EECR & (1<