EmbeddedRelated.com
Forums

MSP430G2553 Sounds

Started by "tre...@yahoo.com [msp430]" November 17, 2016
Hello, my name is Trevor! I was wondering if anyone could help me generate 3 different sounds using a piezo speaker on a msp430 using only assembly language. I understand these different 3 sounds are different frequencies and are thus controlled by DCOCTL and the different BSCCTL registers. In theory, I believed a jump statement could go to different labels where the settings of the registers and the DCOCTL could be changed ,however i keep getting the same output sound.

Beginning Microcontrollers with the MSP430

First you don't use DCOCTL and BSCCTL, these are for the DCO or
digitally controlled oscillator, and the basic clock module. these
govern the instruction execution rate, the peripheral to use is the
timer, and there are many ways to do it using the timer. Secondly make
sure you are you using a speaker not a piezo sounder. Often they are
badly described in catalogues. A sounder will always have the same
tone. Do you want the sounds to run for a fixed time or is one sound
always on? The MSP430 has quite powerful timer control functions. The
basic timer functions, like clock source, clock division, start, stop,
and count mode are set in the TxCTL register while each timer channel
has its own control register so that each channel could be running a
different timer function. The 2553 spoils you for choice, you have 2 3
channel timers of Type A. In the channel control register you can
control what happens to that channels assigned output pin when the timer
match occurs, so, for example set TimerA0_0 (timer type A number 0
channel 0) so that it interrupts after a desired time, and when it
interrupts it toggles its output pin, this generates a square wave, and
all you then need do is decide the time period, create a small ISR which
simple adds the time period to generate the desired frequenct to that
channels CCRx register, and, make sure the interrupt flag is cleared.
CH0 clears the iFG automatically, and has it's own interrupt vector, if
you use ch1 or ch2 you will need to use the TAIV vector to select the
right channel ISR. This works well in continuous mode. If you need to
recude the timer maximum count for any reason, for example it is running
an RTC and you want it to only count to 32768 your isr will need to
account for this.

If you only want the timer tone to run for a certain time then start a
second timer at the same time yoiu enable to frequency output and have
its ISR stop both timers and set the output pin of the tone output to '0'.

It's worthwhile studying and playing around with the timers, as well as
reading every app note you can get. If you truly understand how these
timers work you can do almost anything with a small micro. For example
people compare the blinky LED to 'Hello World' on a PC or high level
language, but in fact it's much more potent than that, more akin to a
sensor and communications toolkit in a few easy registers.
Al

On 18/11/2016 5:08 AM, t...@yahoo.com [msp430] wrote:
> Hello, my name is Trevor! I was wondering if anyone could help me
> generate 3 different sounds using a piezo speaker on a msp430 using
> only assembly language. I understand these different 3 sounds are
> different frequencies and are thus controlled by DCOCTL and the
> different BSCCTL registers. In theory, I believed a jump statement
> could go to different labels where the settings of the registers and
> the DCOCTL could be changed ,however i keep getting the same output sound.
Actually it is enough to have one timer running on fix frequency, for example 100kHz. In the ISR you have a counter and toggle the piezo output each n-th call, in this case 50 for 1kHz. In this case you need only one timer for sound and duration and you can generate zillions of sounds changing only one parameter.

Waldemar

Am 17.11.2016 um 20:39 schrieb Onestone o...@bigpond.net.au [msp430] >:

First you don't use DCOCTL and BSCCTL, these are for the DCO or digitally controlled oscillator, and the basic clock module. these govern the instruction execution rate, the peripheral to use is the timer, and there are many ways to do it using the timer. Secondly make sure you are you using a speaker not a piezo sounder. Often they are badly described in catalogues. A sounder will always have the same tone. Do you want the sounds to run for a fixed time or is one sound always on? The MSP430 has quite powerful timer control functions. The basic timer functions, like clock source, clock division, start, stop, and count mode are set in the TxCTL register while each timer channel has its own control register so that each channel could be running a different timer function. The 2553 spoils you for choice, you have 2 3 channel timers of Type A. In the channel control register you can control what happens to that channels assigned output pin when the timer match occurs, so, for example set TimerA0_0 (timer type A number 0 channel 0) so that it interrupts after a desired time, and when it interrupts it toggles its output pin, this generates a square wave, and all you then need do is decide the time period, create a small ISR which simple adds the time period to generate the desired frequenct to that channels CCRx register, and, make sure the interrupt flag is cleared. CH0 clears the iFG automatically, and has it's own interrupt vector, if you use ch1 or ch2 you will need to use the TAIV vector to select the right channel ISR. This works well in continuous mode. If you need to recude the timer maximum count for any reason, for example it is running an RTC and you want it to only count to 32768 your isr will need to account for this.

