Hello, I am trying to control the brightness of an LED by setting a PWM with a ADC joystick. It can go up or right, to increase brightness, and it can go left or down to control brightness. I can set it to work if I just read up and down, or just read left and right. But I can't figure out how to control the ADC10 control registers to read both x and y values from the joystick.
//#include <msp430.h>
#include <msp430g2553.h>
/*
* main.c
*/
void main(void)
{
//int adcValue;
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
//This is ADC10 control register
//4th bit turns on ADC
//11 and 12 sets "16 × ADC10CLKs" sample and hold time
// initialize ADC
// 0001 0000 0001 0000
ADC10CTL0 = 0x1010;
//ADC10CTL1 register:
// 12 - 15 input channel select
// bit 0: read only, conversion in process
// bit 1,2: Sequence mode select
ADC10CTL1 = 0x1000; // Set ADC to read from pin P1.1 and P1.2
//ADC10 analog enable. These bits enable the corresponding pin for analog input.
//ADC10AE0 = 0x03; //I don't think this does what I thought it did
//Initializing digital output
P1DIR |= 0x40;
P1OUT = 0;
//P1SEL |= 0x40;
/********************************************************
*These are the counter A control registers.
****************************************************/
TACCTL0 = 0x0010; //Enables CCIE interupt
//The output is reset when the timer counts to the TBCLx value.
//It is set when the timer counts to TBCL0
TACCTL1 = OUTMOD_7;
//Another control register
//SMCLK, input /8, up mode.
TACTL = 0x02D0;
//TACCRO is the value to count to
TACCR0 = 1000;
//TACCR1 = 0; // Trigger pwm switch??? Don't need this
_BIS_SR(GIE); // Enable Global interupt.
for (;![;)]()
{
//Code to read ADC.
ADC10CTL0 |= 0x0003; // Enable and start conversion
while (ADC10CTL1 & 0x0001); // While conversion in process.
//ADC10CTL1 |= 0x0000; // Exit conversion?
//ADC is done reading: Value is stored in ADC10MEM
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
while (TA0R < ADC10MEM){
P1OUT |= 0x40;
}
P1OUT = 0x0;
}
// 0001 0000 0001 0000