EmbeddedRelated.com
Forums

Sinewave

Started by Andrew Doilidov October 10, 2002
Hi!

Does anyone know if it's possible to generate at least 10 kGz sinewave with
msp430 TimerB PWM mode? With 8bit resolution?

Thanks
Andrew


Beginning Microcontrollers with the MSP430

Hi Andrew,

It would depend on how "clean" you would want your sine.
With most 8/16 bit MCUs howvere you will never make 10 kHz sinewave
directly -
neither with PWM or directly with a DAC.

Some basic maths :

for 8 bit resolution your PWM would be MCU clock / 256 it its best.
So :
say 8 MHz max on MSP430 :
8 MHz / 256 = 31.25 kHz PWM.

To generate a sine wave directly, the most efficient would be to use a
"phase
accumulator" look-up table, but it depends on how accurately you want to be
able to set your sine frequency (if you need that at all)

With a 31.25 kHz PWM I wouldn't see a technique generating an acceptable
sinewave
at a freq much higher than say 0.5 kHz or so.
You could of course obey the Nyquist limit (2 times sample rate) and output
a square wave
at 20 kHz, and then filter it heavily to recover the "fundamental 10
kHz"
sine wave.
But you would need very heavy analog filtering then.


> Hi!
>
> Does anyone know if it's possible to generate at least 10 kGz sinewave
with
> msp430 TimerB PWM mode? With 8bit resolution?
>
> Thanks
> Andrew
>
>
>
> .
>
>
>
> ">http://docs.yahoo.com/info/terms/
>
>


Hi!

> Hi Andrew,
>
> It would depend on how "clean" you would want your sine.
> With most 8/16 bit MCUs howvere you will never make 10 kHz sinewave
> directly -
> neither with PWM or directly with a DAC.
>
> Some basic maths :
>
> for 8 bit resolution your PWM would be MCU clock / 256 it its best.
> So :
> say 8 MHz max on MSP430 :
> 8 MHz / 256 = 31.25 kHz PWM.
[..]

Thanks Kris! Now I understand.
But now I can make my question more precise - I have to generate different
sounds, from 0 to 2 kHz, with different volumes. Volume need to have at
least 64 gradations. And now I'm totally confused. May be you have any
ideas? May be I'm trying to go in wrong direction and it needs some other
external solutions?

Thanks
Andrew




>From: "Andrew Doilidov"
<andrew@andr...>
>Reply-To: msp430@msp4...
>To: <msp430@msp4...>
>Subject: Re: [msp430] Sinewave
>Date: Fri, 11 Oct 2002 09:56:30 -0400
>
>Hi!
>
> > Hi Andrew,
> >
> > It would depend on how "clean" you would want your sine.
> > With most 8/16 bit MCUs howvere you will never make 10 kHz sinewave
> > directly -
> > neither with PWM or directly with a DAC.
> >
> > Some basic maths :
> >
> > for 8 bit resolution your PWM would be MCU clock / 256 it its best.
> > So :
> > say 8 MHz max on MSP430 :
> > 8 MHz / 256 = 31.25 kHz PWM.
>[..]
>
>Thanks Kris! Now I understand.
>But now I can make my question more precise - I have to generate different
>sounds, from 0 to 2 kHz, with different volumes. Volume need to have at
>least 64 gradations. And now I'm totally confused. May be you have any
>ideas? May be I'm trying to go in wrong direction and it needs some
other
>external solutions?

A software DDS might be the way to go. Look at this web site:

http://www.myplace.nu/avr/minidds/

The output voltage is fixed. You could vary it by scaling the samples before 
they are sent to the DAC. I've got an improved version of Jesper's
Mini DDS 
here:

http://webspace.webring.com/people/jl/leon_heller//minidds.html


Leon
--
Leon Heller, G1HSM Tel: +44 1424 14790
Email:leon_heller@leon...
My web page: http://webspace.webring.com/people/jl/leon_heller/
My low-cost Altera Flex design kit: http://www.leonheller.com


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


Hi Leon,

Thanks for the tip about the SW DDS.
I wasn't aware a phase accu setup can achieve such high frequencies on a
low Mips MCU....
Well, you learn something everyday.... !

I'll have to check it one day, to see how long it takes to change freqs. in
the "SW DDS".

B rgds
Kris
 
  ----- Original Message ----- 
  From: Leon Heller 
  To: msp430@msp4... 
  Sent: Saturday, October 12, 2002 3:25 AM
  Subject: Re: [msp430] Sinewave





  >From: "Andrew Doilidov" <andrew@andr...>
  >Reply-To: msp430@msp4...
  >To: <msp430@msp4...>
  >Subject: Re: [msp430] Sinewave
  >Date: Fri, 11 Oct 2002 09:56:30 -0400
  >
  >Hi!
  >
  > > Hi Andrew,
  > >
  > > It would depend on how "clean" you would want your sine.
  > > With most 8/16 bit MCUs howvere you will never make 10 kHz sinewave
  > > directly -
  > > neither with PWM or directly with a DAC.
  > >
  > > Some basic maths :
  > >
  > > for 8 bit resolution your PWM would be MCU clock / 256 it its best.
  > > So :
  > > say 8 MHz max on MSP430 :
  > > 8 MHz / 256 = 31.25 kHz PWM.
  >[..]
  >
  >Thanks Kris! Now I understand.
  >But now I can make my question more precise - I have to generate different
  >sounds, from 0 to 2 kHz, with different volumes. Volume need to have at
  >least 64 gradations. And now I'm totally confused. May be you have
any
  >ideas? May be I'm trying to go in wrong direction and it needs some
other
  >external solutions?

  A software DDS might be the way to go. Look at this web site:

  http://www.myplace.nu/avr/minidds/

  The output voltage is fixed. You could vary it by scaling the samples before 
  they are sent to the DAC. I've got an improved version of Jesper's
Mini DDS 
  here:

  http://webspace.webring.com/people/jl/leon_heller//minidds.html


  Leon
  --
  Leon Heller, G1HSM Tel: +44 1424 14790
  Email:leon_heller@leon...
  My web page: http://webspace.webring.com/people/jl/leon_heller/
  My low-cost Altera Flex design kit: http://www.leonheller.com


  _________________________________________________________________
  MSN Photos is the easiest way to share and print your photos: 
  http://photos.msn.com/support/worldwide.aspx


        
             
              
       
       

  .



   






----- Original Message -----
From: "Kris De Vos" <microbit@micr...>
To: <msp430@msp4...>
Sent: Friday, October 11, 2002 9:53 PM
Subject: Re: [msp430] Sinewave


> Hi Leon,
>
> Thanks for the tip about the SW DDS.
> I wasn't aware a phase accu setup can achieve such high frequencies on
a
low Mips MCU....
> Well, you learn something everyday.... !

It is running at 11 MIPS.

>
> I'll have to check it one day, to see how long it takes to change
freqs.
in the "SW DDS".

Could work it out. It's restricted by the comms speed. The DDS itself
should
change in a few ns.

Regards,

Leon
--
Leon Heller, G1HSM
leon_heller@leon...
http://webspace.webring.com/people/jl/leon_heller/


--- In msp430@y..., "Andrew Doilidov" <andrew@u...> wrote:
> Hi!
> 
> Does anyone know if it's possible to generate at least 10 kGz
sinewave with
> msp430 TimerB PWM mode? With 8bit resolution?
> 
> Thanks
> Andrew

Program a UART channel to 19.K baud (you only need the transmit pin),
then continuously issue 0x55 out of TXD, which produces a square wave
at 9600 Hz.  Then RC filter it so you only get the fundamental, which
is a sinewave at 9600.  It will not be 100% pure for a simple filter,
but it's  cheap, simple, and requires very little micocontroller
bandwidth.

Oscar