Application Note # 18

EM MICROELECTRONIC - MARIN SA
AppNote 18
Application Note 18
Title:
Product Family:
Part Number:
Keywords:
Date:
Ohmmeter application with EM6X20
4 bits Microcontroller
EM6620, EM6520
4 bits micro-controller, ROM, RAM, data table
January 07, 2002 REV. B/416
This application note describes a method for implementing an ohmmeter using the EM662X series of microcontrollers. This demo software is created for the EM6X20 which have a LCD driver inside. The ohmmeter
requires only two external components. It’s software and hardware configurable for resistance measurement
with resolutions until 16 bits. This method uses a software calibration technique that compensates for voltage,
time, and temperature.
EM6X20
Theory of operation
This application uses a capacity charging circuit (figure 1) to convert
resistance to time, which can be easily measured using a microcontroller.
The supply voltage is applied to a calibration resistor. The capacitor
charged up until the threshold on the chip input trips. This generates
software calibration value that is used to calibrate out most circuit
errors changes in the input threshold voltage and temperature
variations. After the capacitor is discharged, the reference voltage is
applied to the resistance to be measured. The time to trip the
threshold is then measured and compared to the calibration value to
determine the actual resistance.
PA0
PB0
PB1
Rmess
is
a
Rcal
Cmess
Figure 1.
Circuit configuration
The values of Rcal and Cmess are selected based upon the number of bits of resolution required. Rcal should be
one half the largest value resistance to be measured:
Cmess =
−T
æ VT ö
Lnç1 −
÷ ⋅ R max
è Vdd
1
æ
ö
− ç 65535 ⋅
÷
16384 Hz
è
=
= 11,54 µF => 4,7 µF
æ 1,5V ö
Lnç1 −
⋅ 500kΩ
è 3,0V
T
= Time to do the number of bits resolution desired (resolution * frequency counter = FFFF * 16kHz).
Vdd = Supply voltage (3,0V).
VT = Threshold voltage of the EM6X20 (1,5V).
Rmax = Maximum resistance value to be measured (500kΩ).
Actual value for the capacitor should be smaller than calculated to ensure that the EM6x20 does not have a
overflow during the measurement.
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
1
www.emmicroelectronic.com
AppNote 18
Example’s program
The assembly code implementing for the ohmmeter example (figure 1) is at the Appendix A. This program
measures time up to 16 bits (65535 cycles) and calculates the results using 16 bits multiply and divide
modules.
The measured performance reach on the ohmmeter is Ù1% between 1-500kΩ. If the measurement’s zone is
smaller, you can have better performance.
Flowchart
START
Discharge
Measure
Setup
Set C to Vss
Set C to Vdd
Discharge C
Wait
Start the counter
Calibration
Disconnect C
HALT mode
Discharge C
Return
Return
Measurement
Calcul the result
Figure 2.
END
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
2
www.emmicroelectronic.com
AppNote 18
Appendix A: Ohmmeter program
;---------------------------------------------------------------------------------------------------------;
PROGRAM
:
OM_D01.ASM
;
Date last mod
:
22/12/1998
Ch.Mayer
;
Ohmmeter by the measurement of resistors
;
Uses the V6620REG.ASM Include file
;
;
;
Between PB0 and PA0 it's the measurement's resistor.
;
Between PB1 and PA0 it's the calibration's resistor.
;
Between Vss and PA0 it's the condensator.
;
;---------------------------------------------------------------------------------------------------------;--------------------------------------------------------------------------------------------;
6520 registers
;--------------------------------------------------------------------------------------------INCLUDE V6620REG.ASM
;--------------------------------------------------------------------------------------------;
Constants
;--------------------------------------------------------------------------------------------RCal1
EQU 06H
; Calibration resistor (LSB)
RCal2
EQU 0CH
; Calibration resistor
RCal3
EQU 00H
; Calibration resistor
RCal4
EQU 00H
; Calibration resistor (MSB)
;--------------------------------------------------------------------------------------------;
Variables
;--------------------------------------------------------------------------------------------Stack0
EQU 00H
; Stack0
Errors
EQU 01H
; Save if a error is present.
Cnt_Ext1
EQU 02H
; Counter extention n°1
Cnt_Ext2
EQU 03H
; Counter extention n°2
Sel_Meas
EQU 04H
; Select the resistor for the measurement
OP1_1
EQU 05H
; First number for the calcul (LSB)
OP1_2
EQU 06H
; First number for the calcul
OP1_3
EQU 07H
; First number for the calcul
OP1_4
EQU 08H
; First number for the calcul (MSB)
OP2_1
EQU 09H
; Second number for the calcul (LSB)
OP2_2
EQU 0AH
; Second number for the calcul
OP2_3
EQU 0BH
; Second number for the calcul
OP2_4
EQU 0CH
; Second number for the calcul (MSB)
ComptL
EQU 0DH
; Count the position of the division (LSB)
Compt
EQU 0DH
; Count the position of the multiplication
Carry
EQU 0EH
; Save the carry in a calcul, first memory
Carry2
EQU 0FH
; Save the carry in a calcul, second memory
Res1
EQU 10H
; Result of the calcul (LSB)
Res2
EQU 11H
; Result of the calcul
Res3
EQU 12H
; Result of the calcul
Res4
EQU 13H
; Result of the calcul
Res5
EQU 14H
; Result of the calcul
Rst1
EQU 14H
; Rest from the division (LSB)
Res6
EQU 15H
; Result of the calcul
Rst2
EQU 15H
; Rest from the division
Res7
EQU 16H
; Result of the calcul
Rst3
EQU 16H
; Rest from the division
Res8
EQU 17H
; Result of the calcul (MSB)
Rst4
EQU 17H
; Rest from the division (MSB)
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
3
www.emmicroelectronic.com
AppNote 18
ComptH
Stack1
Stack2
Stack3
Stack4
EQU
EQU
EQU
EQU
EQU
18H
19H
1AH
1BH
1CH
TCal1
TCal2
TCal3
TCal4
EQU
EQU
EQU
EQU
2AH
2BH
2CH
2DH
Num1_1
Num1_2
Num1_3
Num1_4
EQU
EQU
EQU
EQU
3AH
3BH
3CH
3DH
; Count the position of the division (MSB)
; Tempory variable
; Tempory variable
; Tempory variable
; Tempory variable
; from 20H to 29H and 2EH-2FH is used for setup the display.
; Time's calibration resistor (LSB)
; Time's calibration resistor
; Time's calibration resistor
; Time's calibration resistor (MSB)
; from 30H to 39H and 3EH-3FH is used for setup the display.
; Number to display on the lcd (LSB)
; Number to display on the lcd
; Number to display on the lcd
; Number to display on the lcd (MSB)
;--------------------------------------------------------------------------------------------;
Code Offset
;--------------------------------------------------------------------------------------------ORG 0
Reset: JMP Main
;--------------------------------------------------------------------------------------------;
Interrupt Handler
;--------------------------------------------------------------------------------------------Handler:
STA
STACK0
; Save ACCU value
LDI
AND
JPZ
STI
01H
RegIRQ1
Hand10
RegCCnt2, 00H
;\
; => Test if it's a interrupt PA0
;/
; Stop the 10Bit counter
Hand10:LDI
AND
JPZ
02H
RegIRQ3
HandEnd
;\
; => Test if it's a interrupt counter
;/
LDI
ADD
STA
JPNC
04H
Cnt_Ext1
Cnt_Ext1
HandEnd
; Increment the counter extention n°1
; Save the new value
INC
STA
JPNC
Cnt_Ext2
Cnt_Ext2
HandEnd
; Increment the counter extention n°2
; Save the new value
STI
STI
RegCCnt2, 00H
Errors, 01H
; Stop the 10 bits counter
; Set error number
STACK0
; Reload ACCU
HandEnd:
LDR
RTI
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
4
www.emmicroelectronic.com
AppNote 18
;--------------------------------------------------------------------------------------------;
Main
;--------------------------------------------------------------------------------------------Main:
STI
RegVLDCntl, 03H
; Disable the watchdog
STI
INTEN, 08H
; Enable the general interrupt
STI
IRQM3, 0010b
; Enable interrupt counter
STI
RegLCD1, 0000b
; Setup the lcd
STI
RegLCD2, 0010b
; Turn LCD on 4 MUX
STI
OPTNoPullPA, 01H
; Disable the pull on PA0
STI
OPTDebIntPA, 01H
; Disable the debouncer on PA0
STI
OPTNoPdPB, 0011b
; Disable the pull on port B
STI
RegPBCntl, 1111b
; Set port B to output
STI
RegPBData, 0000b
; PB0 must be low to discharge resistor
CALL
DisClear
; Clear the display
CALL
DisInit
; Init. the display.
Main100:
CALL
STI
CALL
Discharge
Sel_Meas, 02H
Meas_Res
; Discharge the capacitor
; Select the measure of the calibration resistor
; Start the measurement
CALL
STI
CALL
Discharge
Sel_Meas, 01H
Meas_Res
; Discharge the capacitor
; Select the measure of the resistor
; Start the measurement
LDR
JPNZ
Errors
Mea_Error
;\
; => on a error, jump to the error's subroutine
LDR
STA
LDR
STA
LDR
STA
Res1
Num1_1
Res2
Num1_2
Res3
Num1_3
; Save the result for display on the lcd
CALL
Display
; Refresh the lcd
JMP
Main100
;-------------------------------------------------------------------------;
Errors
;-------------------------------------------------------------------------Mea_Error:
STI
Num1_1, 0EH
; Write "EEE" on the display on a error.
STI
Num1_2, 0EH
STI
Num1_3, 0EH
CALL
Display
; Refresh the lcd
JMP
Main100
;-------------------------------------------------------------------------;
Measurement resistor
;-------------------------------------------------------------------------Meas_Res:
STI
Errors, 00H
; Clr error
STI
Cnt_Ext1, 03H
; Reset the variable
STI
Cnt_Ext2, 00H
; Reset the variable
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
5
www.emmicroelectronic.com
AppNote 18
STI
STI
STI
STI
STI
STI
RegCCnt2,0000b
RegCCnt1,1001b
RegCDataL, 00H
RegCDataM, 00H
RegCDataH, 00H
RegCCnt2, 0001b
; Stop the 10 bit counter
; Count up, System clk/2
; Start with 00H
; Start with 00H
; Start with 00H
; Load counter
LDR
STA
STA
Sel_Meas
RegPBCntl
PortB
;\
; => Set PB0 to 1 for start the measurement
;/
STI
RegCCnt2,1000b
; Start the 10 Bit counter
STI
IRQM1, 0001b
; PA[0] interrupt enable
Meas_Res100:
HALT
; Only PA0 rising edge or 10 Bit overflow will wake up
LDI
AND
JPNZ
08H
RegCCnt2
Meas_Res100
; Check if timer is running
; <> 0 if timer running
STI
IRQM1, 0000b
; PA0 interrupt disabled
LDR
JPNZ
Errors
Meas_Res400
; Test if the counter is in error mode
SHRR
JPC
SHRA
JPC
JMP
Sel_Meas
Meas_Res200
; What the resistor measured ? ...
; ... it's the normal resistor
Meas_Res300
Meas_Res400
; ... it's the calibration resistor
Meas_Res200:
LDR
STA
LDR
STA
LDI
AND
STA
LDI
AND
OR
STA
LDR
STA
RegCDataL
OP1_1
RegCDataM
OP1_2
03H
RegCDataH
OP1_3
0CH
Cnt_Ext1
OP1_3
OP1_3
Cnt_Ext2
OP1_4
; Result from the normal resistor
; Transfer Tmeas in OP1_x for the multiplication
LDI
STA
LDI
STA
LDI
STA
LDI
STA
RCal1
OP2_1
RCal2
OP2_2
RCal3
OP2_3
RCal4
OP2_4
; Transfer Rcal in OP2_x for the multiplication
CALL
Multi16
; Multiplication
LDR
TCal1
; Transfer Tcal in OP2_x for the division
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
6
www.emmicroelectronic.com
AppNote 18
STA
LDR
STA
LDR
STA
LDR
STA
OP2_1
TCal2
OP2_2
TCal3
OP2_3
TCal4
OP2_4
CALL
Divi16
LDR
STA
LDR
STA
LDR
STA
Res1
OP1_1
Res2
OP1_2
Res3
OP1_3
CALL
HEXDEC
JMP
Meas_Res400
Meas_Res300:
LDR
STA
LDR
STA
LDI
AND
STA
LDI
AND
OR
STA
LDR
STA
RegCDataL
TCal1
RegCDataM
TCal2
03H
RegCDataH
TCal3
0CH
Cnt_Ext1
TCal3
TCal3
Cnt_Ext2
TCal4
Meas_Res400:
STI
STI
RegPBCntl, 0FH
PortB, 00H
; Division
; Convert the result from hexa to decimal
; Result from the calibration resistor
; => Reset PB0 and PB1 to GND
;/
RET
;-------------------------------------------------------------------------;
Discharge the capacitor
;-------------------------------------------------------------------------Discharge:
STI
Cnt_Ext1, 03H
; Reset the variable
STI
Cnt_Ext2, 00H
; Reset the variable
STI
STI
STI
STI
STI
STI
RegCCnt2, 0000b
RegCCnt1, 1010b
RegCDataL, 00H
RegCDataM, 00H
RegCDataH, 00H
RegCCnt2, 0001b
; Stop the 10 bits counter
; Count up, system clk/16
; Start with 00H
; Start with 00H
; Start with 00H
; Load counter
STI
RegCCnt2, 1000b
; Start the 10 bits counter
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
7
www.emmicroelectronic.com
AppNote 18
Disch100:
HALT
; Only 10 bits overflow will wake up
LDI
SUB
JPNC
01H
Cnt_Ext2
Disch100
;\
; => Test if "Cnt_Ext2" is < 01H
;/
STI
RET
RegCCnt2, 0000b
; Stop the 10 bit counter
;-------------------------------------------------------------------------;
Include File
;-------------------------------------------------------------------------INCLUDE MULTI16.ASM
INCLUDE DIVIS16.ASM
INCLUDE HEXDEC.ASM
INCLUDE LCDINIT.ASM
; Include file for multiplication 16 bits.
; Include file for division 16 bits.
; Include file for convert hex to dec
; Include file for drive the lcd.
;--------------------------------------------------------------------------------------------END
;---------------------------------------------------------------------------------------------
You can download the latest version of the source
code on our web site (http://www.emmarin.com/).
References
Application Note #13:
Application Note #14:
Application Note #20:
16 bit binary division with 4 bit controller.
16 bit binary multiplication with 4 bit controller.
How to convert Hex – Dec.
01/02 REV. B/416
Copyright  2001, EM Microelectronic-Marin SA
8
www.emmicroelectronic.com