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.

MSP430F5310 PWM output is always one (1), high, at rest



I am using TimerA1 to generate a PWM output. I am using the timer in up-mode. I am basically using it to make warning beeps to drive a piezo. The frequency is about 2kHz.

In this mode, the counter resets when it reaches the tic count in TA1CCR0. I am using TA1CCR1 as the compare registers. I am getting the waveform and duty cycle that I want. But, curiously, the output is always set to one (1) in between PWM bursts. I was using OUTMOD_7. So, I figured that OUTMOD_3 would reverse the resting state. OUTMOD_3 inverted the waveform BUT, the resting state was still a one. I put it back to OUTMOD_7.

How can I force the resting output state to be zero?

Jim

  • Switch it back to normal port function with output set low when the PWM is not needed.
  • Or switch to OUTMOD_0 with the OUT bit clear.

    EDIT: It's strange that OUTMOD_3 didn't resolve the issue for you. I can only think that you were stopping the timer after the output had gone high again (ISR latency?), but that should have affected OUTMOD_7 equally and given output low in that case.

  • "EDIT: It's strange that OUTMOD_3 didn't resolve the issue for you."

    Yeah, I know. A colleague of mine was using the PWM to bit-bang data out to a TI LED PWM controller and said he ran into the same issue. The resting state was wrong for what he needed. He ended up moving over to SPI\I2C.

    I think it's a flaw in the hardware. I can live with the wrong resting state for my application. It's just not as clean as I would like.

  • OK, I found it. It turns out that the code turns off the audio with the following: TA1CCTL1 &= ~OUTMOD_7; This configures the output to use the OUT bit. See the interrupt excerpt below.

    It turns out that I was doing what Robert C. mentioned but I just didn't know it yet.

    So, there is no magic. It's explainable and works as it should.

    Jim

    ==================================================================
    Interrupt excerpt:
    ------------------------------------------------------------------
    case TA1IV_TACCR1: // TACCR1
    TA1CCTL0 &= ~CCIE; // Disable interrupt
    TA1CCTL1 &= ~OUTMOD_7; // Disable PWM mode for TA1.1 (AUDIO_OUT_4)
    TA1CCTL1 &= ~CCIE; // Disable interrupt for TA1.1
    TA1CCTL1 &= ~CCIFG; // Clear interrupt flag for TA1.1
    break;
    ==================================================================
  • For simplicity, speed and code saving you might write this as;

    	TA1CCTL1 &= ~(
    		OUTMOD_7 |	// Disable PWM mode for TA1.1 (AUDIO_OUT_4)
    		CCIE |		// Disable interrupt for TA1.1
    		CCIFG );	// Clear interrupt flag for TA1.1
    

  • >> For simplicity, speed and code saving you might write this as;

    Yeah, I haven't gotten around to cleaning that up. It was part of my testing to take it step-by-step.

    I only used an excerpt for my post. What was missing was local debug variables that I had to declare as volatile because the optimizer wouldn't allow breakpoints to be set on them. It optimized them out. This was with optimization turned off. However, there seems to be some baseline optimization that takes place anyway.

    But, good point, I will make sure to get that combined. Thanks for the input.

    Regards,
    Jim

**Attention** This is a public forum