Hell Sir,
We have implemented PWM on P1_0 using timer1 and channel 0.
Here goes the initialization like this:
////////////******************////////////
PERCFG = (PERCFG & ~0x40) | 0x03; // Select Timer 1 Alternative 0 location, set U1CFG and U0CFG to Alternative 1 location
P2DIR |= 0xC0; // Give priority to Timer 1
P1SEL = 0x00; // GPIO.
P1DIR = 0xFF; // Output.
P1_0 = 1; // LED1 off.
// Clear Timer 1 channel 0 interrupt flag.
// CPU interrupt flag (IRCON) for Timer 1 is cleared automatically by hardware.
T1STAT &= ~(1<<0); //~T1STAT_CH0IF;
// Set individual interrupt enable bit in the peripherals SFR.
T1CCTL0 |= (1<<6)|(1<<3)|(1<<2);//T1CCT1L_IM; // Enable interrupt on channel 0.
T1CCTL1 &= ~(1<<6);//~T1CCT1L_IM; // Disable interrupt on channel 1.
T1CCTL2 &= ~(1<<6);//~T1CCT1L_IM; // Disable interrupt on channel 2.
T1CCTL3 &= ~(1<<6);//~T1CCT1L_IM; // Disable interrupt on channel 3.
T1CCTL4 &= ~(1<<6);//~T1CCT1L_IM; // Disable interrupt on channel 4.
T1OVFIM = 0; // Disable overflow interrupt.
// Enable Timer 1 interrupts by setting [IEN1.T1IE=1].
T1IE=1; //T1IE = 1;
// Enable global interrupt by setting the [IEN0.EA=1].
EA = 1;
// Set channel 0 to compare mode and to toggle on compare.
//T1CCTL0 = //(T1CCTL0 & ~T1CCT1L_CMP) | T1CCT1L_CMP_TOG_ON_CMP | T1CCT1L_MODE;
// Set compare register of channel 0 to 32767 ( 0xFFFF / 2 ).
T1CC0L = 0x7F; // PWM signal period // T1CC0L = 0xFF;
T1CC0H = 0xFF; // T1CC0H = 0x7F;
// Set prescaler divider value to 32 to get a tickspeed of 500 kHz and
// set Timer 1 to free running mode.
// T1CTL = (T1CTL & ~(T1CTL_MODE | T1CTL_DIV)) | T1CTL_MODE_FREERUN | T1CTL_DIV_32;
T1CTL |= (1<<3)|(1<<0);
////////////******************////////////
and ISR is as:
///////*****************//////////////
#pragma vector = T1_VECTOR
__interrupt void timer1_ISR(void)
{
// Clear Timer 1 channel 0 interrupt flag. The proper way to clear interrupt
// flags is by just writing 0, for R/W0 operations see datasheet.
T1STAT &= ~(1<<0);//~T1STAT_CH2IF;
// This value should be the same as the value set for T1CC0 (T1CC0L and T1CC0H)
// in the setup. When reading this value while debugging, some delay should
// be expected due to interrupt generation time and other time consuming code.
// Because of this, a value higher than T1CC0 will be read.
// timer1Ch0CmpResult = T1CNTL;
// timer1Ch0CmpResult |= (T1CNTH << 8);
//#if (chip==2541 || chip==2543 || chip==2545)
// Toggle SRF05EB LED1.
P1_0 ^= 1;
//#endif
}
////////*******************////////////
Led at P1_0 blink only for 7times and then goes off, It has to be run for ever.
Please help me to tackle this issue.
We are using Thermometer program.
I hope i made my point clear, If any other information required please let me know.
Regards,
KKJ