MSP430 Comparator

Publisher:Lihua1314520Latest update time:2017-01-09 Source: eefocusKeywords:MSP430 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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;

      }

  

  }


}


Keywords:MSP430 Reference address:MSP430 Comparator

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

MSP430 MCU RTC Operation - Real-time Clock Implemented by TimeA
: //******************************************************************************* // D13x Demo - Use Timer_A and interrupt to realize RTC, and observe the flashing frequency of the LED light // // Description: Use Timer_A and interrupt to realize RTC; Use P1 XOR to negate P1.5; // The system is in sleep state LPM3,
[Microcontroller]
MSP430 MCU Stepper Motor Program
MSP430 MCU Stepper Motor Program #include "msp430x22x4.h"  #define uchar unsigned char  #define uint unsigned int  uchar i=0;  // Scanning 4x4 keyboard #define keyin (P2IN&0x0F)  //digital tube value 0~f  unsigned char key ={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};  unsigned char hang ={0xef,0xdf,0xbf,0x7
[Microcontroller]
MSP430 A Low Power Design
Achieving the absolute longest battery life with the lowest power consumption is a common design requirement for many deeply embedded applications. In this article, we will discuss a microcontroller (MCU) based residential electronic thermostat, and every microampere (uA) of current has been carefully and thoroughly i
[Microcontroller]
MSP430 key program example (with schematic diagram)
#i nclude void Init_Port(void) {     //Set all pins of P1 port to input mode during initialization     P1DIR = 0;       //Set all pins of P1 port to general I/O port     P1SEL = 0;          //Set P1.4 P1.5 P1.6 P1.7 to output direction     P1DIR |= BIT4;     P1DIR |= BIT5;  P1DIR |= BIT6;     P1DIR |= BIT
[Microcontroller]
MSP430 key program example (with schematic diagram)
MSP430 Timer Detailed Explanation
There is a concept of comparison capture in the MSP430 timer, which is very unfamiliar to me. After reading it for a long time, I finally understood: Comparison Mode: This is the default mode of the timer. When in comparison mode, the hardware related to the capture mode stops working. If the timer interrupt is en
[Microcontroller]
A comparison of MSP430 and AVR microcontrollers
There are many types of microcontrollers, and many manufacturers have launched their own MCUs. Among the many brands of microcontrollers, I prefer the MSP430 and AVR series. The following is a PK analysis based on their respective characteristics and several aspects. Since we are competing, just like in sports, we n
[Microcontroller]
A comparison of MSP430 and AVR microcontrollers
Design of electronic blood pressure meter based on MSP430F449
With the continuous improvement of living standards and the increase in the proportion of urban aging, the household use of medical electronic equipment has gradually become a trend. Among them, the home electronic sphygmomanometer is one of the typical home medical testing equipment. At present, sphygmomanometers c
[Microcontroller]
Design of electronic blood pressure meter based on MSP430F449
Design of CAN Intelligent Node
1. Introduction CAN bus is the abbreviation of controller area network (Controller Area Network) bus. It belongs to the field bus category and is a serial communication network that can effectively support distributed control or real-time control. It can connect intelligent devices connected to the field bus as
[Microcontroller]
Design of CAN Intelligent Node
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号