智能车制作
标题:
关于KL46 TPM模块,程序进不了MOD溢出中断
[打印本页]
作者:
折夜
时间:
2015-2-7 23:09
标题:
关于KL46 TPM模块,程序进不了MOD溢出中断
参考了KL25写了KL46的TPM模块,可是发现进不了MOD溢出中断的问题,检查了代码没发现问题,大神帮忙看看哈
关键代码如下:
void SIM_Init(void)
{
SIM_SOPT2 |= SIM_SOPT2_TPMSRC(1);
SIM_SOPT2 &= ~SIM_SOPT2_PLLFLLSEL_MASK; //FLLCLOCK 为TPM时钟 48MHz
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTC_MASK;
SIM_SCGC6 |= SIM_SCGC6_TPM0_MASK | SIM_SCGC6_TPM1_MASK;
}//ATL3 PTA12 ->TPM1_CH0 PTA13 ->TPM1_CH1 //ATL3 PTC2 ->TPM0_CH1 PTC3 ->TPM0_CH2
void PORT_Init(void)
{
PORTA_PCR12 |= PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x3) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
PORTA_PCR13 |= PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x3) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
GPIOA_PDDR &= ~(3<<12); //上拉输入
PORTC_PCR2 |= PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x3) | PORT_PCR_DSE_MASK;
PORTC_PCR2 &= ~PORT_PCR_PE_MASK; //推挽输出
PORTC_PCR3 |= PORT_PCR_ISF_MASK | PORT_PCR_MUX(0x3) | PORT_PCR_DSE_MASK;
PORTC_PCR3 &= ~PORT_PCR_PE_MASK;
GPIOC_PDDR |= (3<<2);
}void TPM0_Init(void)
{
enable_irq(17);set_irq_priority(17,2);
TPM0_CNT = 0;
TPM0_MOD = 0x12C0;
TPM0_SC |= TPM_SC_TOF_MASK | TPM_SC_TOIE_MASK | TPM_SC_CMOD(1);
TPM0_C1SC |= TPM_CnSC_MSB_MASK | TPM_CnSC_ELSB_MASK; //先高后低
TPM0_C1V = 0;
TPM0_C2SC |= TPM_CnSC_MSB_MASK | TPM_CnSC_ELSA_MASK; //先低后高
TPM0_C2V = 0;
}void TPM1_Init(void)
{
enable_irq(18);set_irq_priority(18,1);
TPM1_CONF |= TPM_CONF_TRGSEL(8) | TPM_CONF_CSOO_MASK | TPM_CONF_CSOT_MASK;
TPM1_CNT = 0;
TPM1_MOD = 14400;
TPM1_SC |= TPM_SC_TOF_MASK | TPM_SC_TOIE_MASK | TPM_SC_CMOD(1);
TPM1_C0SC |= TPM_CnSC_ELSA_MASK | TPM_CnSC_CHIE_MASK | TPM_CnSC_CHF_MASK; //上升沿捕获(周期)
TPM1_C0V = 0;
TPM1_C1SC |= TPM_CnSC_ELSB_MASK | TPM_CnSC_CHIE_MASK | TPM_CnSC_CHF_MASK; //下降沿捕获(占空比)
TPM1_C1V = 0;
}void TPM0_isrv(void)
{
TPM0_SC |= TPM_SC_TOF_MASK;
TPM0_C1V = Input_Period;
TPM0_C2V = Input_Duty;
}void TPM1_isrv(void)
{
TPM1_SC |= TPM_SC_TOF_MASK;
Capture_Period = (uint16)TPM1_C0V;
Capture_Duty = (uint16)TPM1_C1V;
TPM1_C1SC |= TPM_CnSC_CHF_MASK;
if(TPM_STATUS_CH0F_MASK)
{
TPM1_C0SC |= TPM_CnSC_CHF_MASK;
Capture_Duty = Capture_Duty*100/Capture_Period;
LCD_write_english_string(4,0,"So_p");
LCD_Write_Num(4,30,48000000/Capture_Period);
LCD_write_english_string(2,65,"Hz");
LCD_write_english_string(3,0,"Si_D %");
LCD_Write_Num(5,30,Capture_Duty/48);
}
}
复制代码
isr.h文件也写了
断点设在TPM0_isrv()函数中,发现一直到不了断点
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2