Software of LCQ-Meter

No Life Without a Soul – The Software

Now that we know all the theoretical background and know how this can be put together in hardware we need to talk about software for the microcontroller. This is truly a topic by its own and can become quiet complex as many of the LCQ-Meter functionalities like quality measurement are very critical in timing. However at the end it is the software which enables all the functionalities of a complex microcontroller, so it is good to understand how it works.

The following paragraph will just give an overview of the software in a kind of black box design. In reality the microcontroller is programmed in C mixed with assembler routines for critical timing. The current program fills 99.9 % of the relatively large flash memory of the 16F1788 and makes intensive usage of interrupt processing.

Picture 18: Used software routines

As shown in picture 18 there is a main program which executes in an endless loop. In this loop calculation for C, L, Q etc. and the corresponding display on the LCD take place depending on the different operating mode. There is also some functionality which will be invoked if flags are set by interrupt.

For example when the user presses the calibrate button a flag will be set by the interrupt routine ISR and the main loop can call needed functionality and reset the flag afterwards. There is more user flag processing to select operation modes, select letters and numbers etc.

The interrupt service routine is very lean. Just setting flags and incrementing counters for timing purposes avoids a lot of trouble with context saving and decreased performance.

There are a lot of functions to do any kind of processing. This starts in initialization to set up correctly ports, timers, prescaler, the ADC converter and ends in specific routines to do frequency and quality measurement.

Frequency measurement is done on a most accurate base. The microcontroller’s prescaler is dynamically reconfigured to get the best resolution depending on the frequency. This methodology is also used for external frequency measurement.

The complex timing for envelope measurement like oscillator shutdown and waiting of a specific time to start the voltage measurement is programmed in assembler as a compiled language like C is not fully predictable down to needed microsecond level.

Maybe the most interesting thing is the quality Q measurement cycle. Without going too much into detail here is how it is implemented.

As frequency is measured before, the quality measurement cycle is dynamically changed depending on the signal frequency.

Take a slow signal at 100 KHz. Just measuring the envelope voltage a few microseconds after the oscillator is switched off will probably lead to wrong results. It may happen that a decreasing part of a sinusoidal cycle is measured. Therefore with low frequencies the measurement has to be much longer. The opposite is true for very high frequencies.

The cycle itself starts with measuring the base voltage (operating point) and the peak voltage U(0) of the signal and continues with a measuring loop. In this loop the oscillator is powered down to start the decrease of the envelope and each time for different time values the voltage U(t) is measured. If the voltage is for example less than 50 % of the voltage U(0) the cycle is stopped. So the time difference between U(0) and U(t) is dynamically defined by the signal itself. Having an optimal time t the voltage U(t) is measured multiple times in a second loop to get an average in order to decrease the influence of noise.

To get a little bit more transparency on this quality measurement cycle an oscilloscope plot taken from the LCQ-Meter is shown in picture 19. The blue boxes are the oscillator swings, the red line is the voltage measured with the envelope detector. We do not see the decaying envelope as this is a very large time scale. In opposite to picture 8 this is about the complete cycle.



Picture 19: LCQ-Meter quality Q measurement cycle

Each time the oscillator is started it takes some ms until the amplitude stabilization is done. After that the envelope is stable until the oscillator is shutdown.

Starting with the first vertical ruler frequency is measured shortly before, noticeable on the small noise on the red line (so there is a little bit crosstalk anyway). The first red pike is about measuring the DC operating point. Next are 10 small packets which is finding the right delay time t1 to measure u(t). Having that time t1 available 5 longer packets do follow to do a more accurate average measurement of u(t1). The next overall cycle starts after the second vertical ruler.

Functionality of The LCQ-Meter

Picture 20 shows the assembly diagram of the LCQ-Meter version 2.3 with controls.

Picture 20: LCQ-Meter controls

Most controls and terminals are self explaining. The lower 3 buttons help to describe the functionality of the LCQ-Meter.

The left button is ‘Mode Selection’. It is used to enter a setup menu but mainly to toggle between 4 different operating modes:

1)      C – Mode: Measure capacitor attached to the clamps; display capacity and measurement frequency.

2)      L – Mode: Measure inductor attached to the clamps; display inductance and measurement frequency.

3)      L||C – Mode: Measure parallel tuned circuit; display capacity, inductance, measurement frequency and quality Q if enabled by the very right button.

4)      F – Mode: Measure frequency on external connector

In the setup menu it is possible to edit a 16 digit welcome message like a call sign which will be displayed during power on. The ‘Select’ button will jump from digit to digit while the 2 buttons ‘Mode Selection’ and ‘Toogle Q’ allow moving backward and forward through a list of letters and numbers. The setup menu includes also adjusting the reference capacitor values and the constants for the equation to calculate the parasitic oscillator capacitance as explained before. Again ‘Mode Selection’, ‘Select’ and ‘Toogle Q’ are used to increase, decrease and confirm the values. Another option is to switch on and off the LCD-backlight to save power. Last option in the setup menu is factory reset to clear all done changes.

In general all changes are stored in the EEPROM and will be kept after power off. This includes the mode selection but not the ‘Toogle Q’ selection. This is intentionally set back to off. Best procedure is always first to attach a DUT and than switching on Q measurement. Otherwise there may be confusion about some seconds delay as the software is testing for a DUT which is not there.

The next button is ‘Select or Calibrate’. Selection is explained already and straight forward for the menus. Calibration starts a new calibration cycle in C- and L-Mode only. It will allow eliminating any additional capacitance and inductance brought in by measurement leads as calibration is a delta to zero calibration. That means for C – Mode the measurement leads have to be open without DUT before pressing ‘Calibrate’. For L – Mode the leads have to be shorted before pressing the button. There is no calibration possible for L||C – Mode as explained in the paragraph ‘Measurement of Capacitance and Inductance in Tuned Circuits’.

After each calibration as well as after power on the supply voltage will be displayed to warn about low battery.

The last button is ‘Toggle Q’ and switches on and off quality measurement in L||C – Mode.

Measurement and Technical Data

Examples of Assembly

LCQ-Meter Version History

Part Kits