Simple Metronome using MSP430 Launchpad

In the beginning of this year I decided to start taking piano lessons.  Step-by-step the moment I had to start playing using metronome came. My teacher told me to by one. Unfortunately I didn’t found time to buy one. My MSP430 Launchpad had just arrived four days earlier. So I decided to build my on metronome. I opened the “Big-Bag-Of-Parts”, and found the appropriate sound buzzer.

For this project I used MSP430G2231.

This is a video of the Metronome in action.

This is a photo of MSP430 Launchpad with the additional components, ready to work as a metronome.

Metronome Photo

As you can see the only additional parts are two bridges (I made them out of paper clips), and one buzzer.
The bridges are placed in the headers holes on the Launchpad. The first bridge goes from P1.0(LED1) to P2.2. P1.0 (LED1) is the pin that will triger the buzzer. You will find how below in the source code. The other bridge goes from GND to P2.3. These bridges transfer the required signals to a part of the Lauchpad, which is not used, when working MSP430G2231 controller.

A picture of the buzzer is shown below.
Metronome Buzzer

I bought four of these buzzer from a local electronics shop. The price was something like 0.4 BGN (20 eurocent) for each. The part number is TDB05LFPN. They can be found in online shop (for much higher price … that’s strange). You plug the buzzer in the last couple of holes on the microcontroller socket. Pay attention on the polarity of the buzzer. Plug the “+” in the P2.2 hole.

This is the hardware. Now it’s time for the software. I assume you have CCS installed. The listing of the code is shown below.

#include "msp430g2231.h"

#define LED0 BIT0
#define BUTTON BIT3

static int timer = 10000;

void delay_ms(unsigned int ms )
{
    unsigned int i;
    for (i = 0; i<= ms; i++)
       __delay_cycles(500); //Built-in function that suspends the execution for 500 cicles
}
 
void delay_us(unsigned int us )
{
    unsigned int i;
    for (i = 0; i<= us/2; i++) 
       __delay_cycles(1);
}

void beep(void)
{
	P1OUT |= BIT0;     //Set P1.2...
    delay_us(2000);   //...for a semiperiod...
    P1OUT &= ~BIT0;    //...then reset it...
    
}

int main( void )
{
    WDTCTL = WDTPW + WDTHOLD; //Disable Watchdog Timer
    BCSCTL1 = CALBC1_1MHZ; // Set range
	DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
    
    P1DIR|=BIT0;              // P1.2 output
    
    P1IE |= BUTTON; // P1.3 interrupt enabled
	P1IFG &= ~BUTTON; // P1.3 IFG cleared

	__enable_interrupt(); // enable all interrupts
        
    while(1)
    {
	beep();              
	delay_ms(timer);      //Add a 2 sec. delay to avoid replaying right after the end.
    }
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1OUT ^= (LED0); // P1.0 = toggle
P1IFG &= ~BUTTON; // P1.3 IFG cleared
P1IES ^= BUTTON; // toggle the interrupt edge,
// the interrupt vector will be called
// when P1.3 goes from HitoLow as well as
// LowtoHigh
timer = (timer*9)/10;

}

After the code is loaded in the Launchpad, the Metronome is ready. You can use the usb cable as a power supply, or you can use any other way to suply the launchpad. As you can see in the video I used PC power supply and a couple of wires.
After Launchpad is powered it will start beeping. You can increse the speed by pressing P1.3 button.

That is how you can make Simple Metronome using MSP430 Launchpad, within 15min.

Designing the project took me 1 hours, documenting and posting it 4-5 hours. 🙂 Hope you find it usefull.

Leave a Reply

Your email address will not be published. Required fields are marked *

*