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.

[参考译文] TM4C123AE6PM:PWM 信号不会变为 0

Guru**** 2378650 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1527354/tm4c123ae6pm-pwm-signal-not-going-to-0

器件型号:TM4C123AE6PM

工具/软件:

正向 PWM 信号;当我将“脉冲宽度“设置为 0 时、它不是 0、而是稳定在 100%高电平。  我已经尝试了 PWMGenDisable ()、PWMOutputState () 和 PWMOutputInvert () 的各种组合,没有运气。  任何建议(除了在每个 PWM 输出端添加与门之外)。

谢谢、

Doug

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Doug:

     我尝试了以下代码、并生成 0%占空比的 PWM、引脚始终为低电平。  

    int
    main(void)
    {
        //
        // Set the clocking to run directly from the external crystal/oscillator.
        //
        MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ);
    
        //
        // Set the PWM clock to the system clock.
        //
        MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
    
        //
        // Initialize the UART.
        //
        ConfigureUART();
    
        //
        // Display the setup on the console.
        //
        UARTprintf("PWM ->\n");
        UARTprintf("  Module: PWM0\n");
        UARTprintf("  Pin: PB6\n");
        UARTprintf("  Configured Duty Cycle: 25%%\n");
        UARTprintf("  Inverted Duty Cycle: 75%%\n");
        UARTprintf("  Features: PWM output inversion every 2 seconds.\n\n");
        UARTprintf("Generating PWM on PWM0 (PB6) -> State = ");
    
        //
        // The PWM peripheral must be enabled for use.
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    
        //
        // Enable the GPIO port that is used for the PWM output.
        //
        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    
        //
        // Configure the PWM function for this pin.
        //
        MAP_GPIOPinConfigure(GPIO_PB6_M0PWM0);
        MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
    
        //
        // Configure PWM0 to count up/down without synchronization.
        //
        MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN |
                            PWM_GEN_MODE_NO_SYNC);
    
        //
        // Set the PWM period to 250Hz.  To calculate the appropriate parameter
        // use the following equation: N = (1 / f) * SysClk.  Where N is the
        // function parameter, f is the desired frequency, and SysClk is the
        // system clock frequency.
        //
        MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, (SysCtlClockGet() / 250));
    
        //
        // Set PWM0 to a duty cycle of 0%.
        //
        MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,
                             0);
    
        //
        // Enable PWM Out Bit 0 (PB6) output signal.
        //
        MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
    
        //
        // Enable the PWM generator block.
        //
        MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0);
    
        while (1);
    
    
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    很好。  问题是我将其配置为 PWM_GEN_MODE_LOCAL_SYNC、但当我将其更改为 PWM_GEN_MODE_NO_SYNC 时便可以正常工作。

    谢谢