Jump to content
Sign in to follow this  
dannyboy

LaunchPad: Watchdog timer interrupts and TACTL

Recommended Posts

I've been working on getting my LaunchPad to play a song on a speaker wired to P1.2, following the code example in this blog. In short, the idea is to use the watchdog timer to increment a global time integer, which is used to write a delay(ms) function used in timing the notes played. The main clock is then used to actually drive the speaker output.

 

The critical part the play() and stop() methods, which are given in the blog like this:

play(unsigned int hz){
 CCR0 = (1000000/hz) -1;
 CCR1 = (1000000/hz)/2;
 TACTL = TASSEL_2 + MC_1;  //start timer
}

stop(){
 TACTL = TASSEL_2 + MC_3;  //stop timer
 CCR0 = 0;
}

 

I like to write code on my own, however, instead of copying code directly from an example. This resulted in me coming up with the following play() and stop() methods:

play(unsigned int hz)
{
 CCR0 = 1000000 / hz - 1;
 CCR1 = 1000000 / hz / 2;
}

stop()
{
 CCR0 = 0;
}

I wrote them like this because I understand that the CCR variables define when the interrupt for the main clock is called - determining the signal put through the speaker. However, when I used this code (setting TACTL = TASSEL_2 + MC_1 in main() as I had done in other code examples), the watchdog timer interrupt was never called, so the global time tick was never incremented, resulting in an infinite loop whenever the delay() method was called.

 

I haven't been able to find a clear reference for this on the net: what does TACTL do, and why does it affect the interrupts from the watchdog timer? Thanks :)

 

(Note: I've changed my code and I'm rocking out to Aerodynamic as we speak... just want to clear this up :P.)

Share this post


Link to post
Share on other sites

hey look at this viewtopic.php?f=10&t=509

 

and to let you know you dont even need to use the watchdog for this.

 

the delay is the problem

use this delay instead :

 

static void delay(int ms)// Delays by the specified Milliseconds

{

while (ms--)

__delay_cycles(1000); //set to 1000 for 1 Mhz

}

 

and take out the watch dog interrupt call all together.

and be sure to put this in

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

 

TACTL is for TIMER A and has nothing to do with the watchdog.

page 410 of the msp430 users guide will explain the TACTL register and what it does

 

good luck

Share this post


Link to post
Share on other sites

Thanks for the hint about __delay_cycles! I've refactored this to not use the WDT at all.

 

TACTL is for TIMER A and has nothing to do with the watchdog.

I figured, but it seemed like the WDT interrupt routine was never serviced when TACTL was set in main() instead of being changed in stop() and play().

Share this post


Link to post
Share on other sites

I am using WDT to generate the sound in one of my projects and there's no reason why it should not work.

 

To make WDT work the way you want you need the following:

//some global var to keep count

unsigned int counter = 0;

 

//enable WDT's interval mode

WDTCTL = WDT_MDLY_0_064;

Share this post


Link to post
Share on other sites

Dont you need to use PWM to play multiple tones?

 

Can you use the watchdog to create PWM? I didnt see that in the user guide.

 

@dannyboy Did you use a certain program for getting the notes to the song you used?

 

thanks

tim

Share this post


Link to post
Share on other sites
@dannyboy Did you use a certain program for getting the notes to the song you used?

Just plucked them out on the guitar and used an electronic tuner to figure out the actual note... because I'm still unable to discern between tones and semitones :P. Having a piano around would help, or even a virtual keyboard.

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...