enstrum
New Coder
Hello, I am currently trying to control an RGB LED's color by using 3 potientiometers with an MSP430 (Turning one would control red, turning the second would control green). How can I code the Timer A module to use PWM on the three rgb pins? Thank you!
C:
//ADC
int VALUE; // Integer variable "VALUE" declared
int DELAY; // Integer variable "DELAY" declared
int Map;
/* MAIN FUNCTION *****************************************************/
int main(void) {
int32_t longResult;
uint32_t tmp0, tmp1;
WDTCTL = WDTPW | WDTHOLD;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
init_Display();
//init_CounterTimer();
//RGB
P1DIR = BIT4 + BIT5 + BIT1; //GREEN input
P1OUT = BIT4 + BIT5 + BIT1;
//ADC
ADC10CTL1 = ADC10CTL1 | INCH_6; // Pin P1.7 selected as input channel
ADC10CTL0 = ADC10CTL0 | ADC10ON; // ADC is turned on and the Sample
ADC10CTL0 = ADC10CTL0 | ADC10SHT_2; // and Hold Time is extended long
// enough to be able to see the flash
while(1) // This is a loop ... "while(TRUE)" keep looping
{
for(DELAY = 240; DELAY > 0; DELAY --); // The DELAY has the value of
// 240 and as long as DELAY is
// greater than 0 each time thru
// it gets decremented by 1.
// When 0 the program continues.
ADC10CTL0 = ADC10CTL0 | ENC; // ADC is enabled
ADC10CTL0 = ADC10CTL0 | ADC10SC; // ADC starts a converion
for(DELAY = 240; DELAY > 0; DELAY --); // Same delay as above. Gives it
// time to place the "VALUE" in
// the holding register.
VALUE = ADC10MEM; // A number between 0 and 1023 is
// placed in the holding register
// "ADC10MEM
Map = ((VALUE-0)*(255-0)/(1023-0)); ///map value to 255
// P1.1 output
P1SEL |= BIT1; // P1.1 TA1/2 options
CCR0 = 1000-1; // PWM Period
CCTL1 = OUTMOD_7; // CCR1 reset/set
CCR1 = Map; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1 + TAIE; // SMCLK, up mode, Timer_A interrupt enabled, Timer_A interrupt pending
_BIS_SR(CPUOFF + GIE); // Enter LPM0 with interrupts
}
return 0;
}