您好,
目前使用TM4C1231D5PZ做PWM输出,4路PWM同步,及反相都可以正常输出了,死区控制请问如何控制,此SDK 函数 PWMDeadBandEnable(uint32_t ui32Base, uint32_t ui32Gen,uint16_t ui16Rise, uint16_t ui16Fall);无法调用。
Susan Yang:
请您参考下下面的代码
//***************************************************************************** // // dead_band.c - Example demonstrating the dead-band generator. // // Copyright (c) 2010-2017 Texas Instruments Incorporated.All rights reserved. // Software License Agreement ////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. //// This is part of revision 2.1.4.178 of the Tiva Firmware Development Package. // //*****************************************************************************#include <stdbool.h> #include <stdint.h> #include "inc/hw_memmap.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/pwm.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h"//***************************************************************************** // //! \addtogroup pwm_examples_list //! <h1>PWM dead-band (dead_band)</h1> //! //! This example shows how to setup the PWM0 block with a dead-band generation. //! //! This example uses the following peripherals and I/O signals.You must //! review these and change as needed for your own board: //! - GPIO Port B peripheral (for PWM pins) //! - M0PWM0 - PB6 //! - M0PWM1 - PB7 //! //! The following UART signals are configured only for displaying console //! messages for this example.These are not required for operation of the //! PWM. //! - UART0 peripheral //! - GPIO Port A peripheral (for UART0 pins) //! - UART0RX - PA0 //! - UART0TX - PA1 //! //! This example uses the following interrupt handlers.To use this example //! in your own application you must add these interrupt handlers to your //! vector table. //! - None. // //*****************************************************************************//***************************************************************************** // // The variable g_ui32SysClock contains the system clock frequency // //***************************************************************************** #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2) uint32_t g_ui32SysClock; #endif//***************************************************************************** // // This function sets up UART0 to be used for a console to display information // as the example is running. // //***************************************************************************** void InitConsole(void) {//// Enable GPIO port A which is used for UART0 pins.// TODO: change this to whichever GPIO port you are using.//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//// Configure the pin muxing for UART0 functions on port A0 and A1.// This step is not necessary if your part does not support pin muxing.// TODO: change this to select the port/pin you are using.//GPIOPinConfigure(GPIO_PA0_U0RX);GPIOPinConfigure(GPIO_PA1_U0TX);//// Enable UART0 so that we can configure the clock.//SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);//// Use the internal 16MHz oscillator as the UART clock source.//UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);//// Select the alternate (UART) function for these pins.// TODO: change this to select the port/pin you are using.//GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);//// Initialize the UART for console I/O.//UARTStdioConfig(0, 115200, 16000000); }//***************************************************************************** // // Prints out 5x "." with a second delay after each print.This function will // then backspace, clearing the previously printed dots, and then backspace // again so you can continuously printout on the same line.The purpose of // this function is to indicate to the user that the program is running. // //***************************************************************************** void PrintRunningDots(void) {UARTprintf(". "); #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)SysCtlDelay(g_ui32SysClock / 3); #elseSysCtlDelay(SysCtlClockGet() / 3); #endifUARTprintf(". "); #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)SysCtlDelay(g_ui32SysClock / 3); #elseSysCtlDelay(SysCtlClockGet() / 3); #endifUARTprintf(". "); #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)SysCtlDelay(g_ui32SysClock / 3); #elseSysCtlDelay(SysCtlClockGet() / 3); #endifUARTprintf(". "); #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)SysCtlDelay(g_ui32SysClock / 3); #elseSysCtlDelay(SysCtlClockGet() / 3); #endifUARTprintf(". "); #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)SysCtlDelay(g_ui32SysClock / 3); #elseSysCtlDelay(SysCtlClockGet() / 3); #endifUARTprintf("\b\b\b\b\b\b\b\b\b\b");UARTprintf("");UARTprintf("\b\b\b\b\b\b\b\b\b\b"); #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)SysCtlDelay(g_ui32SysClock / 3); #elseSysCtlDelay(SysCtlClockGet() / 3); #endif }//***************************************************************************** // // Configure the PWM0 block with dead-band generation.The example configures // the PWM0 block to generate a 25% duty cycle signal on PD0 with dead-band // generation.This will produce a complement of PD0 on PD1 (75% duty cycle). // The dead-band generator is set to have a 10us or 160 cycle delay // (160cycles / 16Mhz = 10us) on the rising and falling edges of the PD0 PWM // signal. // //***************************************************************************** int main(void) {//// Set the clocking to run directly from the external crystal/oscillator.// TODO: The SYSCTL_XTAL_ value must be changed to match the value of the// crystal on your board.// #if defined(TARGET_IS_TM4C129_RA0) ||\defined(TARGET_IS_TM4C129_RA1) ||\defined(TARGET_IS_TM4C129_RA2)g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |SYSCTL_OSC_MAIN |SYSCTL_USE_OSC), 25000000); #elseSysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ); #endif//// Set the PWM clock to the system clock.//SysCtlPWMClockSet(SYSCTL_PWMDIV_1);//// Set up the serial console to use for displaying messages.This is just// for this example program and is not needed for PWM operation.//InitConsole();//// Display the setup on the console.//UARTprintf("PWM ->\n");UARTprintf("Module: PWM0\n");UARTprintf("Pin(s): PD0 and PD1\n");UARTprintf("Features: Dead-band Generation\n");UARTprintf("Duty Cycle: 25%% on PD0 and 75%% on PD1\n");UARTprintf("Dead-band Length: 160 cycles on rising and falling edges\n\n");UARTprintf("Generating PWM on PWM0 (PD0) -> ");//// The PWM peripheral must be enabled for use.//SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);//// For this example PWM0 is used with PortB Pins 6 and 7.The actual port// and pins used may be different on your part, consult the data sheet for// more information.GPIO port B needs to be enabled so these pins can be// used.// TODO: change this to whichever GPIO port you are using.//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);//// Configure the GPIO pin muxing to select PWM functions for these pins.// This step selects which alternate function is available for these pins.// This is necessary if your part supports GPIO pin function muxing.// Consult the data sheet to see which functions are allocated per pin.// TODO: change this to select the port/pin you are using.//GPIOPinConfigure(GPIO_PB6_M0PWM0);GPIOPinConfigure(GPIO_PB7_M0PWM1);//// Configure the GPIO pad for PWM function on pins PB6 and PB7.Consult// the data sheet to see which functions are allocated per pin.// TODO: change this to select the port/pin you are using.//GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);//// Configure the PWM0 to count up/down without synchronization.// Note: Enabling the dead-band generator automatically couples the 2// outputs from the PWM block so we don't use the PWM synchronization.//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.// In this case you get: (1 / 250Hz) * 16MHz = 64000 cycles.Note that// the maximum period you can set is 2^16 - 1.// TODO: modify this calculation to use the clock frequency that you are// using.//PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 64000);//// Set PWM0 PD0 to a duty cycle of 25%.You set the duty cycle as a// function of the period.Since the period was set above, you can use the// PWMGenPeriodGet() function.For this example the PWM will be high for// 25% of the time or 16000 clock cycles (64000 / 4).//PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 4);//// Enable the dead-band generation on the PWM0 output signal.PWM bit 0// (PD0), will have a duty cycle of 25% (set above) and PWM bit 1 will have// a duty cycle of 75%.These signals will have a 10us gap between the// rising and falling edges.This means that before PWM bit 1 goes high,// PWM bit 0 has been low for at LEAST 160 cycles (or 10us) and the same// before PWM bit 0 goes high.The dead-band generator lets you specify// the width of the "dead-band" delay, in PWM clock cycles, before the PWM// signal goes high and after the PWM signal falls.For this example we// will use 160 cycles (or 10us) on both the rising and falling edges of// PD0.Reference the datasheet for more information on dead-band// generation.//PWMDeadBandEnable(PWM0_BASE, PWM_GEN_0, 160, 160);//// Enable the PWM0 Bit 0 (PD0) and Bit 1 (PD1) output signals.//PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT | PWM_OUT_0_BIT, true);//// Enables the counter for a PWM generator block.//PWMGenEnable(PWM0_BASE, PWM_GEN_0);//// Loop forever while the PWM signals are generated.//while(1){//// Print out indication on the console that the program is running.//PrintRunningDots();} }
Susan Yang:
“无法调用”
能稍微详细描述一下吗?谢谢