Jump to content
Sign in to follow this  
squalo

I can't stop PWM signal because i can't use timer interrupt vector

Recommended Posts

Hi,

i'm trying to start a pwm signal and stop it after 50 miliseconds. But i can't because i can't use timer interrupt vector properly. my count never increments.

Here is my code 

#include <msp430.h>
#include <msp430g2553.h>
void startPWM(void);

unsigned char counter=0;

void stopPWM(void);

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ;
CCTL0 = CCIE;

P2DIR |= BIT2; //IR transmitter
P2SEL |= BIT2;// Select pwm pin (transmitter)

P2OUT=0x00;


while(1){

if((P1IN & BIT4)!=BIT4) //button is pressed
{
startPWM(); //send pwm
stopPWM(); // stop after 50 ms
}

}

}

void startPWM(void) // pwm signal
{
TA1CCR0 = 26-1; // Period Register
TA1CCR1 = 13; // 50% dutycycle
TA1CCTL1 |= OUTMOD_6; // TA1CCR1, Reset/Set
TA1CTL = TASSEL_1 + MC_1 + TACLR;
}


void stopPWM(void) // trying to stop after 50 ms
{
CCR0 = 5000; // CCR0 5 ms
TACTL = TASSEL_2 + MC_2; //
}

#pragma vector=TIMER0_A0_VECTOR // Timer0_A0
__interrupt void Timer_A (void)
{
if(++counter==10){ // is counter 10 (5*10=ms)
TA1CCR1 = 0; ; // Stop timer so it can't send PWM signal
counter = 0;
}
}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...