hI,
I am trying to change the duty cycle of the Timer_A1 by reading ADC value using DTC.
But i found that if i assign the source address directly to TA1CCR1, then duty cycle is changing as can be seen by led brightness.
if(ADC_flag)
{
ADC_flag=0;
ADC10SA = (unsigned int)&TA1CCR1; // Transfer adc readings to an array
ADC10CTL0 |= ENC + ADC10SC; // Start sampling
__delay_cycles (48);
// sequence of conversions complete
ADC10CTL0 &= ~ENC;
}
void Timer_Init(void)
{
P2DIR |= BIT1|BIT2; //set as output pin
P2SEL |= BIT1|BIT2; //pin selected for pwm operations (P2.1/TA1.1) and (P2.2/TA1.1)
TA1CTL |= TASSEL_2 + MC_1; //SMCLK and up mode count till ccr register
TA1CCR0 = 1600 - 1; //pwm frequency 10 khz; DCO = MCLK = SMCLK = 16 Mhz
TA1CCR1 = Duty;
TA1CCTL1 |= OUTMOD_7; //set/reset mode
}
But if i write the code as below no change in the duty cycle is observed.
unsigned int ADC_Readings; // global variable
unsigned int Duty = 100; // global variable
if(ADC_flag)
{
ADC_flag=0;
ADC10SA = (unsigned int)&ADC_Readings; // Transfer adc readings to an array
ADC10CTL0 |= ENC + ADC10SC; // Start sampling
__delay_cycles (48);
// sequence of conversions complete
ADC10CTL0 &= ~ENC;
Duty = ADC_Readings;
}
void Timer_Init(void)
{
P2DIR |= BIT1|BIT2; //set as output pin
P2SEL |= BIT1|BIT2; //pin selected for pwm operations (P2.1/TA1.1) and (P2.2/TA1.1)
TA1CTL |= TASSEL_2 + MC_1; //SMCLK and up mode count till ccr register
TA1CCR0 = 1600 - 1; //pwm frequency 10 khz; DCO = MCLK = SMCLK = 16 Mhz
TA1CCR1 = Duty;
TA1CCTL1 |= OUTMOD_7; //set/reset mode
}
Thank you..!!