How to play a tone on the MSP430 using Assembly language

1.5k views Asked by At

I want to play a song via a buzzer connected to an MSP430. The song will be a series of times or beeps. However I do not know how to make a buzzer beep or how to control its tone in Assembly. I am using IAR's Embedded Workbench to work on this project.

Note, I can do this easily in C using libraries, but I want to do this using only assembly.

Could someone post an example of outputting a 'beep' or a HIGH to a buzzer connected to an MSP430 using only Assembly. I can figure out the rest.

Thank you in advance!

1

There are 1 answers

0
Nick On

I am going to answer this question making a lot of generalizations and assumptions. If you can clear up some questions though I may be able to refactor this answer and give a better one.

CL hit on this in the comments. You need to drive the pin high and low at a certain frequency. You can do that quite simply by driving it high, delaying for an appropriate number of cycles (depending on your clock frequency) and then driving it low, etc.

To do it with a higher degree of precision however you could use a PWM pin on your MSP430. You are going to want to drive the buzzer with a PWM signal with a 50% duty cycle.

PWM output pins are a part of the timer modules on the MSP430. Timer modules are flexible in which clock source you use and have a lot of scaling options to adjust the frequency. You can generally use the Digitally Controlled Oscillator (DCO) to feed a clock which can then feed a timer. In doing so you can vary the frequency of your PWM signal. If you can't do that for some reason (like you need to use DCO for your MCLK and don't want to mess with it) you can set the timer frequency manually by playing with the the source clock's dividers without having to adjust the timer registers.

Here is an app note on the matter: http://www.ti.com/lit/an/slaa116/slaa116.pdf

Otherwise you can use a timer module to bit bang your own PWM signal (on any pin) and change the capture/compare to manually to control the frequency.

Some questions that could help provide a better answer:

  1. What series of the MSP430 are you using
  2. What kind of buzzer is this, do you have a data sheet?
  3. Is the buzzer connected to a GPIO pin, or can the pin be driven by the PWM output of a timer module.
  4. Is it safe to assume this buzzer is just a transducer that needs some external drive signal - or is it something fancy with an internal oscillator that just has an enable signal.
  5. Can you post a schematic?
  6. Do you have an external crystal that you can use for your MCLK if DCO is used to do something else?

I still don't understand why you would choose to do this in assembly and not use C unless this is a homework question. And even then, I would do it in C first to get it working and then go back and do it in assembly once I've hammered out all of my assumptions.