I am using a potentiometer to generate different colours in RGB led. The adc reads the value from the 3 potentiometers and uses them for pwm in 3 pins. The problem is that the adc retains its initial value and doesn't change on rotating the potentiometer knob. hence the intensity of light doesn't change. What is the problem in my code?
#include <msp430.h>
unsigned int pointer[2];
int jum;
volatile int redder,greener,bluer;
#define PIN_REDLED BIT6
#define PIN_GREENLED BIT4
#define PIN_BLUELED BIT2
//Hardware configuration
#define BLUEREG TA1CCR1
#define GREENREG TA1CCR2
#define REDREG TA0CCR1
void setBlueChannel(int value)
{
TA0R = 0;
BLUEREG = value;
}
void setGreenChannel(int value)
{
TA1R = 0;
GREENREG = value;
}
void setRedChannel(int value)
{
TA0R = 0;
REDREG = value;
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL1 = INCH_2 + CONSEQ_3; // A2/A1/A0, repeat multi channel
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10AE0 |= BIT0 + BIT1 + BIT2; // P1.1,2 ADC option select
ADC10DTC1 = 3; // 3 conversions
P2DIR |= PIN_GREENLED + PIN_BLUELED ;//output
P2SEL |= PIN_GREENLED + PIN_BLUELED; //TA 1.2 on P2.4 TA1.1 on P2.2
P2SEL2 = 0;
P1DIR |= PIN_REDLED; //Output
P1SEL |= PIN_REDLED; //TA 0.1 on p1.6
TA1CCR0 = 1023- 1;
TA1CCTL1 = OUTMOD_7;
TA1CCTL2 = OUTMOD_7;
// Set timer A0
TA0CCR0 = 1023 -1;
TA0CCTL1 = OUTMOD_7;
TA1CTL = TASSEL_2 + MC_1; // SMCLK, up mode
TA0CTL = TASSEL_2 + MC_1; // SMCLK, up mode tassel 01 is aclk good to test
for (;;)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY); // Wait if ADC10 core is active
ADC10SA = (unsigned int)&pointer; // Data buffer start
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion ready
setRedChannel(redder);
setGreenChannel( greener);
setBlueChannel( bluer);
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
//_NOP(); // space for debugger
//_NOP(); // Set Breakpoint here to read ADC
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{ redder = pointer[0];
greener = pointer[1];
bluer = pointer[2];
//ADC10SA = (unsigned int)&TACCR1; // Data transfer location
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}