I have studied the 430 comparator these two days. At the beginning, I didn't understand what it was. I read the blogs on this website and seemed to understand it, but when it came to programming, I had no idea where to start. However, God will not let those who work hard, and I finally understood it.
In fact, here you just need to understand a picture, two registers, and understand the working principle.
This is the logic diagram of comparator A. Comparator A consists of 4 parts.
Label 1: Internal reference voltage generator, which can generate reference voltage of 0.25V, 0.50v
Label 2: External voltage input terminal, CA0 corresponds to P2.3, CA1 corresponds to P2.4
Label 3: Internal comparator. I just learned about comparators in class today. That is, when the positive input is greater than the negative input, the comparator outputs a 1 and generates an interrupt flag.
Label 4: comparison result input terminal
Therefore, the general template can be produced
1: Set the internal reference voltage
2: Open the external input port
3: Set the properties of external I/O, that is, the input properties of P2.3 or P2.4
4: Determine the output result
Step 1 corresponds to step 1 in the previous step: At this time, you need to be familiar with the registers. Comparator A has two registers CACTL1 and CACTL2
CACTL1 is used to set the internal reference voltage: Here is a template example: CACTL1 = CARSEL+CAREF1+CAON;
Translation is, set CACTL1 = internal reference voltage to the positive or negative input of the comparator + select 0.25V reference voltage or 0.5V reference voltage + turn on comparator A
Step 2 corresponds to 2 in the previous step
Open the external input port: use CACTL2, CACTL2=P2CAO
The translation is that the external selection is P2CAO, which means P2.3 is used as the input terminal.
Step 3: Set I/O properties
P2DIR = 0x00; //Set IO as the input of the comparator
P2SEL |= BIT3;
Step 4: Compare input and output results:
At this time, you should also be familiar with the register. The lowest bit in CACTL2, that is, CAOUT, if the positive end is greater than the negative end, cout becomes 1. At this time, the typical judgment statement is
if((CACTL2|0xfe) == 0xff) //If the lowest bit is set to 1, the lowest bit in CACTL1, that is, the interrupt flag of the comparator, will also be set
{
Further operation;
The interrupt flag is set to 1
}
Sample code: Compare the voltage of P2.3 input with 0.25. If it is greater, light up the LED and clear the interrupt flag.
#include
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
CACTL1 =CARSEL +CAREF1 +CAON;
CACTL2 = P2CA0;
P2DIR = 0x00; //Set IO as the input of the comparator
P2SEL |= BIT3;
P3OUT |= BIT5;
P3DIR |= BIT5;
while(1)
{
if((CACTL2 | 0xfe) == 0xff)
{
P3OUT &=~BIT5; //Compare if the voltage exceeds 0.25V
CACTL1 &=0xfe; //Clear interrupt flag
}
else
{
P3OUT |= BIT5;
}
}
}
Previous article:Common usage of MSP430 watchdog and writing method of interrupt function
Next article:MSP430 main system clock and 430 low power settings
Recommended ReadingLatest update time:2024-11-16 21:31
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [D-Gesture Recognition Device] Design Report Sharing of Topic D
- About FlexRay Communication Test
- Last three days! Qinheng CH579 free evaluation! BLE, Ethernet, LCD, full-speed USB, ADC, touch... Let's play~
- Thank yourself
- Please advise on the design of a circulating water lamp
- Please recommend a domestic DC to DC chip
- Learn about the key features and benefits of the TPS62840
- Goodbye 2019, hello 2020: The transformation from sitting still to doing well
- What is the difference between [Component Library] and [Element Library] in the Create New Menu in Altium Designer?
- How to get started with microcontrollers/embedded systems