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.

How can I generate PWM signal with Timer3?

Hi,

I am trying to generate a PWM signal by using the Timer3, I took the following code from buzzer.c and edited accordingly

    IRCTL &= ~0x01;
    PERCFG &= 0xDF;             // Timer 3 Alternate location 2
    P1DIR |= 0x08;              // P1_3 = output
    P1SEL |= 0x08;              // Peripheral function on P1_3

    T3CTL &= ~0x10;             // Stop timer 3 (if it was running)
    T3CTL |= 0x04;              // Clear timer 3
    T3CTL &= ~0x08;             // Disable Timer 3 overflow interrupts
    T3CTL &= ~0x03;              // Free run

    T3CCTL0 &= ~0x40;           // Disable channel 0 interrupts
    T3CCTL0 |= 0x04;            // Ch0 mode = compare
    T3CCTL0 |= 0x30;            // Ch0 output Set output on compare, clear on 0
    
 
    //T3CTL |= prescaler;
    T3CC0 = 0x02;    
    T3CTL |= 0x10;

However I am receiving the following output

  

It is alternating when it suppose to be one

I thought it is the IR control, therefore I added the following  IRCTL &= ~0x01 , however the output is the same.

What can be the problem?

Thank you for your help.

Regards

Robert.

  • Setting T3CC0 = 0x02; with no prescaler results in an extremely fast switching.

    You're comment is wrong here :  

    T3CCTL0 |= 0x30; // Ch0 output Set output on compare, clear on 0

    This line of code actual sets on 0 and clears on compare. This means that you signal goes high for 4/32MHz = 0.125us

    Maybe your LSA doesn't have the resolution? If so adding a prescaler would give you a slower/cleaner looking waveform.