Comparator
Introduction
The comparator compares two analog signals: V1 (input voltage) and V2 (reference voltage), and generates a rising edge interrupt when V1 exceeds V2 or falling edge interrupt when V1 is lower than V2. Here it is assumed that V1 is connected to the positive side of the comparator, and V2 is connected to the negative side of the comparator. It is worth noting that interrupts will also be triggered when V1 is already lower than V2 before the comparator is enabled, or V2 is reset to a value higher than V1. The interrupt can be used to wake the system up from sleep state. These two signals can be derived from any of the eight MSIOs (MSIO_0–MSIO_7). Additionally, the comparator can be used to compare an external signal with one of the following:
- An internal programmable reference voltage.
- A programmable divided version of VBATL.
Main Features
- Input voltage (V1)
- Internal reference voltage (Vref)
- VBATL-based reference voltage (Vbatl_ref), internal reference based on VBATL
- Eight MSIOs (MSIO_0–MSIO_7)
- Reference voltage (V2)
- Internal reference voltage (Vref)
- VBATL-based reference voltage (Vbatl_ref), internal reference based on VBATL
- Eight MSIOs (MSIO_0–MSIO_7)
- Configurable 26 mV hysteresis
- No hysteresis
- –26 mV negative side of hysteresis
- +26 mV positive side of hysteresis
- Fully hysteresis 52 mV (±26 mV)
- Res degeneration is set for calibration.
- Negative side calibration of comparator
- Positive side calibration of comparator
- Bias current set (COMP_REG_0.ICOM_CTRL).
- Comparator channel selection
Functional Description
Overview
The following figure shows the overview of the wakeup comparator module.
The Vbatl_ref comes from Vbatl through resistor divided, as shown in the 图 147. Once enabled by using the COMP_REG_0.COMP_EN register, the comparator starts to work. When the wakeup comparator module is started, V1 starts to be compared with V2 continuously. When V1 exceeds V2, the wakeup interrupt will be triggered. The COMP_REG_0.CHANNEL_SEL_P_3_0 and COMP_REG_0.CHANNEL_SEL_N_3_0 registers are used to select the input of V1 and V2. When Vbatl_ref is selected in the COMP_REG_0.CHANNEL_SEL_N_3_0 or COMP_REG_0.CHANNEL_SEL_P_3_0 register, the bit COMP_REG_1.EN_VBATL_REF should be enabled first. The COMP_REG_0.COMP_VBATL_LVL_CTRL_2_0 register is used to select a level value of Vbatl_ref. The COMP_VBATL_LVL_CTRL_2_0 level value ranges from 0 to 7, and the calculation formula of Vbatl_ref is shown below:
When Vref is selected in the COMP_REG_0.CHANNEL_SEL_P_3_0 or COMP_REG_0.CHANNEL_SEL_N_3_0 register, the bit COMP_REG_1.EN_REF should be enabled first. The COMP_REG_0.COMP_REF_CTRL_7_0 register is used to select a level value of Vref. The COMP_REF_CTRL_7_0 level value ranges from 0 to 255 and can be configured by COMP_REG_0.COMP_REF_CTRL_7_0 register. The calculation formula of Vref is shown below. Iref comes from the relatively constant current generated by the chip's bandgap module and will not be affected by other modules, as shown in the 图 148.
When Vref is selected as reference, to keep the Iref stable, the chip supply voltage (VBATL) must be equal to or higher than 2.4 V.
The selected analog pins will be acquired by the comparator once it is enabled.
Hysteresis
The configurable 52 mV (±26 mV) hysteresis could be added into the wakeup comparator, which helps ensure the slowly changing voltage or a slightly noisy voltage that will cause the comparator not to output to oscillate frequently when the two input voltages are almost close. This could increase the anti-interference ability of the comparator. The hysteresis mode can be configured in COMP_REG_1.HYS_EN. The hysteresis on both sides mode is illustrated in 图 149. The comparator will trigger a falling edge interrupt whenever V1 becomes lower than V2- (VHYST/2). It will also trigger a rising edge interrupt whenever V1 becomes higher than V2+ (VHYST/2). Here it is assumed that V1 is connected to the positive side of the comparator, and V2 is connected to the negative side of the comparator.
Sample Clock
The clock source for collecting the comp output signal is shown in the figure below. The clock can be set as 250 kHz or 2 MHz by configuring the aon_slow_clk_sel. A higher clock frequency will improve the sampling accuracy, but correspondingly increase the power consumption.
Res Degeneration
Res degeneration is set for calibration. The default values of COMP_REG_1.RDEG_N_3_0 register and COMP_REG_1.RDEG_P_3_0 register are 0x8 and are always kept unchanged. The COMP module obtains positive and negative res degeneration which means users can calibrate the comparator by adjusting positive and negative sides. For example, when the comparator outputs a valid signal, the voltage values at N and P sides of the comparator should be approximately equal; if it is found that the actual voltage at P side is too much larger than that at N side, you can set the value of COMP_REG_1.RDEG_P_3_0 smaller, or set the value of COMP_REG_1.RDEG_N_3_0 larger.
CascRes Half
The COMP_REG_1.CASCRES_HALF register is used to ensure that the comparator is in proper operation at different bias currents.
- The COMP_REG_1.CASCRES_HALF is set to 1 for half resistor when COMP_REG_0.ICOMP_CTRL_3_0 is close to 0000.
- The COMP_REG_1.CASCRES_HALF is set to 0 for full resistor when COMP_REG_0.ICOMP_CTRL_3_0 is close to 1111.
Bias Current Set
The COMP_REG_0. ICOMP_CTRL_3_0 register is used to configure the bias current. Higher bias currents will reduce the response time of the comparator, but with a corresponding increase in power consumption. Lower bias currents will increase the response time of the comparator, but with a corresponding reduce in power consumption. It is worth noting that this bias current is also from bandgap module, but this current and Iref are independent of each other and will not interfere with each other.
Glitch Remove
When the voltage reaches the threshold, the signal from the comp output will jitter because of noise interference. In order to eliminate jitter, users can specify a time by configuring the PMU_COMP_GLITCH_REMOVE.GLITCH_REMOVE_CYCLE register and the signal is considered valid if it does not change within this period of time. As the following figure shows, if the duration of the signal is less than the user set time Glitch_t, then the probability of triggering the interrupt will be greatly reduced. If the duration of the signal is larger than the user set time Glitch_t, then the interrupt will definitely be triggered.
Registers
COMP_REG_0
- Name: Comparator Register 0
- Description: This register includes REF_VALUE setting, COMP enablement, and channel selection.
- Base Address: 0x4000A800
- Offset: 0x40
- Reset Value: 0x00000000
Bits | Field Name | RW | Reset | Description |
---|---|---|---|---|
23:20 |
CHANNEL_SEL_N_3_0 |
WR |
0x0 |
Wakeup comparator channel N selection:
|
19:16 |
CHANNEL_SEL_P_3_0 |
WR |
0x0 |
Wakeup comparator channel P selection:
|
15:8 |
COMP_REF_CTRL_7_0 |
WR |
0x0 |
COMP REF CTRL (Vref) Changes the BG-based reference: Min = 0 V, Max =1.9 V (step = 7.5 mV).
|
7 |
COMP_EN |
WR |
0x0 |
Enables or disables wakeup comparator.
|
6:4 |
COMP_BATT_LVL_CTRL_2_0 |
WR |
0x0 |
Changes the Vbatl based ref (Vbatl_vref):
…
|
3:0 |
ICOMP_CTRL_3_0 |
WR |
0x0 |
|
COMP_REG_1
- Name: Comparator Register 1
- Description: This register includes res degeneration, reference source enable, CascRes Half, and Hysteresis.
- Base Address: 0x4000A800
- Offset: 0x44
- Reset Value: 0x00000088
Bits | Field Name | RW | Reset | Description |
---|---|---|---|---|
15 |
EN_REF |
WR |
0x0 |
|
14 |
EN_VBATL_REF |
WR |
0x0 |
|
13 |
CASCRES_HALF |
WR |
0x0 |
CascRes Half:
|
12:10 |
RSVD |
R |
0x0 |
Reserved bits |
9:8 |
HYS_EN |
WR |
0x0 |
Hysteresis = 26 mV |
7:4 |
RDEG_N_3_0 |
WR |
0x8 |
Res degeneration N, for calibration only |
3:0 |
RDEG_P_3_0 |
WR |
0x8 |
Res degeneration P, for calibration only |
MCU_WKUP_CTRL
- Name: MCU Wakeup Control Register of COMP
- Description: For each bit, 0 indicates IRQ is disabled, and 1 indicates IRQ is enabled.
- Base Address: 0x4000A000
- Offset: 0x80
- Reset Value: 0x0000FFFF
Bits | Field Name | RW | Reset | Description |
---|---|---|---|---|
11 | EVT_PMU_MSIO_COMP_F | WR | 0X1 |
|
5 |
EVT_PMU_MSIO_COMP |
WR |
0x1 |
|
AON_SLP_EVENT
- Name: AON Sleep Event Register of COMP
- Description: Events that happen in sleep or active mode, controlled by MCU_WKUP_CTRL.
When clearing the individual event, do not use read-mask-write but simply write ~ (1<< EVENT_BIT) to AON_SLP_EVENT.
- Base Address: 0x4000A000
- Offset: 0x84
- Reset Value: 0x00000000
Bits | Field Name | RW | Reset | Description |
---|---|---|---|---|
11 | EVT_PMU_MSIO_COMP_F | WR | 0x0 | Write 0 to this bit to clear comp falling event. |
5 |
EVT_PMU_MSIO_COMP |
WR |
0x0 |
Write 0 to this bit to clear rising comp event. |
PMU_COMP_GLITCH_REMOVE
- Name: COMP Glitch Remove Register
- Description: To remove voltage jitter, add deglitch circuit on comparator output (glitch: from 4 μs to 28 μs at a 4 μs step).
- Base Address: 0x4000A000
- Offset: 0x2C0
- Reset Value: 0x00000000
Bits | Field Name | RW | Reset | Description |
---|---|---|---|---|
31:3 |
RSVD |
R |
Reserved bits |
|
2:0 |
GLITCH_REMOVE_CYCLE |
WR |
0 |
|
Electrical Specifications
In the table below, the typical values are measured at 25 °C, and the minimum and maximum values are measured at the worst process and temperature conditions.
Symbol | Description | Min. | Typ. | Max. | Unit |
---|---|---|---|---|---|
VREF | Internal reference voltage in wakeup comparator (when VBATL is equal to or higher than 3 V) | 0 | 1900 | mV | |
VBATL_REF | Battery based reference voltage in wakeup comparator | Vbatl*0.1 | Vbatl*0.8 | V | |
ERR_VREF | The error rate of the Internal reference voltage (when VBATL is equal to or higher than 3 V) | 1.3 | 5 | % | |
ERR_VBATL_REF | The error rate of the battery based reference voltage | 1 | 5 | % | |
P_HYS | Positive hysteresis voltage in wakeup comparator | 16 | 26 | 36 | mV |
N_HYS | Negative hysteresis voltage in wakeup comparator | 16 | 26 | 36 | mV |
T_RES | Comparator response time | 8 | 12 | μs |