Capacitance meter with Microchip's PIC 16F628A and DEM 16216-SGH
Some time ago I found a nice blog about creating a capacitance meter with the PIC16F628A by Roman Black. I liked the simplicity, but unfortunately I did not have the 16 Mhz crystal and only the hex file was available for download. I couldn't see whethere that would be a problem or not. Therefore I decided to build my own capacitance meter based on the same idea: use a known RC-network (270pF 5% capacitor and 10k 1% resistor) as a reference for measuring capacitance. At start up, the reference value for dT is measured, consecutive measurements are calculated by comparing dT measurement with dT reference.
capacitancemeter schema
capacitancemeter schema

However there are some design differences with Roman's approach:
  • The first capture is skipped because it is inaccurate.
  • 256 consecutive measurements are taken to calculate an accurate average (instead of waiting until more than 0.5 second passed)
  • 20 Mhz crystal is used instead of 16 Mhz. Therefore timer1's frequency is 5 Mhz (timer1 is configured as fosc /4)
  • Bigger capacitors only have between 1 and 256 captures


In a nutshell:
  • At start up, measure dT of reference capacitor dTref
  • Compare the measured amount of time dTref with the expected amount of time Texp.
  • Texp can be calculated by: 2 x R x C x ln(Vth/Vtl) where R=10000 ohm, C=270pF, Vth = 3.33V and Vtl = 1.67V => 0.0000037429947750 seconds.
  • 256 measurements at clock speed 5Mhz, every 16th rising edge, no prescalar makes 76656.5 ticks.
  • Measure reference value of capacitor Cref. Because I use a 0.1% 10000oh resistor, and a 1% 270pF the difference between measured and expected, mainly is caused by the capacitor. The real value of Cref = 270pF x dTmeasured / dTexpected
  • Consecutive measurements first need to determine the range for Cx, this is performed my detecting timer 1 overflows.
  • Measuring starts with settings pF.
  • When timer 1 overflow, the settings for nF
  • When timer 1 overflows again, settings for uF are used.
  • When this still results in timer 1 overflows, the program starts capturing in an alternative mode: each timer 1 overflow results in adding 65536 to the measured value. When a capture event occurs, then the value of timer 1 is added too. If timer 1 has more then 256 overflows when the capture event occurs, the measurings stops and the capacitance value is calculated.
  • In the first 3 modes, 256 consecutive measurements are taken, in the latter between 1 and 256 measurements are taken.

The table below shows the settings for each mode:

RangeNth rising edgePrescalarTimer1 overflowsNumber of measurements
1 (pF)16 th1No256
2 (nF)4 th2No256
3 (uF)1 st4No256
4 (uF2)1 st8Yes1...256

