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 输出不会变为零。

Guru**** 2465890 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1551032/tm4c123ae6pm-pwm-output-not-going-to-zero

器件型号:TM4C123AE6PM


工具/软件:

我有一个工作正常的 PWM 信号、但它不会变为 0、如果脉冲宽度设置为 0、则输出变为稳定高电平、而不是稳定低电平。  代码:

SysCtlPWMClockSet (SYSCTL_PWMDIV_64);                                       // 1250KHz PWM 时钟。

PWMGenConfigure (PWM0_BASE、PWM_GEN_0、PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);

PWMDeadBandDisable (PWM0_BASE、PWM_GEN_0);

PWMGenPeriodSet (PWM0_BASE、PWM_GEN_06250);                               // 200Hz 输出。

PWMPulseWidthSet (PWM0_BASE、PWM_GEN_0、0);                                 // 0%占空比。

PWMOutputUpdateMode (PWM0_BASE、PWM_OUT_0_BIT、PWM_OUTPUT_MODE_SYNC_LOCAL);

PWMGenEnable (PWM0_BASE、PWM_GEN_0);

PWMOutputState (PWM0_BASE、PWM_OUT_0_BIT、TRUE);

谢谢、Doug

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

    尊敬的 Doug:

     请参阅此帖子 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/5873743?tisearch=e2e-sitesearch&keymatch=0%2520duty%2520cycle%2520pwm#。 您需要 将其更改为 PWM_GEN_MODE_NO_SYNC、而不是 PWM_OUTPUT_MODE_SYNC_LOCAL。  

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

    尊敬的 Charles:

    我已经尝试过、不起作用。

    Doug

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

    有人可以在你离开的时候把这件事带走吗?

    谢谢

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

    尊敬的 Doug:

     我想在这条线中你报告了它是有效的。  

     您可以尝试以下代码片段吗、它与发布在该主题上的代码片段相同。 我能够让它正常工作。  

    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);
    
    
    }

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

    它是在 PWMGenConfigure() 上、而不是在 PWMOutputUpdateMode() 上、我发现我在 PWMPulseWidthSet() 上使用了不正确的参数、我使用的是 PWM_GEN_1、而不是 PWM_OUT_2。  在一切正常之前、除了在宽度 0、现在它总是高的、所以我不知道我做了什么、但我必须走一小段路、会找出我做了什么错误、当我回来。

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

    找到问题后、我将 PWM_OUT_X 与 PWM_OUT_X_BIT 混淆、但设置 0 宽度仍会导致稳定的高电平。  不想花更多的时间,我只是使用 PWMOutputState(x,x,false);关闭它。

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

    找到问题后、我将 PWM_OUT_X 与 PWM_OUT_X_BIT 混淆、但设置 0 宽度仍会导致稳定的高电平。  不想花更多的时间,我只是使用 PWMOutputState(x,x,false);关闭它。

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

    我们来把它调为闭合状态。