简体   繁体   English

如何使用汇编语言在MSP430上播放音调

[英]How to play a tone on the MSP430 using Assembly language

I want to play a song via a buzzer connected to an MSP430. 我想通过连接到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. 我正在使用IAR的Embedded Workbench进行此项目。

Note, I can do this easily in C using libraries, but I want to do this using only assembly. 注意,我可以使用库在C语言中轻松完成此操作,但是我只想使用汇编语言即可完成此操作。

Could someone post an example of outputting a 'beep' or a HIGH to a buzzer connected to an MSP430 using only Assembly. 有人可以发布一个仅使用Assembly向连接到MSP430的蜂鸣器输出“蜂鸣”或“高”的示例。 I can figure out the rest. 我可以找出其余的。

Thank you in advance! 先感谢您!

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. CL在评论中提到了这一点。 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. 要实现更高的精度,可以在MSP430上使用PWM引脚。 You are going to want to drive the buzzer with a PWM signal with a 50% duty cycle. 您将要使用占空比为50%的PWM信号来驱动蜂鸣器。

PWM output pins are a part of the timer modules on the MSP430. PWM输出引脚是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. 通常,您可以使用数字振荡器(DCO)来提供时钟,然后再将其提供给定时器。 In doing so you can vary the frequency of your PWM signal. 这样做可以改变PWM信号的频率。 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. 如果由于某种原因(例如您需要为DCLK使用DCO并且不想弄乱它)而不能这样做,则可以通过使用源时钟的分频器来手动设置计时器频率,而无需调整定时器寄存器。

Here is an app note on the matter: http://www.ti.com/lit/an/slaa116/slaa116.pdf 这是关于此事的应用笔记: 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. 否则,您可以使用定时器模块对自己的PWM信号(在任何引脚上)进行位爆裂,并将捕获/比较更改为手动控制频率。

Some questions that could help provide a better answer: 一些可以帮助提供更好答案的问题:

  1. What series of the MSP430 are you using 您正在使用什么系列的MSP430
  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. 蜂鸣器是否连接到GPIO引脚,或者该引脚可以由定时器模块的PWM输出驱动。
  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? 如果使用DCO进行其他操作,您是否具有可用于MCLK的外部晶体?

I still don't understand why you would choose to do this in assembly and not use C unless this is a homework question. 我仍然不明白为什么您会选择在汇编中执行此操作而不使用C,除非这是一个家庭作业问题。 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. 即便如此,我还是会先用C语言完成它的工作,然后在我完成所有假设后再返回并进行汇编。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM