Jump to content
Sign in to follow this  
RogueGeek

Sine Wave Generator using PWM like a class D amplifier.

Recommended Posts

About a year or so ago, I quit working on a project which would generate the 1200 baud audio tones for an AFSK Amateur Radio system.

Due to real life getting in the way, I never finished it.  I got it to generate the audio tones but never fully implemented the ascii data input handling.

This general design isn't anything new, it has been done before on other platforms and it is quite likely someone has done it on the MSP.

It was my first real development effort using Timers and was a good learning experience. 

I figured it was time to post the code in case all or part of it might be useful to someone.   USE AT YOUR OWN RISK.

 

Essentially this code implements a software driven class D amplifier using an MSP430G2553 to generate either a 1200Hz  or  2200 Hz sine wave using PWM.

The PWM output is run through a simple low pass filter to get the clean sine wave audio tones.

 

This uses all of the available timers on the G2553.

TA1 is the PWM generator running at 500Khz

TA0 is the modulator.

WDT is used as an interval timer to clock the ascii data into the modulator at 1200 buad (this is where I stopped working)

 

The TA0 modulator steps through the wave table and updates the TA1 PWM duty cycle setting it to the value in the wave table.  TA1CCR1  = SineTable[sinePosition];

This runs in a continuous loop. The rate at which TA0 steps through the table is the MARK and SPACE values.  This rotating PWM duty cycle is what generates the 1200Hz or 2200Hz sine wave.

The 500Khz PWM frequency is filtered out by the low pass filter.

 

The NOT WORKING parts.

Basically I quit shortly after starting on the ASCII input handling. The idea was that the WDT loop would set TA0 to MARK or SPACE depending on the ASCII character to be sent.

I was in the process of trying to implement a FIFO buffer when I stopped developing the code.

 

I hope someone finds this useful. 

 

-Brian

 

WARNING:  The code you are about to view most likely breaks every known rule for good software design.

It may use magic numbers, variables named X or Y, have little of no care for memory management, or have numerous other or unknown issues.

This was R&D code and I never really meant for it to be seen by anyone other than myself.

 

 

SineGenPWM_main.c

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...