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.

MSP430 PWM 1HZ



Please help me with the code QQ

i am now suffering from the draining of my brain @@

How can i generate exactly a PWM signal with exactly "1 HZ"

here' s the already finished code:

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
DCOCTL = 0; // Select lowest DCOx and MODx
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation

/*** GPIO Set-Up ***/
P1DIR |= BIT2; // P1.2 set as output
P1SEL |= BIT2; // P1.2 selected Timer0_A Out1

/*** Timer0_A Set-Up ***/

TA0CCR0 |= 1000-1; // PWM Period
TA0CCTL1 |= OUTMOD_7; // TA1CCR1 output mode = set/Reset
TA0CCR1 |= 250-1;
TA0CTL |= TASSEL_2 + MC_1; // SMCLK, Up Mode (Counts to TA1CCR0)




but i don't how to generate the signal in "1HZ"
i am now using MSP430 G2553

  • Do you want 1Hz of frequency with 50% duty cycle? Or do you need a variable duty-cycle inside the 1Hz? If variable, what is the desired resolution of the PWM?

    Dennis

  • Mark Huang said:
    How can i generate exactly a PWM signal with exactly "1 HZ"

    Easy. Using formula: PWM_frequency = timer_clock_frequency/(PWM_period_count-1).

    In your case it would be timer running from watch crystal (fork) oscillator, 32768Hz and TA0CCR0 = (32768 -1);

    Mark Huang said:
    TA0CCR0 |= 1000-1; // PWM Period

    This is totally wrong assignment that could lead to register contents which is not desired 999.

    You shall be using "="  operand, not "|=". Actually all your timer setup lines have same error.

  • Ilmars said:
    In your case it would be timer running from watch crystal (fork) oscillator, 32768Hz and TA0CCR0 = (32768 -1);

    This will be the best choice.

    If you do not have a watch crystal available in your application, you can also use an ISR driven software method for this low frequency.

**Attention** This is a public forum