/*At90S2313 LC Meter Version 2313LCmeter_070217A Copyright 2007 Richard Cappels www.projects.cappels.org Complied with avr-gcc (GCC) 3.4.6 The compiler can be downloaded from http://sourceforge.net/ Here is how to connect it: Use an AT90S21313 or an ATTINY2313, 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 inverting RS-232 buffer to the TXD pin. This is the output fo the circuit and it will drive a dumb terminal application or a serial input LCD controller. The output is 9600 baud, no parity. A carriage return and a linefeed are sent to indicate that a new line is to be displayed. Since this LC meter displays both the measured L or C value and the oscillation frequency, a two line display is required. Alternatively, UART Transmit output can be connected wtihout an inverting buffer to the UART Receive input to an AN90S2313 or ATTINY2313 operating from the same power supply voltage, and on the same circuit board. The output of a comparitor based LC oscillator, that is used to measure the unknown L and C connects to the input of counter/timer1. In the case of inductance measurement, the expected value for the capacitor is 0.01 uf. In the case of capacitance measurement, the expected value for the inductor is 1.00 mh. 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. This code pretty much fills the flash on the ATTINY2313. */ #include #include //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 counter1_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. void ioinit (void) // Initialize I/O. { //Initialize output ports PORTB = 0b00000000; DDRB = 0xFF; PORTD = 0b01111100; DDRD = 0b01000000; /* I/O Pin assignments for AT90S2313/ATTINY2313: DO Reserved for UART RXD. D1 UART TXD. D2 Not used -AVAIABLE. D3 Taken low (grounded) to indicate capacitance is being measured. D4 Taken low (grounded) to zero meter. D5 Uses as Timer 1 clock input from LC oscillator. D6 Measuring indicator LED. D7 Does not exist as a physical port on AT90S2313/ATTINY2313. B0 - B6 Are not used. */ } void UARTinit (void) { UBRR = 25; // 9600 Baud with 4 MHz crystal. UCR = (1< 1000000000) // Error message if inductance is over 100H or 100uF. { crlf(); sendstring("RANGE"); } else { ultoa( (unsigned long) ((double) inductance), numstring, 10); // unsigned long to string crlf(); crlf(); if (!(PIND & 0b00001000)) // Display capacitance or inductance depending on D3. sendstring("C(pf)= "); else { sendstring("L(uH)= "); add_decimal_point =1; // Set a flag so inductance will be displayed with one digit to right of decimal point. } sendstring(numstring); // Send the inductance value. crlf(); sendstring("F(Hz)= "); ultoa( (unsigned long) ((double) frequency), numstring, 10); // unsigned long to string. sendstring(numstring); } } } int main (void) { ioinit (); // Initialize the I/O, the UART, and variables. UARTinit(); ioffset = 0; measure_frequency(); //This only done for a 1 second delay while the LCD identifies its firmware verion. sendstring("LCmeter070217A"); //Identify the LC meter firmware version. while (1) { measure_and_display_inductance(); //Go through measurement cycles over and over again. } return (0); }