EmbeddedRelated.com
Forums
Memfault Beyond the Launch

m430g2553 project

Started by bdingalls1966 August 10, 2013
i am working a simple code to allow the "brightness" of the onboard led 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

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;

}

}

Beginning Microcontrollers with the MSP430


Memfault Beyond the Launch