Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Simple ADC LED control program MSP430G2553

$
0
0

I am working a simple code to allow the "brightness" of the onboard LED P1 to
follow a varying input voltage from 0-3.6v. I have the code to the the point
that I can see the ADC10MEM register change state, I am hung up on translating
the input to the output for the LED. any help would be greatly appreciated. My
code below...
 

#include <msp430.h>

int main(void)

{
volatile unsigned int ADCval, pw, pi;
WDTCTL = WDTPW + WDTHOLD; // Stop Watch Dog Timer
P1DIR |= 0x01;
ADC10CTL0 = ADC10SHT_3 + ADC10ON; // Set sampling time, turn
on ADC10
ADC10CTL1 = INCH_4 + ADC10DIV_7;
//ADC10CTL0 |= ENC ; // Conversion enabled
ADC10AE0 |= 0x04; // Enable interrupt


for (;;)
{

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
while (ADC10CTL1 & ADC10BUSY); // ADC10BUSY?
while (!(ADC10CTL0 & ADC10IFG));
ADCval = ADC10MEM;

pw = ADCval * 0x08;
pi = 0x2200 - pw;

TACCTL0 = pw;
TACCTL1 = pi;

}

}

 


Viewing all articles
Browse latest Browse all 2077

Trending Articles