TI中文支持网
TI专业的中文技术问题搜集分享网站

TM4C1294NCPDT呼吸灯–求助

初学嵌入式开发,一个呼吸灯例程,大家帮忙看一下,谢谢!

#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pwm.h"
#include "driverlib/pin_map.h"
#include "inc/hw_gpio.h"

#define APP_PI           3.1415926535897932384626433832795f
#define PWM_FREQUENCY 100
#define STEPS         256

int main(void)
{
    volatile uint32_t ui32Load;
    volatile uint32_t ui32BlueLevel;
    volatile uint32_t ui32PWMClock;
    volatile uint32_t ui32SysClkFreq;
    volatile uint32_t ui32Index;
    float fAngle;
    uint8_t ui8PinData = 3;
    
    ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);
    
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
    
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_2 | GPIO_PIN_3);
    //GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2 | GPIO_PIN_3, 0x00);
    GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1, 0x02);
    
    PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_64);
    
    GPIOPinTypePWM(GPIO_PORTF_BASE, PWM_GEN_2 );
    
    ui32PWMClock = ui32SysClkFreq / 64;
    ui32Load = (ui32PWMClock / PWM_FREQUENCY) – 1;
    
    PWMGenConfigure(PWM0_BASE, PWM_GEN_2, PWM_GEN_MODE_DOWN);
    PWMGenPeriodSet(PWM0_BASE, PWM_GEN_2, ui32Load);
    
    PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, ui32Load/2);
    PWMGenEnable(PWM0_BASE, PWM_GEN_2);
    PWMOutputState(PWM0_BASE, (PWM_OUT_4_BIT ), 1);
    
    ui32Index = 0;
    
    
    while(1)
    {        fAngle = ui32Index * (2.0f * APP_PI/STEPS);
        ui32BlueLevel = (uint32_t) (9370.0f * (1 + sinf(fAngle)));
        PWMPulseWidthSet(PWM0_BASE, PWM_OUT_4, ui32BlueLevel);
        ui32Index++;
        if (ui32Index == (STEPS – 1))
        {
            ui32Index = 0;
        }
        SysCtlDelay(ui32SysClkFreq/STEPS);
    }
}

xyz549040622:

你还没说出你的问题呢?呼吸灯出什么问题了?

xiang liu3:

回复 xyz549040622:

编译烧写之后没反应啊,灯都不亮!!!

xyz549040622:

回复 xiang liu3:

给你个PWM程序对照看看,TM4对初始化要求很严格的,你好像有些顺序都颠倒了

//PWM实验程序解析
//头文件
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/fpu.h"
#include "driverlib/pin_map.h"int main (void)
{//使能FPUFPUEnable();FPULazyStackingEnable();//设置系统时钟为50MHzSysCtlClockSet(SYSCTL_SYSDIV_4 |SYSCTL_USE_PLL|SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);//使能PWM模块ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);//使能PWM2和PWM3输出所在GPIOROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);//配置PH0/PH1为PWM功能ROM_GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_0);ROM_GPIOPinTypePWM(GPIO_PORTH_BASE, GPIO_PIN_1);// PWM时钟配置:不分频ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1);//配置PWM发生器1:加减计数ROM_PWMGenConfigure(PWM_BASE,PWM_GEN_0,PWM_GEN_MODE_UP_DOWN| PWM_GEN_MODE_NO_SYNC);//设置PWM发生器1的周期ROM_PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, 6000);//设置PWM2/PWM3输出的脉冲宽度ROM_PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, 4200);ROM_PWMPulseWidthSet(PWM_BASE, PWM_OUT_1, 1800);//使能PWM2和PWM3的输出ROM_PWMOutputState(PWM_BASE, (PWM_OUT_0_BIT |PWM_OUT_1_BIT), true);//使能PWM发生器1ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0);while(1);{}
}

赞(0)
未经允许不得转载:TI中文支持网 » TM4C1294NCPDT呼吸灯–求助
分享到: 更多 (0)