1155 views|0 replies

3836

Posts

19

Resources
The OP
 

MSP430 ADC analog-to-digital routines [Copy link]

The following uses the design of a street light controller as an example to illustrate how to use ADC12. Street lights will go out above a certain brightness value, and light up when the brightness is below a certain value. The following is a simplified diagram. When the brightness is high and the light is strong, the resistance value of the photoresistor is relatively small. At this time, it is divided by 10K below, and the voltage sent to ADC12 is relatively high; when the brightness is low and the light is weak, the resistance value of the photoresistor is relatively large. At this time, it is divided by 10K below, and the voltage sent to ADC12 is relatively low. The ADC12 module converts a specific value representing the light intensity (the stronger the light, the larger the converted value, but it is not proportional), and then sets a threshold data for turning on the street light. The actual measured light intensity data can be compared with the threshold data to get the purpose of turning on the street light.

The following is a specific example program: (using single-channel single-time conversion).
#include "msp430x44x.h" //Use MSP430F447
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; //Stop watchdog
P6SEL |= 0x01; //Define P6.0 as analog input channel 0
ADC12CTL0 = ADC12ON+SHT0_2; //Turn on ADC12 power and set sampling time
ADC12CTL1 = SHP;
ADC12CTL0 |= ENC; //Enable conversion
while (1)
{
delay(60000) //Delay 1 second (roughly, equivalent to the function of timer)
ADC12CTL0 |= ADC12SC; //Start conversion
while ((ADC12IFG & ADC12BUSY)==0); //Wait for conversion to complete
if(ADC12MEM0<1234) //Read the conversion result and compare to get the conclusion
P1OUT |= BIT0; //Turn on the street light when the brightness is below the threshold

else P1OUT ^= BIT0; //Turn off the street light when the brightness is higher than or equal to the threshold

}

}

This post is from Microcontroller MCU
 

Guess Your Favourite
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