If you only want the timer tone to run for a certain time then start a second timer at the same time yoiu enable to frequency output and have its ISR stop both timers and set the output pin of the tone output to '0'.

It's worthwhile studying and playing around with the timers, as well as reading every app note you can get. If you truly understand how these timers work you can do almost anything with a small micro. For example people compare the blinky LED to 'Hello World' on a PC or high level language, but in fact it's much more potent than that, more akin to a sensor and communications toolkit in a few easy registers.
Al

On 18/11/2016 5:08 AM, t...@yahoo.com [msp430] wrote:

Hello, my name is Trevor! I was wondering if anyone could help me generate 3 different sounds using a piezo speaker on a msp430 using only assembly language. I understand these different 3 sounds are different frequencies and are thus controlled by DCOCTL and the different BSCCTL registers. In theory, I believed a jump statement could go to different labels where the settings of the registers and the DCOCTL could be changed ,however i keep getting the same output sound.
Yes, there are plenty of different ways to do this. A single counter
only works for a limited range of durations, whereas a second timer
allows you to control the timebase by using either different clock
sources or different clock divider values.

Al

On 18/11/2016 8:00 AM, 'Krzok, Waldemar' w...@charite.de
[msp430] wrote:
> Actually it is enough to have one timer running on fix frequency, for
> example 100kHz. In the ISR you have a counter and toggle the piezo
> output each n-th call, in this case 50 for 1kHz. In this case you need
> only one timer for sound and duration and you can generate zillions of
> sounds changing only one parameter.
>
> Waldemar
>
> Am 17.11.2016 um 20:39 schrieb Onestone o...@bigpond.net.au
> [msp430] > >:
>
>> First you don't use DCOCTL and BSCCTL, these are for the DCO or
>> digitally controlled oscillator, and the basic clock module. these
>> govern the instruction execution rate, the peripheral to use is the
>> timer, and there are many ways to do it using the timer. Secondly
>> make sure you are you using a speaker not a piezo sounder. Often
>> they are badly described in catalogues. A sounder will always have
>> the same tone. Do you want the sounds to run for a fixed time or is
>> one sound always on? The MSP430 has quite powerful timer control
>> functions. The basic timer functions, like clock source, clock
>> division, start, stop, and count mode are set in the TxCTL register
>> while each timer channel has its own control register so that each
>> channel could be running a different timer function. The 2553 spoils
>> you for choice, you have 2 3 channel timers of Type A. In the channel
>> control register you can control what happens to that channels
>> assigned output pin when the timer match occurs, so, for example set
>> TimerA0_0 (timer type A number 0 channel 0) so that it interrupts
>> after a desired time, and when it interrupts it toggles its output
>> pin, this generates a square wave, and all you then need do is decide
>> the time period, create a small ISR which simple adds the time period
>> to generate the desired frequenct to that channels CCRx register,
>> and, make sure the interrupt flag is cleared. CH0 clears the iFG
>> automatically, and has it's own interrupt vector, if you use ch1 or
>> ch2 you will need to use the TAIV vector to select the right channel
>> ISR. This works well in continuous mode. If you need to recude the
>> timer maximum count for any reason, for example it is running an RTC
>> and you want it to only count to 32768 your isr will need to account
>> for this.
>>
>> If you only want the timer tone to run for a certain time then start
>> a second timer at the same time yoiu enable to frequency output and
>> have its ISR stop both timers and set the output pin of the tone
>> output to '0'.
>>
>> It's worthwhile studying and playing around with the timers, as well
>> as reading every app note you can get. If you truly understand how
>> these timers work you can do almost anything with a small micro. For
>> example people compare the blinky LED to 'Hello World' on a PC or
>> high level language, but in fact it's much more potent than that,
>> more akin to a sensor and communications toolkit in a few easy registers.
>> Al
>>
>> On 18/11/2016 5:08 AM, t...@yahoo.com [msp430] wrote:
>>>
>>>
>>> Hello, my name is Trevor! I was wondering if anyone could help me
>>> generate 3 different sounds using a piezo speaker on a msp430 using
>>> only assembly language. I understand these different 3 sounds are
>>> different frequencies and are thus controlled by DCOCTL and the
>>> different BSCCTL registers. In theory, I believed a jump statement
>>> could go to different labels where the settings of the registers and
>>> the DCOCTL could be changed ,however i keep getting the same output
>>> sound.
>>>
>>>
>>>
>