In order to calculate Cx, the following formula is applied: Cx = Cref * ((Mx * (16 / Nth rising edge) * prescalar - Mref) / Mref
Example measurements for all 4 modes. The reference capacitor Cref = 270 pF (5%), the reference measurement Mref = 78306
Which means that the Cref is about 275.8 pF (that is within the tolerance)
All measurements resulted in value within tolerance of capacitor. Only values below 10pF are tricky (the measeringwires add some capacitance too. This can be more than 2pF (!), the shorter the wires, the better the result. N.B. keep your fingers/hands away while measuring small caps in order to decrease the measurement error.

Cin (pF)RangeMxNmeas.Nth rising edgePrescalarExactPercentage(1)Ccalc (pF)ErrorPercentage(2)CdispUnit
22pF8481125616122.911941514.122.9110.004114.122.911pF
47pF9288925616151.364310999.351.3620.004509.351.362pF
220pF145077256161235.18112936.9234.430.319386.6234.430pF
470pF212826256161473.80697490.8471.6180.462000.3471.618pF
2200pF6770802561612109.004591-4.12107.1120.08974-4.22107.112pF
4700pF14757762561614922.1753884.74920.2720.038674.74920.272pF
22000pF588301325616120445.36622-7.120442.2960.01502-7.120442.296pF
47000pF1315709125616146066.15786-2.046064.1160.00443-2.046064.116pF
100000nF357099225642100346.30840.3100115.40.230110.1100.1154nF
220000nF728264225642204931.8367-6.8204919.40.00607-6.9204.9194nF
1000000uF439755125614991024.9746-0.9990949.40.00763-0.90.9909494uF
10000000uF220724615256189343255.217-6.692944600.52225-7.19.29446uF
220000000uF217717125918227203354.23.32271213000.036113.2227.12130uF
2200000000uF223371351118269741829922.626972412600.0065622.62697.24126uF

  • Cin = indicated value of the capacitor being measured.
  • Range see table above
  • Mx = the cumulative timer1 ticks.
  • Nmeas = the number of measurements taken.
  • Nth rising edge, see table above
  • Prescalar, see table above
  • 'Exact' = the value calculated by spreadsheet (no integer roundoffs).
  • Percentage(1) = the difference between indicated value and measured value.
  • Ccalc is the calculated value with int32 calculations
  • Error = 100 * (Ccalc - Exact) /Exact
  • Percentage(2) = the difference between indicated value and int32 calculated value.
  • Cdisp = the dispayed value
  • Unit = the displayed unit

The outcome is pretty good. Most capacitors have a tolerance of more than 10% (!) and as you can see the calculated values all within 10% except for the 2200 uF capacitor.

You can download both the ASM file and the HEX file (last update: 2013-06-09):
16f628a_cap_v5.asm
16f628a_cap_v5.hex (rename 'txt' to 'hex')

Below you can see a high-level program overview.
program overview
program overview

In the config section the oscillator mode is set to High Speed, no watch dog timer is used. The interrupt vector is set to memory locaton 'MY_INTERRUPT_HANDLER'.

__CONFIG(_HS_OSC & _WDT_OFF & _MCLRE_OFF & _BOREN_OFF & _LVP_OFF & _CP_OFF); org 0x0000 goto MAIN_INIT org 0x0004 goto MY_INTERRUPT_HANDLER

The section flag bits defines bitnumber values for specific flags. I hope the comment behind the names explains their purpose. For example the byte value MY_FLAGS has 8 bits, 5 bits are used. When bit 5 (SKC) is set, this indicates that the first capture must be skipped. Bit 4 (CAP) indicates whether caputure mode is on. Etc.

;--- MY_FLAGS --- #define SKC 5 ;Skip capture bit #define CAP 4 ;Capture mode on = 1, off = 0 #define U4B 3 ;Write upper four bits (high nibble) #define SKF 2 ;Skip frame bit #define WRT 1 ;Ready for writing bit #define LCDE 0 ;LCD Enable bit ;--- MY_MEASUREMENT --- #define AL_T1OF 4 ;allow timer 1 overflow #define DISA 3 ;display all digits #define FSTM 2 ;First measurement #define MR_0 1 ;MR[1:0] measurement range, 00 = pF, 01 = nF, 10 = uF, 11 = uF2 accepts timer1 overflows #define MR_1 0 ;First digit ;-- MY_ERRORS bits -- #define OVERFLOW 0 ;Math overflow #define UNDERFLOW 1 ;Math negative value (underflow) #define DIV0 2 ;Division by zero #define BIGCAP 3 ;Capacitance overflow

The section binary constants is used for defining constants that look like a bit-representation of a hex value. For example 'b10101010' makes more sense to me when you are interessed in which bits of port A are set then the hex value 0xAA

#define b00000000 0x00 #define b00000001 0x01 #define b00000011 0x03 ... #define b11110101 0xF5 #define b11111111 0xFF

The constants section defines other constants. In this case only one. TMR_DELTA. This value is used to initialize timer 0. Timer 0 starts at 0xF0 and counts from 0xF0...0xFF, overflows and is reset to 0xF0

#define TMR_DELTA 0xF0 ;start at: 255 - x, overflow on 255+1

The section 'bank 0, general purpose registers' defines the variables I use. They're al located in 'bank 0', hence the name. For all calculations I use 32-bits intergers (MATH_A, MATH_B, MATH_RES, MATH_TMPA, MATH_TMPB). Writing mathmetical operations like 'a divide by b', 'a times b' in assembly is a 'nice exercise'. Because the integers are actually just bytes that have to be addressed per byte. So variable MATH_A exists of 4 bytes: MATH_A3...MATH_A0. So I had to take care of checking the 'C', 'Z' flags in calculations and detect overflows, underflows, division by zero, etc. Using the simulation option in MPLAB-X was quite a relief for me in detecting errors in my algorithm. Below is a list of the variables and their purpose.

;RAM data variables bank 0 cblock 0x20 ;bank 0x20, 80 bytes general purpose register MATH_RES3 ;MATH_R3...0 32 bits unsigned int 'RESULT' MATH_RES2 MATH_RES1 MATH_RES0 MATH_TMPA3 ;MATH_TMPA3...0 32 bits unsigned int 'TMPA' MATH_TMPA2 MATH_TMPA1 MATH_TMPA0 MATH_TMPB3 ;MATH_TMPB3...0 32 bits unsigned int 'TMPB' MATH_TMPB2 MATH_TMPB1 MATH_TMPB0 MATH_A3 ;MATH_A3...0 32 bits unsigned int 'A' MATH_A2 MATH_A1 MATH_A0 MATH_B3 ;MATH_B3...0 32 bits unsigned int 'B' MATH_B2 MATH_B1 MATH_B0 MATH_C3 ;MATH_C3...0 32 bits unsigned int 'C' MATH_C2 MATH_C1 MATH_C0 MATH_D3 ;MATH_D3...0 32 bits unsigned int 'D' MATH_D2 MATH_D1 MATH_D0 MATH_REM3 ;MATH_REM3...0 32 bits unsigned int 'MATH_REM' MATH_REM2 MATH_REM1 MATH_REM0 Mx_Cap3 ;Mx_Cap3...0 32 bits unsigned int 'Mx_Cap' Mx_Cap2 Mx_Cap1 Mx_Cap0 Mx_REF3 ;Mx_REF3...0 32 bits unsigned int 'Mx_REF' Mx_REF2 Mx_REF1 Mx_REF0 C_REF3 ;C_REF3...0 32 bits unsigned int 'C_REF' C_REF2 C_REF1 C_REF0 LCD_DIV3 ;LCD_DIV3..0 32 bits unsigned int 'LCD_DIV' LCD_DIV2 LCD_DIV1 LCD_DIV0 W_TEMP STATUS_TEMP MY_ERRORS MY_FLAGS MY_MEASUREMENT LCD_BUF_00 LCD_BUF_01 LCD_BUF_02 LCD_BUF_03 LCD_BUF_04 LCD_BUF_05 LCD_BUF_06 LCD_BUF_07 CNT_VAR DLY_VAR CNT0 CNT1 CNT2 CNT3 TMR1IF_C1 ;TMR1IF_C1...0 16 bits unsigend int: number of timer1 time-outs TMR1IF_C0 CNT_RW ;number of items in LCD_BUF LCD_TMP ;buffer for tmp lcd data CAP_NR1 ;CAP_NR1...0 16 bit capture number CAP_NR0 MATH_BS ;number of bits shifted LCD_C0 ;LCD_C0...LCD_C5 6 lcd characters LCD_C1 LCD_C2 LCD_C3 LCD_C4 LCD_C5 endc

The main init section is responsible for initializing the PIC and the LCD. But I already discussed this in my previous blog PIC16F628A LCD driver (assembly)

In the capture init, the capture and compare module is initialized depending on the capture mode (pF, nF, uF, uF2). See also code comments.

init_capture_compare_module: BSF MY_FLAGS, CAP ;set capture mode flag BSF MY_FLAGS, SKC ;set skip first capture flag BCF MY_ERRORS, OVERFLOW ;clear overflow flag BCF MY_ERRORS, BIGCAP ;clear BIGCAP flag ;--- select bank 1 --- BSF STATUS, RP0 BCF INTCON, GIE ;disable all interrupt BCF INTCON, T0IE ;disable Timer 0 overflow interrupt CLRF PIE1 MOVLW b00000101 ;RA0 and RA2 as analog inputs MOVWF TRISA ;--- select bank 0 --- BCF STATUS, RP0 MOVLW b00000000 MOVWF T1CON ; - - T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON ;prescale 1:1, T1SYNC ignored, clock source: Internal clock (FOSC/4), tmr1 off MOVWF TMR1H MOVWF TMR1L MOVLW b00000110 MOVWF CMCON ;C2OUT=x, C1OUT=x, C2INV = 1, C1INV = 1, CIS = 0, CM<2:0> = 100 ;C2OUT: Comparator 2 Output bit ;C1OUT: Comparator 1 Output bit ;C2INV: Comparator 2 Output Inversion bit ;C1INV: Comparator 1 Output Inversion bit ;CIS ;Two Independent Comparators CM<2:0> = 100 ;Two Common Reference Comparators CM<2:0> = 011 ;Two Common Reference Comparators with Outputs CM<2:0> = 110 init_capture_compare_pF: MOVLW b00000111 ;Capture mode, every 16th rising edge MOVWF CCP1CON ;CCP1M<3:0>: CCPx Mode Select bits BTFSS MY_MEASUREMENT, MR_1 ; uF or F? GOTO init_capture_compare_pF_nF init_capture_compare_uF_uF2: MOVLW b00000101 ;Capture mode, every rising edge (factor 16) MOVWF CCP1CON ;CCP1M<3:0>: CCPx Mode Select bits BTFSS MY_MEASUREMENT, MR_0 ; F? GOTO init_capture_compare_uF init_capture_compare_uF2: MOVLW b00110000 ;prescale 1:8 (factor 8) MOVWF T1CON GOTO init_capture_compare_done init_capture_compare_uF: MOVLW b00100000 ;prescale 1:4 (factor 4) MOVWF T1CON GOTO init_capture_compare_done init_capture_compare_pF_nF: BTFSS MY_MEASUREMENT, MR_0 ; nF? GOTO init_capture_compare_done init_capture_compare_nF: MOVLW b00000110 ;Capture mode, every 4th rising edge (factor 4) MOVWF CCP1CON ;CCP1M<3:0>: CCPx Mode Select bits MOVLW b00010000 ;prescale 1:2 (factor 2) MOVWF T1CON init_capture_compare_done: ;0000 = Capture/Compare/PWM off (resets CCP1 module) ;0100 = Capture mode, every falling edge ;0101 = Capture mode, every rising edge ;0110 = Capture mode, every 4th rising edge ;0111 = Capture mode, every 16th rising edge ;1000 = Compare mode, set output on match (CCP1IF bit is set) ;1001 = Compare mode, clear output on match (CCP1IF bit is set) ;1010 = Compare mode, generate software interrupt on match (CCP1IF bit is set, CCP1 pin is unaffected) ;1011 = Compare mode, trigger special event (CCP1IF bit is set; CCP1 resets TMR1 ;11xx = PWM mode ;--- select bank 1 --- BSF STATUS, RP0 MOVLW b00000100 ;RB0...RB1, RB3...RB7 as outputs, RB2 as input MOVWF TRISB ;TRISB, bank 1 BCF PIE1, CMIE ;bank 1, disable comparator interrupts BSF PIE1, CCP1IE ;bank 1, enable CCP1 Interrupt Enable BSF PIE1, TMR1IE ;bank 1, enable timer 1 interrupts ;--- select bank 0 --- BCF STATUS, RP0 BSF T1CON, TMR1ON ;start timer 1 BSF INTCON, PEIE ;enable periperal interrupts BSF INTCON, GIE ;enable interrupts RETURN

In the capture interrupt routine is responsible for:
  • skipping the first measurement
  • taking n timer1 measurements
  • optionally act on the number of timer1 overflows if timer1 overflow are allowed.

capture_interrupt: ;--- BANK 0 --- BCF PIR1, CCP1IF ;bank 0, reset interrupt CCP1IF btfss MY_FLAGS, CAP ;if not captureing, stop adding captured T1 GOTO capture_stop BCF STATUS, RP0 BCF STATUS, RP1 BTFSS MY_FLAGS, SKC ;skip first capture GOTO capture_ccpr1 MOVLW 0x00 MOVWF CAP_NR1 ;bank 0, Capturenummer MOVWF CAP_NR0 ;bank 0, Capturenummer BCF MY_FLAGS, SKC ;stop skipping captures GOTO capture_end capture_ccpr1: MOVF Mx_Cap3, 0 ;copy 'Mx_Cap' to 'MATH_A' MOVWF MATH_A3 MOVF Mx_Cap2, 0; MOVWF MATH_A2 MOVF Mx_Cap1, 0; MOVWF MATH_A1 MOVF Mx_Cap0, 0; MOVWF MATH_A0 MOVLW 0x00 ;copy '0x00 0x00 CCPR1H CCPR1L' to 'MATH_B' MOVWF MATH_B3 MOVWF MATH_B2 MOVF CCPR1H, 0 ;bank 0, CCPR1H MOVWF MATH_B1 MOVF CCPR1L, 0 ;bank 0, CCPR1L MOVWF MATH_B0 CALL calc_a_plus_b MOVF MATH_RES3, 0 ;copy 'RES' to 'Mx_Cap' MOVWF Mx_Cap3 MOVF MATH_RES2, 0 MOVWF Mx_Cap2 MOVF MATH_RES1, 0 MOVWF Mx_Cap1 MOVF MATH_RES0, 0 MOVWF Mx_Cap0 BTFSS MY_MEASUREMENT, AL_T1OF ;allow TMR1IE? GOTO capture_timer1_no_overflow INCFSZ CAP_NR0, 1 GOTO capture_check_c1 ;max 256 measurements INCF CAP_NR1, 1 GOTO capture_stop capture_check_c1: MOVF TMR1IF_C1, 0 ADDLW 0xFF BTFSS STATUS, C GOTO capture_end caputure_timer1_overflow_end: call capture_stop RETURN capture_timer1_no_overflow: INCFSZ CAP_NR0, 1 ;do 256 measurements GOTO capture_end INCF CAP_NR1, 1 capture_stop: BCF T1CON, TMR1ON ;bank 0, stop timer 1 MOVLW b00000000 ;set timer 1 to b0000000000000000 MOVWF TMR1H MOVWF TMR1L BCF INTCON, PEIE ;disable periperal interrupts BCF INTCON, GIE ;disable interrupts ;--- select bank 1 --- BSF STATUS, RP0 BCF PIE1, CCP1IE ;bank 1, disable CCP1 Interrupt Enable BCF PIE1, TMR1IE ;bank 1, disable timer 1 interrupts ;--- select bank 0 --- BCF STATUS, RP0 bcf MY_FLAGS, CAP ;end of caputure RETURN capture_end: BCF T1CON, TMR1ON ;bank 0, stop timer 1 restore_prescaler: MOVLW b00000000 ;set timer 1 to b0000000000000000 MOVWF T1CON ; - - T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON ;prescale 1:1, T1SYNC ignored, clock source: Internal clock (FOSC/4), tmr1 off MOVWF TMR1H ;setting TMR1H or L resets prescaler! MOVWF TMR1L BTFSS MY_MEASUREMENT, MR_1 ; uF or F? GOTO restore_prescaler_pF_nF restore_prescaler_uF_uF2: MOVLW b00000101 ;Capture mode, every rising edge (factor 16) MOVWF CCP1CON ;CCP1M<3:0>: CCPx Mode Select bits BTFSS MY_MEASUREMENT, MR_0 ; F? GOTO restore_prescaler_uF restore_prescaler_uF2: MOVLW b00110000 ;prescale 1:8 (factor 8) MOVWF T1CON GOTO restore_prescaler_done restore_prescaler_uF: MOVLW b00100000 ;prescale 1:4 (factor 4) MOVWF T1CON GOTO restore_prescaler_done restore_prescaler_pF_nF: BTFSS MY_MEASUREMENT, MR_0 ; nF? GOTO restore_prescaler_done restore_prescaler_nF: MOVLW b00010000 ;prescale 1:2 (factor 2) MOVWF T1CON restore_prescaler_done: BSF T1CON, TMR1ON ;bank 0, start timer 1 BCF PIR1, CCP1IF ;bank 0, reset interrupt CCP1IF RETURN
On 2013-06-09, Eeuwe Vandyke wrote:

comment=Updated+schema%2C+assembly+and+hex+file.+Reset+button+for+better+calibration+of+reference+value.

On 2013-06-14, Eeuwe Vandyke wrote:

comment=Updated+measurement+table%2C+added+detailed+information+on+measurements+and+code

On 2013-12-10, Joris wrote:

comment=Hello%2C%0D%0A%0D%0AWhat+is+the+value+for+C2%3F%0D%0A%0D%0ATnx%2C%0D%0A%0D%0AJoris

On 2013-12-11, Eeuwe Vandyke wrote:

comment=Capacitor+C2+is+a+decoupling+capacitor+of+100nF.+This+is+used+to+connect+power+and+ground+pins+of+the+IC.%0DThis+acts+as+power+reservoir+for+the+fast+switching+logic+and+must+be+placed+as+close+as+possible+and+on+the+same+side+as+the+IC.

On 2014-05-23, Robert Marko wrote:

comment=Hello%2Cwhat+is+C6+value%3F%0D%0AThanks

On 2014-05-24, Eeuwe Vandyke wrote:

comment=Hi+Robert+Marko%2C%0D%0AC6+is+the+capacitor+you+want+to+measure.+I've+updated+the+picture.+I+think+the+new+picture+is+more+clear+than+the+old+one.%0D%0AThanx+for+question.

On 2014-05-25, Robert Marko wrote:

comment=Can+I+temporarily+use+16+Mhz+XTAL+until+20Mhz+one+arrives+from+Spain%3F

On 2014-05-25, Eeuwe Vandyke wrote:

It+won't+work.+During+the+first+measurement+(without+any+capacitor+attached)+the+internal+ref+expects+that+76657+ticks+equals+270pF.+That+is+correct+for+20Mhz.+For+16+Mhz+you+need+to+change+value+in+function+"display_measurement_init:"+from+256E1+to+1EEBA.+%0D%0DX-tal+++=+20+Mhz%0Dtimer+1+=+5+Mhz%0Dtick+=+0.2+usec%0D2+x+R+x+C+x+ln(Vth/Vtl)+=3.74299E-06+sec%0D256+measurements+16th+edge+=0.015331307+sec%0Dtotal+=76656.53299+ticks%0Ddoubled+for+accuracy+=153313.066%0Dhex+value+=256E1%0D%0DX-tal+=16+Mhz%0Dtimer+1+=4+Mhz%0Dtick+=0.25+usec%0D2+x+R+x+C+x+ln(Vth/Vtl)+=3.74299E-06+sec%0D256+measurements+16th+edge+=0.015331307+sec%0Dtotal+=61325.22639+ticks%0Ddoubled+for+accuracy+=122650.4528%0Dhex+value+=1EEBA%0D--------------------------------%0Ddisplay_measurement_init:%0D++++;2+ln(2)RC+=+270pF+x+10000k+=+76656.5329924855+ticks%0D++++BTFSS+MY_MEASUREMENT,+FSTM%0D++++GOTO+display_measurement%0D++++MOVF+Mx_Cap3,+0++++++++++++;copy+'Mx_Cap'+to+'Mx_REF'%0D++++MOVWF+Mx_REF3%0D++++MOVF+Mx_Cap2,+0;%0D++++MOVWF+Mx_REF2%0D++++MOVF+Mx_Cap1,+0;%0D++++MOVWF+Mx_REF1%0D++++MOVF+Mx_Cap0,+0;%0D++++MOVWF+Mx_REF0%0D%0D++++MOVF+Mx_Cap3,+0++++++++++++;copy+'Mx_Cap'+to+'MATH_B'%0D++++MOVWF+MATH_B3%0D++++MOVF+Mx_Cap2,+0;%0D++++MOVWF+MATH_B2%0D++++MOVF+Mx_Cap1,+0;%0D++++MOVWF+MATH_B1%0D++++MOVF+Mx_Cap0,+0;%0D++++MOVWF+MATH_B0%0D++++;(2700x2)+x+measurement+Mx+/+(2x+76656.5)+=>+to+keep+significance%0D++++MOVLW+0x00%0D++++MOVWF+MATH_A3%0D++++MOVWF+MATH_A2%0D++++MOVLW+0x15%0D++++MOVWF+MATH_A1%0D++++MOVLW+0x18%0D++++MOVWF+MATH_A0%0D++++call+calc_a_times_b%0D++++call+copy_result_to_math_a%0D++++;2x+76656.5+=+153313+=+0x256E1%0D++++MOVLW+0x00%0D++++MOVWF+MATH_B3%0D++++MOVLW+0x02%0D++++MOVWF+MATH_B2%0D++++MOVLW+0x56%0D++++MOVWF+MATH_B1%0D++++MOVLW+0xE1%0D++++MOVWF+MATH_B0%0D++++call+calc_a_divided_by_b%0D%0D++++MOVF+MATH_RES3,+0++++++++++++;copy+'MATH_RES'+to+'Mx_REF'%0D++++MOVWF+C_REF3%0D++++MOVF+MATH_RES2,+0;%0D++++MOVWF+C_REF2%0D++++MOVF+MATH_RES1,+0;%0D++++MOVWF+C_REF1%0D++++MOVF+MATH_RES0,+0;%0D++++MOVWF+C_REF0%0D%0D++++MOVF+Mx_Cap3,+0++++++++++++;copy+'Mx_Cap'+to+'MATH_A'%0D++++MOVWF+MATH_A3%0D++++MOVWF+MATH_B3%0D++++MOVF+Mx_Cap2,+0;%0D++++MOVWF+MATH_A2%0D++++MOVWF+MATH_B2%0D++++MOVF+Mx_Cap1,+0;%0D++++MOVWF+MATH_A1%0D++++MOVWF+MATH_B1%0D++++MOVF+Mx_Cap0,+0;%0D++++MOVWF+MATH_A0%0D++++MOVWF+MATH_B0%0D%0D++++call+calc_a_plus_b%0D%0D++++MOVF+MATH_RES3,+0++++++++++++;copy+'MATH_RES'+to+'Mx_Cap'%0D++++MOVWF+Mx_Cap3%0D++++MOVF+MATH_RES2,+0;%0D++++MOVWF+Mx_Cap2%0D++++MOVF+MATH_RES1,+0;%0D++++MOVWF+Mx_Cap1%0D++++MOVF+MATH_RES0,+0;%0D++++MOVWF+Mx_Cap0%0D%0D++++BCF+MY_MEASUREMENT,+FSTM

On 2014-05-25, Robert Marko wrote:

comment=Then+I+wont+fiddle+with+that%2CI+will+wait+until+20+Mhz+crystal+arrives%2Cotherwise+I+will+need+to+purchase+18+pin+DIL+socket+so+I+wont+have+to+unsolder+PIC+to+reprogram+it

On 2014-05-25, Eeuwe Vandyke wrote:

comment=I+understand.+I+prefer+DIL+sockets+for+PICs+over+permanent+soldering.+But+that's+just+a+matter+of+taste.+Most+of+the+times+I+start+prototyping+on+a+bread+board+with+a+ZIF-socket+and+two+PICs%3A+one+in+the+programmer+and+one+in+the+ZIF+socket+and+I+swap+them+every+program+cycle.+It+saves+me+a+lot+of+time+and+frustration.+Hopefully+your+crystal+arrives+soon.+Good+luck+anyway!

On 2014-05-25, Robert Marko wrote:

comment=Thats+a+pretty+good+idea%2Cmost+likely+i+will+purchase+a+DIL+socket+if+I+catch+enough+time+to+stop+by+nearest+electronics+shop+

On 2014-11-12, Victor wrote:

comment=Hello%2C%0D%0A%0D%0ACan+U+please+change+code+to+use+16x1+display%3F+Need+only+measurement+message+of+capasitors.+Have+a+lot+of+this+type+indicators+but+no+16x2.++%0D%0A%0D%0ATnx%2C

On 2014-11-16, Eeuwe Vandyke wrote:

comment=Hi+Victor%2C%0D%0A%0D%0AThe+code+I+supplied+is+already+suitable+for+1+x+16.%0D%0AI+only+use+one+line.+If+you+download+the+sources%2C+you+see+in+the+function+MAIN_INIT+at+line+240%2C+comments+and+statements+for+initializing+the+LCD.%0D%0A%3BN%3A+0+%3D+1-line+mode+%2C+1+%3D+2-line+mode%0D%0A%3BF%3A+0+%3D+5+x+7+dots%2C+1+%3D+5+x+10+dots%0D%0A%3B%0D%0A%3BRS+RW+DB7+DB6+DB5+DB4+DB3+DB2+DB1+DB0%0D%0A%3B0++0++0+++0+++1+++0+++X+++X+++X+++X%0D%0A%3B0++0++0+++0+++1+++0+++X+++X+++X+++X%0D%0A%3B0++0++N+++F+++X+++X+++X+++X+++X+++X%0D%0AThe+N+value+I+use%2C+is+0+which+means+we+are+using+1+x+16+mode.%0D%0AI+don't+have+a+1+x+16+LCD%2C+so+I+can't+verify+that.+Could+verify+this+for+me%3F+%0D%0AThanx.

Back to List

All form fields are required.
A confirmation mail for the comments will be send to you.