ESR Meter
ESR Meter
ESR Meter
;
;
;
,
;
;
;
;
,
,
:
,
:
,
:
:
:
:
,
:
:
,
15
16
17
18
19
20
21
22
23
24
25
26
27
28
*
*
*
*
*
*
*
*
*
*
*
*
*
*
;************************************************* *****************************
**********
Port_A_Config equ 0xFF
; Port A bit equates
Kn_Set equ 2
Kn_Plus equ 4
Kn_Minus equ 5
Port_B_Config equ b'11000000 '
Port_C_Config equ b'11000100 '
; Port C bit equates
Cap_Charge equ 0
Cap_Discharge equ 1
Comp_Up equ 2
In_N_Gnd equ 3
In_P_Cx equ 4
In_N_Cx equ 5
Comp_Low equ 6
ESR_ready equ b'00110011 '; incl. discharge, "+" and "-" control at the Cx
ESR_start equ b'00110000 '; incl. charge, "+" and "-" control at the Cx
Cap_ready equ b'00011011 '; incl. razdyad "-" control on the ground, "+" on Cx
Cap_start equ b'00011000 '; incl. charge, "-" control on the ground, "+" on Cx
Cap_start2 equ b'00110000 '; incl. charge, "-" control at Cx, "+" on Cx
Max_Count equ .70; the maximum number (1 byte, not more than 256) when TMR0 over
flows account
; Step account - 0.2 ms, 65536 * 0.2 = 13107.2 ms - one overflow
, Or when I = 10mA 15 counts / uF 65536/15 = 4369 microfarads - one overflow
; Let Cx = max 150000mkF, 150000/4369 = 34
; Given time charge to the lower boundary of the constant need to redouble
;************************************************* *****************************
**********
list p = PIC16F873a
# Include P16F873a.inc;; 20.000 MHz
__CONFIG _CP_OFF & _BODEN_OFF & _HS_OSC & _WRT_OFF & _WDT_OFF & _PWRTE_ON & _DEB
UG_OFF & _CPD_OFF & _LVP_OFF
; # Define _BAT PORTA, 1, 0 - low bat
# Define _RS PORTB, 4
# Define _E PORTB, 5
CBLOCK 0x35; 0x20-0x34 for FLOATING POINT LIBRARY
; Data blocks
W_TEMP; preserve the context of interrupted
STATUS_TEMP
PCLATH_TEMP
Dly0; Stores 3 bytes of data for the delay count
Dly1; Dly0 is the least significant byte
Dly2; while Dly3 is the most significant byte
; Temp
Temp1
Temp2
Temp3
Temp4
Count1
Count2
T0
; Data blocks
T2; High Byte
T3
T4
T5; Byte
AX; High Byte
A0
A1
A2; Byte
A3
A4
A5
BCD0; Byte
BCD1
BCD2
BCD3
BCD4; High Byte
U330_L; voltage output from the controller, gain = 330, low byte
U330_H; voltage output from the controller, gain = 330 byte
U33_L; voltage output from the controller, gain = 33, low byte
U33_H; voltage output from the controller, gain = 33, byte
TMR1_Count; TMR1 counter overflows
TMR0_Count; TMR0 counter overflow
Flags
EE_ADR; helper cell to work with EEPROM
EE_DATA
NZ; number of significant digits for output to display
NC; number of constants
Const_ADR; address constants in the EEPROM
ENDC
CBLOCK 0xB5
W_TEMP1; preserve the context of interrupted
ENDC
;=========================
; MACROS
;=========================
bank0 macro
bcf STATUS, RP0
endm
bank1 macro
bsf STATUS, RP0
endm
Dly24 MACRO DLY
; Take the delay value argument from the macro, precalculate
; The required three RAM values and load the The RAM values Dly2, Dly1
; And Dly0.
banksel Dly0
movlw DLY & H'FF '
movwf Dly0
movlw DLY>> D'08 '& H'FF'
movwf Dly1
movlw DLY>> D'16 '& H'FF'
movwf Dly2
;************************************************* *****************************
*
; START PROGRAM
;************************************************* *****************************
*
nop; for MPLAB-ICD2
goto init
;------------------ Interrupt -----------------org 0x004
movwf W_TEMP; save W
swapf STATUS, W; swap STATUS, W
clrf STATUS
movwf STATUS_TEMP; save status
movf PCLATH, W
movwf PCLATH_TEMP; save PCLFTH
decfsz TMR0_Count
goto restore_context
bsf Flags, 0; Time Out!
goto stop_TMR1
restore_context
bcf INTCON, T0IF; clear interrupt flag
movf PCLATH_TEMP, W
movwf PCLATH
swapf STATUS_TEMP, W; fetch status, reswap nibbles
movwf STATUS; restore status
swapf W_TEMP, F; swap nibbles in preparation
swapf W_TEMP, W; for the swap restoration of w
retfie; return from interrupt
;----------------------------------------------init
banksel INTCON
clrf Flags
clrf INTCON
clrf PCLATH
clrf PORTA
clrf PORTB
movlw ESR_ready; incl. discharge, "+" and "-" control at the Cx
movwf PORTC
banksel TRISA
movlw Port_A_Config
movwf TRISA
; Initialize ADC
movlw b'10000100 '; right aligned, Vdd, Vss, AN0, AN1, AN3
movwf ADCON1
movlw
movwf
movlw
movwf
Port_B_Config
TRISB
Port_C_Config
TRISC
movwf ADCON0
call Delay_20_us
bsf ADCON0, 2; start analog-digital conversion
btfsc ADCON0, 2
goto $ -1; waiting for the end of conversion
movf ADRESH, W
movwf U33_H
banksel ADRESL
movf ADRESL, W
banksel U33_L
movwf U33_L
;------------ If ESR> 10 ohms, capacitance measurement does not perform ----------clrf Flags
movlw 0x03
subwf U33_H, W; if evidence ADC> = 0x300 (768)
btfss STATUS, Z
goto Cx_0; transition to measure the capacitance
bsf Flags, 0; platoon flag Time Out
goto Cx_3
;------------ Measurement capacitor -----------Cx_0
movlw Cap_ready; incl. razdyad "-" control on the ground, "+" on Cx
movwf PORTC
call TMR0_init; Run TMR0 to prevent deadlocks in the measurement of capacitance
call Delay_200_us
btfss PORTC, Comp_Low; 1 - Cx is discharged
goto $ -2; forward again, 200 microseconds
call Delay_200_us; for reliability even delay
call TMR1_init
movlw 0x03
subwf U330_H, W; if evidence ADC> = 0x300 (768)
btfss STATUS, Z; ie ESR> 1 Ohm, capacitance is measured with ESR compensation
goto Cx_1
movlw Cap_start2; incl. charge, "-" control at Cx, "+" on Cx
movwf PORTC
movlw 0x4; 3.6mks Delay (18 cycles) for a charge with the "-" input control
call Delay_go
bcf PORTC, In_N_Cx; disable the "-" input control of Cx
goto Cx_2
Cx_1
movlw Cap_start; incl. charge, "-" control on the ground, "+" on Cx
movwf PORTC
Cx_2
btfsc PORTC, Comp_Low; 0 - Cx been charged to the lower limit
goto $ -1
bsf T1CON, TMR1ON; start the timer
tst_charge
btfss PORTC, Comp_Up; 0 - Cx charged to the upper boundary
goto stop_TMR1
btfsc PIR1, TMR1IF; TMR1 full?
call Inc_count
goto tst_charge
stop_TMR1
clrf T1CON; stop TMR1
movlw BCD1
call DispBCD
movlw BCD0
call DispBCD
movlw BCD0
call DispBCD
call DispSP
movlw 1; sign th
call CharLCD
end_disp
banksel PORTC
bsf PORTC, Cap_Discharge; incl. discharge Cx
call Delay_05_sec
banksel PORTC
bcf PORTC, Cap_Discharge; off. discharge Cx
goto ESR_measure
; For testing - output of the ADC without treatment
, Once 2-channel (1 and 10 ohms)
tst_ESR
call SecLine
; Channel 1 Ohm
movlw LOW _tst_1
call Read_String
call ClrA
movf U330_H, W; amplifier gain = 330, limit 1 ohm
movwf AARGB1
movf U330_L, W
movwf AARGB2
call BCD
movlw BCD1
call Disp_Full
; Channel 10 Ohm
movlw LOW _tst_10
call Read_String
call ClrA
movf U33_H, W; amplifier gain = 33, limit 10 ohms
movwf AARGB1
movf U33_L, W
movwf AARGB2
call BCD
movlw BCD1
call Disp_Full
btfsc PORTA, Kn_Set; check button zeroing
goto end_disp
; Saving U0 in EEPROM -----------------------call CursorHome
movlw LOW _write_U0
call Read_String
; U0 for l Ohm
call ClrA
movf U330_H, W; amplifier gain = 330, limit 1 ohm
movwf AARGB0
movf U330_L, W
movwf AARGB1
movwf PORTB
bsf _E
nop
nop
nop
bcf _E
movf Temp4, W
andlw 0x0F
movwf PORTB
bsf _E
nop
nop
nop
bcf _E
; Clrf PORTB
call Delay_200_us
return
; Recoding to ASCII and output
NumLCD andlw 0x0F; mask
iorlw 0x30; ASCII
; Output ASCII character
CharLCD movwf Temp4
SendLCD swapf Temp4, W
andlw 0x0F
iorlw b'00010000 '; RS = 1
movwf PORTB
bsf _E
nop
nop
nop
bcf _E
movf Temp4, W
andlw 0x0F
iorlw b'00010000 '; RS = 1
movwf PORTB
Send bsf _E
nop
nop
nop
bcf _E
clrf PORTB
call Delay_200_us
return
movf INDF, W
btfss Flags, 1, 1 - do not display leading zeros
goto chk_NZ
andlw 0x0F
btfsc STATUS, Z
return; pass output
bcf Flags, 1; this and all figures derive posdeduyuschie
chk_NZ
btfss Flags, 3, 1 - show only NZ discharges, other - 0
goto NumLCD
movf NZ, F
btfsc STATUS, Z; counter = 0?
goto Disp0; yes, we deduce that 0
decf NZ, F; not, then we deduce that there is
call NumLCD
return
;---------------------- BCD --------------------; Recoding values from binary to decimal
BCD movlw 0x20
movwf T1
clrf BCD0
clrf BCD1
clrf BCD2
clrf BCD3
clrf BCD4
BcdLoop rlf AARGB2, F
rlf AARGB1, F
rlf AARGB0, F
rlf AEXP, F
rlf BCD0, F
rlf BCD1, F
rlf BCD2, F
rlf BCD3, F
rlf BCD4, F
decfsz T1, F
goto Adjust
return
Adjust movlw .5
movwf Count2
movlw BCD0
movwf FSR
goto ADloop +1
ADloop incf FSR, F
call Adjbcd
decfsz Count2, F
goto ADloop
goto BcdLoop
Adjbcd movlw 0x03
addwf INDF, W
movwf T0
btfsc T0, 3
movwf INDF
movlw 0x30
addwf INDF, W
movwf T0
btfsc T0, 7
movwf INDF
return
;------------------------------------------------- -----; Copy "on purpose" block (4 bytes) of data
; Temp1 = recipient's address - indicates the senior block address
; Temp2 = source address - indicates the senior block address
; CEQUA movlw CX; C = A
Copy_From_A
movwf Temp1; Xw = A
movlw AEXP
movwf Temp2
goto Copy
BEQUA movlw AEXP; B = A
Copy_To_B movwf Temp2; B = Xw
movlw BEXP
goto Copy_B
; AEQUF movlw FX; A = F
Copy_To_A
movwf Temp2; A = Xw
movlw AEXP
Copy_B movwf Temp1
Copy movlw 4; volume unit
movwf Count1
Copy_Loop
movf Temp2, W
movwf FSR
movf INDF, W
movwf Temp3
movf Temp1, W
movwf FSR
movf Temp3, W
movwf INDF
decf Temp1, F; moving in the direction of decreasing
decf Temp2, F; Address
decfsz Count1, F
goto Copy_Loop
return
;------------------------------------------------- -----X_To_B call EEPROM_To_B; Load factor X
call ASwapB
call FLO2424
call FPM24
return
ASwapB movlw T5
call Copy_From_A
movlw BEXP
call Copy_To_A
movlw T5
call Copy_To_B
return
;------------------------------------------------- ------
incf EE_ADR, F
decf FSR, F
decfsz Count1, F
goto EE_write_loop
return
; Write EEPROM
WriteEEPROM
banksel EECON1; bank3
btfsc EECON1, WR
goto $ -1
banksel EE_ADR
movf EE_ADR, W
banksel EEADR; bank2
movwf EEADR
banksel EE_DATA
movf EE_DATA, W
banksel EEDATA; bank2
movwf EEDATA
banksel EECON1; bank3
bcf EECON1, EEPGD
bsf EECON1, WREN
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR
nop
bcf EECON1, WREN
return
;------------------------------------------------- -----; Incrementing polubloka B
IncB
bsf Flags, 5, set the flag change in the constants
incf BARGB2, F
btfsc STATUS, Z
incf BARGB1, F
goto ShowX
; Decrementing polubloka B
DecB
bsf Flags, 5, set the flag change in the constants
movf BARGB2, F
btfsc STATUS, Z
decf BARGB1, F
decf BARGB2, F
ShowX
movlw BEXP
call Copy_To_A
call BCD
call SecLine
movlw BCD1
call DispBCD
call DispDot
movlw BCD1
call DispBCD
movlw BCD0
call
DispBCD
movlw
call
BCD0
DispBCD
call
return
Delay_05_sec
;=======================================================
;
PIC16 24 BIT FLOATING POINT LIBRARY
#define P16_MAP1 0
#define P16_MAP2 1
include "math16.inc"
include "fp24.a16"
END