I want to generate duty cycle adjustable pwm with msp430. and I write a program using timer_a interrupt that change pwm duty cycle between 80% and 20% but it won't work.I think something is wrong with the interrupt i can't figure out.Here is the code:
Rich (BB code):
#include<msp430x16x.h>
typedef unsigned int uint;
typedef unsigned char uchar;
uint i,j=0;
void int_clk()
{
BCSCTL1 &= ~XT2OFF;
do
{
IFG1&=~OFIFG;
for(i=0xff;i>0;i--);
}
while((IFG1&OFIFG));
BCSCTL2|=SELM_2+SELS;//XT2 for m&smclk
}
void int_ta()
{
TACTL=TASSEL_2+TACLR+MC_1+TAIE;//smclk;upmode;interruptenable
///8Mhz for timer_a(start!)
TACCTL1|=OUTMOD_7;//reset/set mode
TACCR0=499;//period
TACCR1=100;
}
void main()
{
WDTCTL=WDTPW+WDTHOLD;
int_clk();
int_ta();
P1DIR|=BIT6;
P1SEL|=BIT6;
_EINT();
}
#pragma vector=TIMERA0_VECTOR
__interrupt void timera0(void)
{
if(TACCR1==100)
TACCR1=400; //80% duty cycle
else
if(TACCR1==400)
TACCR1=100; //20% duty cycle
}
Last edited by a moderator: