The whole code what is written above is inside while(1) loop but timer_init() is called before while(1) loop. i.e. void main() { timer_init(); while(1) { 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 } } } But anyway variable "Duty" is defined as a global variable and i am changing the duty value as Duty = ADC_Readings; so, it should update TA1CCR1 register right..!! Can you please provide the solution for it. Thank you.!
↧