SN8P26L38
8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD
Page 108
Version 1.5
9.4
ANALOG COMPARATOR APPLICATION
This is a using the analog comparator to do two levels low battery detector. There are two low battery levels which are
2.2V and 2.0V. When the battery level is less than 2.2V, the system does low power process. When the battery level is
less than 2.0V, the system does no power process. The battery detect level is 1/2 bias voltage of battery power source.
The comparator positive voltage (reference voltage) is comparator internal reference voltage. The application circuit is
as following.
MCU
VDD
VSS
XIN
XOUT
CM0N
CM1N
20pF
20pF
0.1uF
0.1uF
0.1uF
DC 3V
1M
ohm
1M
ohm
The application circuit use internal reference and the comparator output process by internal flag, so the circuit only
uses CMnN pin to input battery 1/2 bias voltage to compare with internal reference voltage. Use comparator 0 to check
battery 2.2V and comparator 1 to check battery 2.0V.
Example: Use 2-ch comparators to detect battery status. The battery voltage less than 2.2V is low battery
status. The battery voltage less than 2.0V is no battery status. This case is polling CMnOUT flag to check
the battery voltage status and do difference processes. Users also can use the comparator interrupt
function to obtain immediately process.
; The comparator initialize.
MOV
A, #00001010b
; Enable internal reference 1.1V.
B0MOV
CMP0M, A
; Disable comparator output pin.
B0MOV
CMP1M, A
; Disable comparator interrupt.
B0BSET
FCM0EN
; Enable comparator 0.
B0BSET
FCM1EN
; Enable comparator 1.
; Check 2.2V battery voltage.
CMP0_CHK:
B0BSET
FCMS1
; Set internal reference voltage = 1.1V.
B0BCLR
FCMS0
NOP
; Delay 2 instructions cycle to be the internal band-gap
NOP
; setup time.
B0BTS1
FCM0OUT
; Check comparator 0 status through CM0OUT flag.
JMP
Main
; Not low battery, return to main loop.
JMP
CMP1_CHK
; Is low battery status, go to check comparator 1.
; Check 2.0V battery voltage.
CMP1_CHK:
B0BCLR
FCMS1
; Set internal reference voltage = 1.0V.
B0BSET
FCMS0
NOP
; Delay 2 instructions cycle to be the internal band-gap
NOP
; setup time.
B0BTS1
FCM1OUT
; Check comparator 1 status through CM1OUT flag.