1

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!

  • The first two and a half paragraphs are not helpful towards the task you are asking for, as you solely want to know how to output a beep in assembly. You should remove it as it takes time reading, which could be spent on solving the task ;) Cheers and welcome to SO – davegson Nov 24 '14 at 22:13
  • I have only worked with IAR for ARM, so I don't know how much of this applies to MSP430, but anyway: if you have hardware debugger, IAR has a possibility to step trough compiled ASM code. If not, check the manual if IAR has any simulator mode for MSP. That way you could see from C program how it is done. Just disable any optimizations first. After that you could start replacing the C functions with inline assembler. Note that I haven't used this method much so I don't know how useful it is in the long run. – user694733 Nov 25 '14 at 08:08
  • The C program uses libraries I don't want to use. I was thinking it should be as simple as outputting a HIGH to the buzzer, but that doesn't seem to work. Additionally, I want to be able to control the tone in the end. That's the hard part. – dhruvaldarji Nov 26 '14 at 00:39
  • This is like a blinking LED, only with a higher frequency. – CL. Nov 30 '14 at 17:31

1 Answers1

0

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.

Nick
  • 1,361
  • 1
  • 14
  • 42