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.

关于MSP430F5438a PWM输出用了TA1.0对应引脚,是不是只能调整周期,不能调整占空比?

Other Parts Discussed in Thread: MSP430F5438A

你好,我用贵公司的MSP430F5438a已经有一年时间了,去年已经有产品卖出去了,这次是产品升级,除了PWM输出外,其他功能已经调试完毕。
我的PWM输出引脚是P8.5,对应TA1.0定时器输出。

我查看芯片用户手册,TAxCCTLn寄存器OUTMOD写着:“Output mode. Modes 2, 3, 6, and 7 are not useful for TAxCCR0 because EQUx = EQU0.”

经过调试,用示波器测得这几种模式都是不产生波形的(包括MC__UPDOWN,MC__UP,MC__CONTINUOUS模式)。

我暂时只能调出可调周期的波形,请问用什么模式输出P8.5可调占空比的PWM???

  • 楼主你好!

    每一种模式都可以输出占空比可调的方波。而且能且仅能产生方波。楼主可以参考下面代码:

    /* --COPYRIGHT--,BSD_EX
    * Copyright (c) 2012, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    *******************************************************************************
    *
    * MSP430 CODE EXAMPLE DISCLAIMER
    *
    * MSP430 code examples are self-contained low-level programs that typically
    * demonstrate a single peripheral function or device feature in a highly
    * concise manner. For this the code may rely on the device's power-on default
    * register values and settings such as the clock configuration and care must
    * be taken when combining code from several examples to avoid potential side
    * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
    * for an API functional library-approach to peripheral configuration.
    *
    * --/COPYRIGHT--*/
    //*******************************************************************************
    // MSP430F543xA Demo - Timer_A3, PWM TA1.1-2, Up/Down Mode, DCO SMCLK
    //
    // Description: This program generates two PWM outputs on P2.2,3 using
    // Timer1_A configured for up/down mode. The value in CCR0, 128, defines the
    // PWM period/2 and the values in CCR1 and CCR2 the PWM duty cycles. Using
    // ~1.045MHz SMCLK as TACLK, the timer period is ~233us with a 75% duty cycle
    // on P2.2 and 25% on P2.3.
    // SMCLK = MCLK = TACLK = default DCO ~1.045MHz.
    //
    // MSP430F5438A
    // -------------------
    // /|\| |
    // | | |
    // --|RST |
    // | |
    // | P2.2/TA1.1|--> CCR1 - 75% PWM
    // | P2.3/TA1.2|--> CCR2 - 25% PWM
    //
    // M. Morales
    // Texas Instruments Inc.
    // June 2009
    // Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
    //******************************************************************************

    #include <msp430.h>

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    P2DIR |= 0x0C; // P2.2 and P2.3 output
    P2SEL |= 0x0C; // P2.2 and P2.3 options select
    TA1CCR0 = 128; // PWM Period/2
    TA1CCTL1 = OUTMOD_6; // CCR1 toggle/set
    TA1CCR1 = 32; // CCR1 PWM duty cycle
    TA1CCTL2 = OUTMOD_6; // CCR2 toggle/set
    TA1CCR2 = 96; // CCR2 PWM duty cycle
    TA1CTL = TASSEL_2 + MC_3 + TACLR; // SMCLK, up-down mode, clear TAR

    __bis_SR_register(LPM0_bits); // Enter LPM0
    __no_operation(); // For debugger
    }

  • Billy 你好!

    你给我的例程我也有,我的旧版本设备硬件就是用TA1.1对应引脚P8.6。但是我输出的是TA1.0的相应引脚,不知你们有否试过输出TA1.0或者或者TA1.0的相应引脚,

    我上网查基本都是TAx.1和TAx.2的用法,就没见过有人用输出TA1.0或者或者TA1.0的相应引脚。

    还是原来的问题,我用io口P8.5输出可调占空比的PWM,怎么输出?

  • 对于TA1.0 即CCR0比较输出只能用Output4模式即翻转输出,此时只能调节周期不能调节占空比,因为占空比一直是50%,用CCR1,CCR2可以利用CCR0做周期而CCR1/2做占空比模式7输出可调占空比的PWM。

  • Xutong Han2 你好

    根据我的调试,就是你所说的那样,谢谢你,这样我好去跟我做硬件的同时说清楚让他改硬件。。

  • 如果不想改硬件,可以使用中断在timer中断中翻转GPIO,也可以输出PWM。

  • 我试过你所说的方法,但是不行,无论是continuous还是其他模式,用MODE4。。

  • CCR0控制周期/频率,CCR1控制占空比。在CCR0中断中GPIO = 0;CCR1中断中GPIO = 1;upmode、downmode、updownmode都可以。

  • 你这样做是用计时器模拟PWM吧,而且这个TIMERA不是只有到达CCR0才进一次吗,到达CCR1也能??能给个代码看看吗?