{"id":15077,"date":"2022-08-24T02:07:19","date_gmt":"2022-08-24T06:07:19","guid":{"rendered":"https:\/\/embedded-lab.com\/blog\/?p=15077"},"modified":"2023-09-06T01:32:40","modified_gmt":"2023-09-06T05:32:40","slug":"inductance-capacitance-measurement-using-pic18-microcontroller","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/inductance-capacitance-measurement-using-pic18-microcontroller\/","title":{"rendered":"Inductance-Capacitance Measurement using PIC18 Microcontroller"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When designing or debugging an electrical or electronics device, it is very important to know the values of the components that have been used on board. With a multimeter most of the components can be easily measured and identified but most ordinary multimeters do not have options to measure inductors and capacitors as this is rarely needed. However, without capacitors there are literally no circuits while complex circuits may have inductors in them. A LCR (inductor-capacitor-resistor) measurement meter can be used to determine the aforementioned components but usually such meters are pretty expensive. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"539\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-20.png\" alt=\"\" class=\"wp-image-15103\" \/><\/figure><\/div>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">Here, I will share a method with which we can measure inductors and\ncapacitors with some degree of accuracy. For the purpose, we can use a common\n8-bit microcontroller. I have used a PIC18F452. Of course, any other\nmicrocontroller will be equally suitable for the purpose as long as the\ncalculations and procedures are maintained. We will also need a small external\nanalogue circuit based on LM393 dual analogue comparator. This circuit is a\nsimple <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hartley_oscillator\">Hatley\noscillator<\/a>. The idea is to measure the frequency or time period of the\noscillator. When a new component such an inductor introduced to the oscillator,\nits frequency and therefore time period changes. We can then back-calculate\ncomponent value. &nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PIC18F452 is an 8-bit PIC18F series microcontroller. In terms of hardware is much more capable than the popular PIC16F877A or PIC16F887. However, we do not need any other hardware apart from a capture compare module (CCP) and a timer. The main reason to use a PIC18F is its operating clock speed which is 40MHz.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Schematic<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"778\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-1.png\" alt=\"\" class=\"wp-image-15079\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-1.png 975w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-580x463.png 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-1-768x613.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Components<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As shown in the circuit diagram all the components would be needed. Components L2 to L6 and C4 to C8 are test components. These are present only in simulation and not physically. Rotary switches SW1 and SW2 are only use in simulation schematic and are physically not present. A 2&#215;16 alphanumerical LCD is used for displaying info. And a button connected to pin C0 is used for mode selection. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\"> #include &lt;18F452.h&gt;  <br> &nbsp;<br> #device *=16<br> &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> #fuses NOWDT, PUT, H4, BROWNOUT, BORV42<br> #fuses NOLVP, NODEBUG, NOCPB, STVREN, CPD<br> #fuses PROTECT, NOWRT, NOWRTB, NOWRTC<br> #fuses NOWRTD, NOEBTR, NOEBTRB, NOOSCSEN<br> &nbsp;<br> #use delay(clock = 40M) &nbsp; &nbsp;<br>  <br>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> #include \"lcd.c\" &nbsp; &nbsp;<br> &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> #define mode_button &nbsp; &nbsp; &nbsp;input(pin_C0) &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> #define C_cal_in_nF &nbsp; &nbsp; &nbsp; &nbsp; 100.0 <br> #define L_cal_in_uH &nbsp; &nbsp; &nbsp; &nbsp; 100.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> #define pi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3.142 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> #define cal_delay &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;1000 &nbsp; <br><br> #define scaling_factor_c &nbsp; &nbsp;((10.0 \/ (4.0 * pi * pi * L_cal_in_uH))) &nbsp; &nbsp;<br> #define scaling_factor_l &nbsp; &nbsp;&nbsp;((10.0 \/ (4.0 * pi * pi * C_cal_in_nF))) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> unsigned int32 overflow_count = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> unsigned int32 pulse_ticks = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> unsigned int16 start_time = 0; &nbsp;<br> unsigned int16 end_time = 0; &nbsp; &nbsp;<br> &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> void setup(void); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp;<br> #int_TIMER1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> void TMR_ISR(void) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp;overflow_count++; &nbsp; &nbsp; &nbsp;<br> } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br><br><br> #int_CCP1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> void CCP_ISR(void)<br> {<br> &nbsp; &nbsp;end_time = CCP_1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp;pulse_ticks = ((65536 * overflow_count) + end_time - start_time);<br> &nbsp; &nbsp;start_time = end_time; <br> &nbsp; &nbsp;overflow_count = 0;<br> }<br> &nbsp;<br> void main(void) &nbsp;<br> {<br> &nbsp; &nbsp; short calibration_done = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; unsigned char mode = 0; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; unsigned long t = 0; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; double ref = 0.0; <br> &nbsp; &nbsp; double value = 0.0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;   <br> &nbsp; &nbsp; setup(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> &nbsp; &nbsp; while(TRUE) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> &nbsp; &nbsp; &nbsp; &nbsp; t = (pulse_ticks); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; value = ((double)t * (double)t);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; if(mode_button == FALSE)<br> &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_ms(60); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(mode_button == FALSE); &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;calibration_done = 0; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mode++;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(mode &gt; 1)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mode = 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br> &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; if(calibration_done == 0) <br> &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"\\f\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Calibrating....\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Place no part.\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delay_ms(cal_delay); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"\\f\"); &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mode == 0)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ref = (value * scaling_factor_c); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"C.ref\/nF:\"); &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(lcd_putc, \"%3.1g &nbsp; \", ref); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mode == 1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ref = (value * scaling_factor_l);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"L.ref\/uH:\"); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(lcd_putc, \"%3.1g &nbsp; \", ref); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delay_ms(cal_delay); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"\\f\");<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calibration_done = 1;<br> &nbsp; &nbsp; &nbsp; &nbsp; } <br> &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(mode)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = (value * scaling_factor_c); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Ind.\/uH:\"); &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = (value * scaling_factor_l); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Cap.\/nF:\"); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value -= ref;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if((value &lt; 0) || (value &gt; 1000)) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value = 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(lcd_putc, \"%3.1g &nbsp; &nbsp; &nbsp; &nbsp; \", value); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; delay_ms(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; }; <br> }<br> &nbsp;<br> void setup(void) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; <br> { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; setup_wdt(WDT_OFF); &nbsp;<br> &nbsp; &nbsp; setup_adc(ADC_OFF);<br> &nbsp; &nbsp; setup_adc_ports(NO_ANALOGS); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; setup_spi(SPI_DISABLED); &nbsp; &nbsp;<br> &nbsp; &nbsp; setup_psp(PSP_DISABLED); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; setup_ccp1(CCP_CAPTURE_RE);<br> &nbsp; &nbsp; setup_ccp2(CCP_OFF);<br> &nbsp; &nbsp; setup_low_volt_detect(LVD_43); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; setup_timer_0(T0_OFF | T0_8_BIT); <br> &nbsp; &nbsp; setup_timer_1(T1_INTERNAL); &nbsp;<br> &nbsp; &nbsp; setup_timer_2(T2_DISABLED, T2_DIV_BY_1, 16); <br> &nbsp; &nbsp; setup_timer_3(T3_DISABLED); &nbsp;<br> &nbsp; &nbsp; set_timer0(0);<br> &nbsp; &nbsp; set_timer1(0); &nbsp;<br> &nbsp; &nbsp; set_timer2(0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; set_timer3(0);<br> &nbsp; &nbsp; enable_interrupts(INT_CCP1); &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; enable_interrupts(INT_TIMER1);<br> &nbsp; &nbsp; enable_interrupts(global); &nbsp;<br> &nbsp; &nbsp; lcd_init();<br> &nbsp; &nbsp; lcd_putc(\"\\f\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> } &nbsp; &nbsp; &nbsp; &nbsp; <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Theory <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We know that:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"161\" height=\"60\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-4.png\" alt=\"\" class=\"wp-image-15082\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">For a known set of L and C the equation above becomes:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"222\" height=\"72\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-3.png\" alt=\"\" class=\"wp-image-15081\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We also know that the inductance of inductors adds when connected in series:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"272\" height=\"77\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-2.png\" alt=\"\" class=\"wp-image-15080\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, the total capacitance of capacitors sums up when connected in parallel:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"282\" height=\"74\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-5.png\" alt=\"\" class=\"wp-image-15083\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The above equation can be rearranged as follows:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"276\" height=\"165\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-6.png\" alt=\"\" class=\"wp-image-15084\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">We also know that:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"92\" height=\"76\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-7.png\" alt=\"\" class=\"wp-image-15085\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Thus, the above equation for unknown capacitor becomes:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"222\" height=\"190\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-8.png\" alt=\"\" class=\"wp-image-15086\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The same is equation also holds true for unknown inductor too:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"219\" height=\"196\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-9.png\" alt=\"\" class=\"wp-image-15087\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Thus,\nby knowing two different frequencies or time periods, the value of any unknown\ncapacitor or inductor can be determined. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A PIC18F452\u2019s CCP1 module along with Timer 1 is used to capture the oscillations coming out of a Hartley oscillator. With nothing unknown connected except the 100nF and 100\u00b5H reference capacitor and inductor respectively, the reference oscillation frequency is about 50kHz (about 20\u00b5s time period). Whenever a new component is added this frequency changes. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Explanation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Basing on the theory discussed, we would need PIC18\u2019s high processing speed along with a timer and capture module. We would also need an LCD to display results. The setup function shown below highlights these modules and their settings. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> void setup(void) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> \u2026<br> &nbsp; &nbsp; setup_ccp1(CCP_CAPTURE_RE);<br> \u2026<br> &nbsp; &nbsp; setup_timer_1(T1_INTERNAL); &nbsp;<br> \u2026<br> &nbsp; &nbsp; set_timer1(0); &nbsp;<br> \u2026<br> &nbsp; &nbsp; enable_interrupts(INT_CCP1); &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; enable_interrupts(INT_TIMER1);<br> &nbsp; &nbsp; enable_interrupts(global); &nbsp;<br> &nbsp; &nbsp; lcd_init();<br> &nbsp; &nbsp; lcd_putc(\"\\f\"); &nbsp; &nbsp; &nbsp;<br> } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">CCP1 module is\nset for rising edge capture. This means that CCP1 will capture Timer 1\u2019s count\nwhenever it senses rising edges. CCP modules in PIC microcontrollers usually\nwork Timer 1 module and so its count is captured. Capturing two consecutive\nrising edges result in period measurement of incoming waveform. This is what we\nwould need the most. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To further make thing work apparently in concurrent manner, interrupts are used. CCP1 interrupt is triggered when there is a rising edge capture and Timer 1 interrupt is used to keep track of timer overflows. The current and previous capture counts are stored while taking care of Timer 1 overflow. These would be used to determine time period. Timer 1 will rarely overflow because it would only overflow if the incoming waveform has very low frequency and this would literally never happen. &nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> #int_TIMER1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> void TMR_ISR(void) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> { &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp;overflow_count++; &nbsp; &nbsp; &nbsp;<br> } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> <br> #int_CCP1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> void CCP_ISR(void)<br> {<br> &nbsp; &nbsp;end_time = CCP_1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp;pulse_ticks = ((65536 * overflow_count) + end_time - start_time);<br> &nbsp; &nbsp;start_time = end_time; <br> &nbsp; &nbsp;overflow_count = 0;<br> } <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">PIC18\u2019s PLL is used to upscale an external 10 MHz crystal oscillator clock to 40 MHz. This is reflected in the fuse bit and clock settings.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> #fuses H4 \u2026.<br> &nbsp;<br> #use delay(clock = 40M) &nbsp; &nbsp; <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">However, PICs usually take 4 clock cycles per instruction and so the effective system clock frequency is 10 MHz.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"470\" height=\"77\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-10.png\" alt=\"\" class=\"wp-image-15088\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Thus, one tick of Timer 1 is: <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"73\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-11.png\" alt=\"\" class=\"wp-image-15089\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Thus, at the base frequency of 50 kHz (20 \u00b5s), Timer 1 would count:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"332\" height=\"63\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-12.png\" alt=\"\" class=\"wp-image-15090\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Since the reference inductor and capacitor values are know the following equations simply as:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"309\" height=\"333\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-13.png\" alt=\"\" class=\"wp-image-15091\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The same applies for inductor measurement too and the formula simplifies as shown below:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"288\" height=\"69\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-14.png\" alt=\"\" class=\"wp-image-15092\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The fixed constants are defined in definitions on top of the code<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> #define C_cal_in_nF &nbsp; &nbsp; &nbsp; &nbsp; 100.0 <br> #define L_cal_in_uH &nbsp; &nbsp; &nbsp; &nbsp; 100.0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> #define pi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;3.142 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> #define cal_delay &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1000 &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> #define scaling_factor_c &nbsp; &nbsp;((10.0 \/ (4.0 * pi * pi * L_cal_in_uH))) &nbsp; &nbsp;<br> #define scaling_factor_l &nbsp; &nbsp;((10.0 \/ (4.0 * pi * pi * C_cal_in_nF))) &nbsp; &nbsp; &nbsp; <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s say we want to measure 220nF. So, for this amount of capacitance, the oscillator frequency would be:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"544\" height=\"166\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-15.png\" alt=\"\" class=\"wp-image-15093\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Timer 1 would count 355 counts while\ncapturing this frequency from the oscillator. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now if we back-calculate using the formulae shown previously, the capacitor is found to be:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"338\" height=\"65\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-16.png\" alt=\"\" class=\"wp-image-15094\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, the\nreading is a bit off from actual value but close enough to actual value. The error\noccurs because timer counts cannot be anything other than integers. This error can\nbe smartly compensated in code. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The push button connected to pin C0 is used to select either inductance or capacitance measurement mode. Every time the mode is changed, calibration would be needed. The calibration procedure is simple. We just have to leave our meter with nothing connected except the reference capacitor and inductor as shown the following circuit diagram. This is the Hartley oscillator and the core part of the entire device. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"623\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-17.png\" alt=\"\" class=\"wp-image-15095\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-17.png 975w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-17-580x371.png 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/image-17-768x491.png 768w\" sizes=\"auto, (max-width: 975px) 100vw, 975px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">During this\ntime, the reference component value is measured and saved. This value would be\ndeducted during unknown component measurement. During calibration, the meter\u2019s display\nwould show instruction for not placing any external component. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After the calibration is completed, unknown components can be placed and measured accordingly. These are all what the program\u2019s main loop does.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">     while(TRUE) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br> &nbsp; &nbsp; &nbsp; &nbsp; t = (pulse_ticks); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; value = ((double)t * (double)t);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; if(mode_button == FALSE)<br> &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay_ms(60); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while(mode_button == FALSE); &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;calibration_done = 0; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mode++;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(mode &gt; 1)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mode = 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br> &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; if(calibration_done == 0) <br> &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"\\f\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Calibrating....\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Place no part.\"); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delay_ms(cal_delay); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"\\f\"); &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mode == 0)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ref = (value * scaling_factor_c); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"C.ref\/nF:\"); &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(lcd_putc, \"%3.1g &nbsp; \", ref); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(mode == 1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ref = (value * scaling_factor_l);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"L.ref\/uH:\"); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(lcd_putc, \"%3.1g &nbsp; \", ref); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delay_ms(cal_delay); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"\\f\");<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; calibration_done = 1;<br> &nbsp; &nbsp; &nbsp; &nbsp; } <br> &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; else<br> &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 1); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch(mode)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case 1:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = (value * scaling_factor_c); &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Ind.\/uH:\"); &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value = (value * scaling_factor_l); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_putc(\"Cap.\/nF:\"); &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value -= ref;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if((value &lt; 0) || (value &gt; 1000)) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value = 0;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lcd_gotoxy(1, 2); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(lcd_putc, \"%3.1g &nbsp; &nbsp; &nbsp; &nbsp; \", value); &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; &nbsp; &nbsp; delay_ms(100); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br> &nbsp; &nbsp; };  <\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Some time-proven\ngood-old tricks have been applied in this code:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Instead of measuring frequency, time period is\nmeasured. This saved one calculation step because frequency is inverse of time\nperiod. <\/li><\/ol>\n\n\n\n<ul class=\"wp-block-list\"><li>Rather than using math library, some values that\nneed to raised by some power, is simply repeated multiplied. For example, the\ntime period needs to be squared but instead it is multiplied by itself. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Definitions have been used in order to identify some\nimportant constant values and reduce calculation.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>The use of global variables has been kept to a minimum.\nAlthough the code is nothing compared to the memory resources of the PIC18 microcontroller.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Interrupt methods have been employed to make the\nprogram efficient and as less blocking as possible.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Unused hardware peripherals have been reinitialized\nto reduce power consumption and other issues. <\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Demo<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-1024x576.jpg\" alt=\"\" class=\"wp-image-15100\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-1024x576.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-580x326.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-768x432.jpg 768w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941.jpg 1815w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13005120-1024x576.jpg\" alt=\"\" class=\"wp-image-15098\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13005120-1024x576.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13005120-580x326.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13005120-768x432.jpg 768w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13005120.jpg 1822w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011057-1024x576.jpg\" alt=\"\" class=\"wp-image-15099\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011057-1024x576.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011057-580x326.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011057-768x432.jpg 768w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011057.jpg 1827w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-1024x576.jpg\" alt=\"\" class=\"wp-image-15100\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-1024x576.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-580x326.jpg 580w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941-768x432.jpg 768w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2022\/08\/IMG_20220823_13011941.jpg 1815w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"PIC18 LC Meter - Measurement of Inductance and Capacitance\" width=\"860\" height=\"484\" src=\"https:\/\/www.youtube.com\/embed\/R6ZhQxcOhSo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">All files related to this project can be found <a href=\"https:\/\/github.com\/sshahryiar\/PIC-Microcontroller-Projects\/tree\/main\/LC%20Meter\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Happy coding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Author: Shawon M. Shahryiar<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.facebook.com\/groups\/microarena\">https:\/\/www.facebook.com\/groups\/microarena<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.facebook.com\/MicroArena?ref=hl\"><em>https:\/\/www.facebook.com\/MicroArena<\/em><\/a><em> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>23.08.2022<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When designing or debugging an electrical or electronics device, it is very important to know the values of the components that have been used on board. With a multimeter most of the components can be easily measured and identified but most ordinary multimeters do not have options to measure inductors and capacitors as this is rarely needed. However, without capacitors there are literally no circuits while complex circuits may have inductors in them. A LCR (inductor-capacitor-resistor) measurement meter can be used to determine the aforementioned components but usually such meters are pretty expensive.<\/p>\n","protected":false},"author":5,"featured_media":15101,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,105],"tags":[844,896,270,1751,1752,117],"class_list":["post-15077","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-pic-projects","category-pic18f","tag-frequency-measurement","tag-lc-meter","tag-microchip","tag-pic","tag-pic18","tag-pic18f452"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/15077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=15077"}],"version-history":[{"count":7,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/15077\/revisions"}],"predecessor-version":[{"id":15403,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/15077\/revisions\/15403"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/15101"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=15077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=15077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=15077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}