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.

pwm output for 4.1 khz buzzer msp430g2533

Hi,

I have activate the pwm for 4.1 khz buzzer but its not matching with the 4.1 khz frequency.

P1DIR |= BIT2; \
P1SEL |= BIT2; \

CCR0 = 128; \
CCTL1 = OUTMOD_4; \
CCR1 = 32;

How to calculate the CCRO and CCR1 VALUES FOR MY BUZZER?

  • AND I AM USING INTERNAL OSC SMCLK.
  • Akila,

    first, please jump over to your other thread here:

    Because without a fixed time base you cannot output a PWM with a known frequency as well.

    These settings

    P1DIR |= BIT2;
    P1SEL |= BIT2;

    are OK - they connect P1.2 internally to TA0.1, but you did not configure your timer. Example for doing so:

    #include "msp430g2553.h"
    
    void main( void )
    {
      BCSCTL1   = CALBC1_1MHZ;                    // 1MHz DCO
      DCOCTL    = CALDCO_1MHZ;                    // 1MHz DCO
    
      P1SEL    |= 0x04;                           // P1.2 to TA0.1
      P1DIR    |= 0x04;                           // P1.2 output direction
    
      TA0CCTL1  = OUTMOD_7;                       // reset/set for PWM
      TA0CCR0   = 244;                            // (1 / 4100Hz) / (1 / 1000000Hz) = 243.902 -> 4.1kHz frequency
      TA0CCR1   = 61;                             // 25% duty cycle
      TA0CTL    = TASSEL_2 | ID_0 | MC_1 | TACLR; // SMCLK, CLK divider 1, up-mode, clear
    
      while( 1 );                                 // Endless loop
    }

    I don't know your buzzer, so I just copied your 25% duty cycle and the PWM frequency of 4.1kHz, so please double check if these are the correct settings. If you switch to a higher DCO frequency , then change your CCRx values accordingly.

    Dennis

  • if you do not want to waste a Timer, using 32K crystal with aclk/div8 set.
     BCSCTL1 = DIVA_3;     // div ALCK by 8

    P1.0 can then be set to output a 4.1KHz square wave by setting SEL registers.

    P1.0/TA0CLK/ACLK/A0

    A flipflop could divide it in half and provide higher drive strength  and some even have complemented output (differential)
     and 2KHz also sounds better to your ears.

    http://www.mouser.com/ProductDetail/Texas-Instruments/SN74LVC2G74DCTR/?qs=sGAEpiMZZMvxP%252bvr8KwMwB25p6a2AxEEmAu18JjbIEQ%3d

     

**Attention** This is a public forum