最近在调试100时遇到PWM与定时器只能使用一个的问题,两个外设同时用在调试是程序就会卡死
代码如下:基本使用的都是官方的库函数,请大家帮我看看问题出在什么地方
#include "nano1xx.h"
//#include <stdio.h>
#include "nano1xx_gpio.h"
#include "nano1xx_pwm.h"
#include "nano1xx_timer.h"
void GPIOInit(void);
void TimerInit(void);
void PWMInit(uint8_t pwmch);
void delay(uint16_t cnt);
int32_t main()
{
SystemInit();
GPIOInit();
PWMInit(0);
TimerInit();
TIMER_Start(TIMER1);
PWM_Enable(0);
while(1)
{
GPIO_ClrBit(GPIOB,10);
}
}
void GPIOInit(void)
{
GPIO_Open(GPIOB, GPIO_PMD_PMD10_OUTPUT, GPIO_PMD_PMD10_MASK);
}
void PWMInit(uint8_t pwmch)
{
S_DRVPWM_TIME_DATA_T PWMcfg;
GCR->PA_H_MFP = (GCR->PA_H_MFP & ~(PA12_MFP_MASK | PA13_MFP_MASK)) |
PA12_MFP_PWM0_CH0 | PA13_MFP_PWM0_CH1;
GPIO_Open(GPIOA, GPIO_PMD_PMD12_OUTPUT|GPIO_PMD_PMD13_OUTPUT, GPIO_PMD_PMD12_MASK|GPIO_PMD_PMD13_MASK);
PWM_Init(pwmch);
PWMcfg.u8Mode = PWM_CTL_CHMOD_AUTO_RELOAD;
PWMcfg.u8PreScale = 1; // actually 1 + 1
PWMcfg.u8Div = PWM_CLKSEL_CLKSEL_DIV1;
PWMcfg.u32Cn = 6000000 / 500 - 1; //set FREQ
PWMcfg.u16Cm = (PWMcfg.u32Cn / 10)*3; //set PWM_DUTY
PWMcfg.u8Inv = 0;
PWM_SetClk(pwmch, &PWMcfg);
PWM_ConfigOutput(0, 1);
PWM_EnableInt(0);
}
void TimerInit()
{
// TIMER_Init(TIMER0, 11, 10000, TIMER_CTL_MODESEL_PERIODIC);
TIMER_Init(TIMER1, 11, 10000, TIMER_CTL_MODESEL_PERIODIC);
// TIMER_EnableInt(TIMER0, TIMER_IER_TMRIE);
TIMER_EnableInt(TIMER1, TIMER_IER_TMRIE);
}
void delay(uint16_t cnt)
{
uint16_t i;
for(i = 0;i < cnt;i++);
}
|