1151 views|0 replies

2015

Posts

0

Resources
The OP
 

MSP430F149 Comparator [Copy link]

At the beginning, I didn't understand what the 430 comparator was. I seemed to understand it after reading some blogs on the website, but I had no idea where to start when it came to programming. However, hard work pays off and I finally understood it. In fact, all you need to do here is to understand a picture, two registers, and 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 voltages of 0.25V and 0.50v. Label 2: external voltage input terminal, CA0 corresponds to P2.3, CA1 corresponds to P2.4 Label 3: internal comparator. We just happened to learn about comparators in class today. That is, when the positive input terminal is greater than the negative input terminal, the comparator outputs a 1 and generates an interrupt flag at the same time Label 4: that is, the comparison result input terminal Therefore, the general template can be produced 1: Set the internal reference voltage 2: Open the external input terminal 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 of 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; Translated, 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 step 2 of the previous step: Open the external input: CACTL2 is used, CACTL2=P2CAO Translation means, the external selection is P2CAO, that is, P2.3 is used as the input terminal. Step 3: Set I/O properties P2DIR = 0x00; //Set IO as the input terminal of the comparator P2SEL |=BIT3; Step 4: Compare input and output results: At this time, you should also be familiar with the registers, 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 } Example code: Compare the voltage input of P2.3 with 0.25. If it is greater, turn on 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;[ /size] P3OUT |=BIT5; P3DIR |=BIT5; while(1) { if((CACTL2 |0xfe)==0xff) { P3OUT &=~BIT5 ; //Compare whether the voltage exceeds 0.25V CACTL1 &=0xfe; //Clear the interrupt flag } else { P3OUT |=BIT5; } [ size=4] } }

This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list