[求助] pwm问题

cylot   2011-4-8 17:01 楼主
我对lm3s6965例程里的pwm例程把PD1改PE1,结果PE1输出低电平,而没改之前PD1输出对应的是喇叭,高电平有效,一下是原厂提供的程序
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "drivers/rit128x96x4.h"

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

//*****************************************************************************
//
// This example demonstrates how to setup the PWM block to generate signals.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulPeriod;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Initialize the OLED display.
    //
    RIT128x96x4Init(1000000);

    //
    // Clear the screen and tell the user what is happening.
    //
    RIT128x96x4StringDraw("Generating PWM", 18, 24, 15);
    RIT128x96x4StringDraw("on PF0 and PD1", 18, 32, 15);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Set GPIO F0 and D1 as PWM pins.  They are used to output the PWM0 and
    // PWM1 signals.
    //
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinTypePWM(GPIO_PORTD_BASE, GPIO_PIN_1);

    //
    // Compute the PWM period based on the system clock.
    //
    ulPeriod = SysCtlClockGet() / 440;

    //
    // Set the PWM period to 440 (A) Hz.
    //
    PWMGenConfigure(PWM_BASE, PWM_GEN_0,
                    PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPeriod);

    //
    // Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%.
    //
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, ulPeriod / 4);
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, ulPeriod * 3 / 4);

    //
    // Enable the PWM0 and PWM1 output signals.
    //
    PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);

    //
    // Enable the PWM generator.
    //
    PWMGenEnable(PWM_BASE, PWM_GEN_0);

    //
    // Loop forever while the PWM signals are generated.
    //
    while(1)
    {
    }
}
我只把上面程序中的GPIOD改为GPIOE,结果PE1输出低电平,把PWM_OUT_1改为PWM_OUT_5也是低电平,(注:PE1对应的是pwm5),希望各位高手给小弟解答啊。我对这个程序不了解,拜托了,详细点

回复评论 (8)

回复 楼主 cylot 的帖子

把改过的程序也贴上来吧,这样才知道具体改哪里了
点赞  2011-4-8 17:07

回复 沙发 academic 的帖子

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "drivers/rit128x96x4.h"
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

//*****************************************************************************
//
// This example demonstrates how to setup the PWM block to generate signals.
//
//*****************************************************************************
int
main(void)
{
    unsigned long ulPeriod;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);
    SysCtlPWMClockSet(SYSCTL_PWMDIV_1);

    //
    // Initialize the OLED display.
    //
    RIT128x96x4Init(1000000);

    //
    // Clear the screen and tell the user what is happening.
    //
    RIT128x96x4StringDraw("Generating PWM", 18, 24, 15);
    RIT128x96x4StringDraw("on PF0 and PD1", 18, 32, 15);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Set GPIO F0 and D1 as PWM pins.  They are used to output the PWM0 and
    // PWM1 signals.
    //
    GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
    GPIOPinTypePWM(GPIO_PORTE_BASE, GPIO_PIN_1);

    //
    // Compute the PWM period based on the system clock.
    //
    ulPeriod = SysCtlClockGet() / 440;

    //
    // Set the PWM period to 440 (A) Hz.
    //
    PWMGenConfigure(PWM_BASE, PWM_GEN_0,
                    PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, ulPeriod);

    //
    // Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%.
    //
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, ulPeriod / 4);
    PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, ulPeriod * 3 / 4);

    //
    // Enable the PWM0 and PWM1 output signals.
    //
    PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);

    //
    // Enable the PWM generator.
    //
    PWMGenEnable(PWM_BASE, PWM_GEN_0);

    //
    // Loop forever while the PWM signals are generated.
    //
    while(1)
    {
    }
}
点赞  2011-4-8 17:14

回复 板凳 cylot 的帖子

PE1 对应的是 PWM5,你还从 PWM_OUT_1 输出是不对的,
PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, ulPeriod * 3 / 4);
不过,我不知道 PWM 发生器0 是不是可以输出到 PWM_OUT_5,你试一下,把  PWM_OUT_1 改成  PWM_OUT_5,看行不?
点赞  2011-4-8 18:00

回复 4楼 academic 的帖子

这个1改成5我改过了,我在1楼说过啦,还是不行的,pwm发生器0不能输出到PWM_OUT_5,感谢2楼的耐心解答,谢谢
点赞  2011-4-9 08:51

回复 5楼 cylot 的帖子

PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
这里改了没
点赞  2011-4-10 12:46

回复 6楼 academic 的帖子

因为pwm发生器0只能产生pwm0和pwm1,所以不能输出pwm5,我之前看datasheet不怎么会,非常感谢,现在可以了 感谢2楼
点赞  2011-4-10 17:10
引用: 原帖由 cylot 于 2011-4-10 17:10 发表
因为pwm发生器0只能产生pwm0和pwm1,所以不能输出pwm5,我之前看datasheet不怎么会,非常感谢,现在可以了 感谢2楼

也谢谢你的分享
加油!在电子行业默默贡献自己的力量!:)
点赞  2011-4-10 17:40
没经验,等着牛人解答,呵呵
点赞  2011-4-11 11:16
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复