This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Generating Sine Wave Signal from MSP430

Other Parts Discussed in Thread: MSP430G2553

Dear all,

I am planning to design simple pure sine wave using MSP430G2553 launchpad. I have no idea how to generate sine wave. I have followed some link but it is not much helpful generate purely. Is it require filter at the output end? Experts please help me.

Thanks in advance.

Betul

  • Since the G2553 doesn't have an internal DAC, the most obvious method is generating PWM and running it through an external low-pass filter.

    Google "pwm filter signal". When I just did that, the top of the list was right here at ti.com:
    www.ti.com/.../spraa88a.pdf

    It's for a different MCU, but don't let that stop you -- the principles and analysis (most of the document) are generally applicable.

    "Pure" is an asymptote. How close you get depends on your PWM resolution and how good a filter you construct.
  • Also beware the inherent limitation on frequency range from such an approach. Both from the perspective of how high a frequency the MSP430 can generate (most likely SMCLK/2) and the implementation of the external filter. E.g. a filter designed for sine wave at 100 KHz will give you square wave output at 100 Hz.
  • Thank you for your reply. Previously I generate PWM but this is not seems  like a pwm accurately. I think the cause of problem is filter but I have no idea which filter is available. Iam very confused. Can you share related some links or about your ideas?

    Thanks for your help

  • I could generate PWM %50 Duty cycle.But I don't understand generate sine wave from pwm.Could you help me about it?Maybe some friends confuse with same problem. Pwm code is here.

    #include "msp430g2553.h"

    void main( void )
    {
    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

    BCSCTL1 = CALBC1_1MHZ; // Set range to 1MHz
    DCOCTL = CALDCO_1MHZ; // Set DCO step and modulation to 1MHz

    P1SEL = 0x40; // Enable timer function for P1.6 (TA0.1)
    P1DIR = 0x40; // Set P1.6 (TA0.1) to output direction

    TA0CCR0 = 10000; // Period for 1st PWM: 10ms @ 1MHz
    TA0CCR1 = 5000; // Duty cycle for 1st PWM: 5ms @ 1MHz
    TA0CCTL1 = OUTMOD_7; // TA0.1 reset/set mode
    TA0CCTL2 = CCIE; // Compare interrupt for 25% of elapsed duty cycle
    TA0CTL = TASSEL_2 | ID_0 | MC_1 | TACLR; // 1st PWM: SMCLK, divider 1, up-mode, clear


    __bis_SR_register( GIE ); // Enable interrupts

    while( 1 );
    }

    #pragma vector = TIMER0_A1_VECTOR // Compare interrupt for 25% elapsed duty cycle
    __interrupt void TIMER0_A1_ISR( void )
    {
    TA0CCTL2 = 0x00; // Clear compare interrupt - executed only once
    }
  • Betul Bakar said:
    But I don't understand generate sine wave from pwm.

    You need an analog filter outside of the MSP430. The cutoff frequency should be slightly (maybe 1.25 to 1.5x) than the sine-wave you are trying to generate.

    Some additional reading:

    http://www.ti.com/lit/pdf/spna217

    http://www.ti.com/lit/pdf/SLAA497

    http://www.ti.com/lit/an/sbfa003/sbfa003.pdf

  • Hi Brian,

       I applied first order low pass filter at the output of Msp430. Before filter I generated 100 Hz pure PWM but after filter using I am looking sawtooth on the Dewesoft screen. I used R=47 k ohm and C=22 nF. Cut off frequency is approximately 161 Hz. Why doesn't see sine wave I dont understand.I think I missed some issues. What do you think about my result?

    Thank you for your help

    Betul

  • Betul,

    You are on the right track. Couple of things - you really need a 3rd-order filter to get close to a sine-wave. The db/decade roll off of a 1st order filter is very slow and allows the higher-order harmonics to come through.

    This page has good online calculator: http://sim.okawa-denshi.jp/en/Fkeisan.htm

    Also be careful about the values you choose when it comes to impedance matching. I don't know what the sine wave is feeding, but your filter is high-impedance (47K). 

    See this attached simulation of 3rd-order RC filter with 15K resistors (impedance is ~45K). I roughly modeled the MSP430 output with 20 ohms and 10pF and normalized it to 1V.

  • {facepalm} what you are doing guys :) You really want to read www.ti.com/.../spraa88a.pdf which was mentioned by Bruce. 

    Betul Bakar said:
    Before filter I generated 100 Hz pure PWM but after filter using I am looking sawtooth

    Please note that running square wave signal (PWM at 50% duty cycle) through RC filter is not PWM DAC at all. It's just filtering square wave signal with RC filter :D

    Proper PWM DAC shall consist of waveform table (in this case sine) which is fed into CCR register of timer which is updated every timer cycle with next value from table. In such case filtering is much easier too - because PWM frequency is much higher than filter cutoff freq.

  • Brian,

    Thank you for your all help. I generate sine wave using your recommended filter. Sine wave frequency is 100 Hz. But I want to apply different frequencies to sine wave. I changed my TA0CCRO value for getting different frequency. I obtained 100 Hz using this calculation: TAOCCRO / 1 mhz= 0.01 s and 1/0.01=100 hz. I applied same calculation for example 10 kHz but I couldn't obtain .Could you give me feedback about this calculation?

    Betul
  • What do you mean by "but couldn't obtain"? Was there no square wave output at the MSP pin? If you change the frequency, you also need to change the analog filter as well.

    Assuming you are configuring the TA0 module to use the 1MHz clock, that the calculation is CCR0 = (1000000 / 10000 ) - 1 = 100 - 1 = 99
  • Hi Brian,

    I have two questions for you:

       1.I gave CCRO:10000 and generate 100 hz approximately 3 p-p  V sine wave but  I give CCRO: 100 I expected 10 khz and app. 3 V but I see 50 Hz and 1.1 V. I am sure for calculation. I don't understand what I missed out.

       2.My product has buttons and must generate sine wave different frequency.Brian is there anyway using fix filter for different frequency at the output of MSP430? For example, I have two different frequencies of  PWM but one filter and generate  two different frequencies sine wave. 

    Thanks for your advice

    Betul

  • Betul Bakar said:
       2.My product has buttons and must generate sine wave different frequency.Brian is there anyway using fix filter for different frequency at the output of MSP430? For example, I have two different frequencies of  PWM but one filter and generate  two different frequencies sine wave. 

    No, you can't. - Not by using 50% duty cycle PWM with fixed RC filter behind it. I would suggest proper PWM DAC design (using wave table) as I described already, but you you did not even notice my post ;) So be it ;)

  • Hi Ilmars,

      Sorry for my late response. I did not understand what do you mean your solution.But I hope, I understand now. You suggest way like a this link:

    http://www.msp430launchpad.com/2011/06/simple-launchpad-dac.html I will try and thank you for your advice.

    Betul

  • Betul Bakar said:

    Yes, exactly. Seems like good starting point for you.

  • How are you doing? Any progress?

**Attention** This is a public forum