You are on page 1of 12

MSP430 Comparator

--PRASANNA KUMAR M

Note: For better understanding I have added animation to this presentation,


•Please wait for the animation to complete
•When the animation is complete click to for explanation
Comparator- Introduction
• Comparator compares one analog voltage level with another analog
voltage level, or some preset reference voltage, VREF and produces an
output signal based on this voltage comparison.
MSP430 Comparator
Features of Comparator_B :
•Inverting and noninverting terminal input multiplexer
•Output provided to Timer_A capture input
•Software selectable reference voltage generator
•Reference voltage input from shared reference (1.5, 2.0, 2.5)
•Ultra-low-power comparator mode
•Interrupt driven measurement system – low-power operation
support
MSP430 Comparator
There are 15 Analog comparator Inputs,
one of the analog input can be selected
on +ve input of the Comparator.
The selected analog input voltage at Output through an RC
+ve terminal is compared with another filter to smooth out any
analog input voltage from the PIN or rapid oscillations that
with the Internal Reference voltage might occur if the
comparator inputs are
very close together

CBOUT sets to logic-1


when input at +ve
terminal is greater
Software than input at –ve
selectable terminal
reference
voltage
There are 15 Analog comparator Inputs,
one of the analog input can be selected
on -ve input of the Comparator.
MSP430 Comparator Registers
CBCTL0: Comparator_B Control Register – 0
This register is used to enable comparator input and to select the
comparator inputs(+ve and –ve) Enables +ve input(InputPlus) of
Comparator_B
Using CBIPSEL, select one of the
Comparator_B input to be available
at +ve input of Comparator
Enables -ve input(InputMinus) of
Comparator_B
Using CBIMSEL, Select one of the
Comparator_B input to be available
at -ve input of Comparator

-
MSP430 Comparator Registers
CBCTL1: Comparator_B Control Register – 1
Switch ON Comparator module
Comparator can be configured
using CBON bit
to operate in these modes

Exchange inputs:
•Comparator input selected by CBIMSEL will
be available at +ve input of comparator and
•Comparator input selected by CBIPSEL will
be available at -ve input of comparator
•Output is inverted.

Enables Comparator Output filter

Comparator o/p:
= 1 if V+ve input > V-ve input, while CBEX = 0
= 0 if V+ve input > V-ve input, while CBEX = 1
MSP430 Comparator Registers
CBCTL2: Comparator_B Control Register – 2
Option of selecting Shared
Using resistor divider network,
reference voltage
select the required reference
voltage CBREF1

Select the reference voltage source

Select Vref either on +ve or on –ve terminal


of Comparator

Using resistor divider network, select the


required reference voltage CBREF0
MSP430 Comparator
Steps to configure Comparator:
1.Enable +ve input, and select the input
CBCTL0 |= CBIPEN + CBIPSEL0;
2. Configure the comparator to operate in Normal mode
CBCTL1 |= CBPWRMD_1;
3. Configure Reference voltage
• Select reference voltage available on –ve input of comparator
• Select Vcc, voltage applied to resistor ladder network to generate required reference
voltage
• Tap the required reference voltage from resistor ladder network
CBCTL2 |= CBRSEL + CBRS0 + CBREF0_7;
4. Switch ON comparator module
CBCTL1 |= CBON ;
5. If the Voltage applied at +ve input is greater than reference voltage
at –ve input of comparator, then CBOUT, the output of comparator,
change the state from logic-0 to logic-1
MSP430 Comparator
3.3V
(CBON)
Switch ON
Comparator module

(CBRS0) Using these 5 bits, we


Select Vcc as can generate
source to reference required reference
voltage generator voltage using Voltage
divider network
+
-
Ex:
Calculation for Reference Voltage
•If CBRER0 = CBREF0_7
then, (8/25)*3.3 = 0.825 V
•If CBRER0 = CBREF0_15
then, (16/25)*3.3 = 1.65 V
]
MSP430 Comparator Program example

3.3V

P1.0

P6.0/A0/CB0
+
5K Pot - CBOUT

Reference
Voltage
Generator

MSP430F5529
MSP430 Comparator Program example
In <msp430F5529.h> Wait for reference voltage generator to
CBIPEN = 0x0080 and CBIPSEL0 = 0x0000 get stabilized
So, CBCTL0 = 0x00800 #include <msp430F5529.h>
This will configure comparator module int main (void)
{
enabling +ve terminal and Selecting CB0 WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= 0x01; // P1.0 output
comparator input.
CBCTL0 |= CBIPEN + CBIPSEL0; // Enable comperator_B +Ve input and select CB0 input
In <msp430F5529.h> CBPWRMD_1 = CBCTL1 |= CBPWRMD_1;
CBCTL2 |= CBRSEL + CBRS0 + CBREF0_7;
// Configure comparator_B to operate in Normal mode
//Comperator_B Internal Ref.0(CBREF0),
0x0100 //Select 7, ; 8/32; 3.3 * 8 /32 = 0.50V

So, CBCTL1 = 0x0100 __delay_cycles(75);


CBCTL1 |= CBON ;
// wait for reference voltage generation stabilization.
// Switch on Comperator_B module
This will configure Comparator module while (1) // Test comparator_A output
{
in normal mode. if ((CBCTL1 & CBOUT))
P1OUT |= 0x01; // if CBOUT set, set P1.0
else P1OUT &= ~0x01; // else reset
}
}
Switch ON Comparator module
In <msp430F5529.h>
CBRSEL=0x0020 Reference voltage applied to –ve terminal
CBRS0 = 0x0040p Vcc (3.3V) reference voltage source to resistor
If Vin > Vref, CBOUT will set, Switch ON ladder
LED connected to P1.0 CBREF0_7 = 0x0007Resistor ladder tap-7
else So, CBCTL2 = 0x0067
Switch OFF LED Comparator module configured for reference voltage applied to –ve
terminal, 3.3V voltage for resistor ladder and Tap-7 in ladder network

You might also like