Tuesday, February 19, 2019

LCR-T4 Oscillator Upgrade

We will replace the 8MHz crystal with a 16MHz one on LCR-T4 transistor tester.  ATMega328p can run up to 20MHz.  The old firmware still seems to run with the 16MHz, but some measurements are off.  Maybe it can be fixed with calibration, but we'll just update the firmware.

The OP_MHZ parameter in the makefile defines the operating frequency of the CPU.  We change it to 16 from 8.  Now we can also enable crystal and ceramic resonator test by defining WITH_XTAL. Only 16MHz and 20MHz are supported for crystal test at this time.   F_CPU, F_CPU_HZ and MHZ_CPU are in turn defined by OP_MHZ. 

After compilation, the program size is shown to be 95.1% full, grown 2290 bytes.  The I2C display version no longer fit in the flash, exceeded by 216 bytes.
Program:   32984 bytes (100.7% Full)(.text + .data + .bootloader)
Data:        210 bytes (10.3% Full)(.data + .bss + .noinit)
EEPROM:      912 bytes (89.1% Full)(.eeprom)
So we disable the crystal test for now, and it is 93.5% full.   After programming the flash, it runs fine.

Now we'll try to trim the code a little so we can enable the crystal test.  Before doing any size optimization, we'll try to remove some features.  Looking the memory map, removing select_color() function would yield enough saving.  We change the compile option undef LCD_CHANGE_COLOR, which saves 586 bytes.  Now we have 370 bytes to spare.
Program:   32398 bytes (98.9% Full)
(.text + .data + .bootloader)
Data:        206 bytes (10.1% Full)
(.data + .bss + .noinit)
EEPROM:      887 bytes (86.6% Full)
(.eeprom)
We can test the XTAL function.  The crystal that we replaced is measured 8000.00KHz, not bad!  A 10MHz series resonance crystal is measured 9999.77kHz series and 10.0018MHz parallel.  But it seems that it cannot measure beyond 10MHz.

We further replace the crystal with a 20MHz one.  Now when we measure the 16MHz crystal, we get 15.9948MHz series, 15.9979MHz parallel.  However, other lower frequency crystals are measured incorrectly.  We'll look into it.


No comments:

Post a Comment