是关于M0516BN的定时器1的外部捕获/复位功能不正常的问题。以下程序段是我从版本为M051SeriesBSP_CMSIS_v2.01.002的开发包中的SampleCode\Driver\TIMER工程里摘抄的。 /* Enable TIMER1 counter and capture function */
TIMER1->TCMPR = 0xFFFFFF;
TIMER1->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_IE_Msk | TIMER_TCSR_MODE_CONTINUOUS |TIMER_TCSR_CTB_ENABLE | TIMER_TCSR_TDR_EN_Msk | TIMER_TCSR_PRESCALE(1);
TIMER1->TEXCON = TIMER_TEXCON_MODE_CAP | TIMER_TEXCON_TEXIEN_ENABLE | TIMER_TEXCON_TEXEN_ENABLE;
这是对Timer1进行捕捉功能配置。
对TIMER1->TCSR寄存器配置时,TDR_EN位置1使能。
对TIMER1->TEXCON寄存器配置时,RSTCAPSEL位置0,选择捕捉功能。
硬件方面,我已将新唐提供的M052_TINY_EVB_V002上的芯片换位M0516LBN。将MCU的9脚和10脚短接起来。
运行程序,通过超级终端选择TIMER1的外部捕捉功能测试,按任意键启动测试后,超级终端打印出来的数据如下:
# TIMER Settings:
TIMER0: Clock source is 12 MHz; Toggle-Out mode and frequency is 500 Hz; Disable interrupt.
TIMER3: Clock source is 12 MHz; Toggle-Out mode and frequency is 1 Hz; Disable interrupt.
TIMER1: Clock source is HCLK(48 MHz); Periodic mode; Disable interrupt; Pre-scale 1; TCMP is 0xFFFFFF;
Counter pin enable; Capture pin enable;
# Generate 500 Hz frequency of T0 and connect T0 to T1 counter pin.
# Generate 1 Hz frequency of T3 and connect T3 to T1EX capture pin.
# Get 500 ccounts from T1 pin when each T1EX pin interrupt occurred.
Press any key to start test ...
[1]- 0
[2]- 0
[3]- 0
[4]- 0
[5]- 0
[6]- 0
[7]- 0
[8]- 0
[9]- 0
[10]- 0
[11]- 0
我用示波器测试过T0端口和T3端口,确认这两个端口输出的波形一个为1Hz,一个为500Hz。
之后我进行设断点仿真,观测到程序是可以进入TIMER1的中断服务程序中,而且寄存器TEXISR中的TEXIF位被置1。
void TMR1_IRQHandler(void)
{
if (_TIMER_GET_CMP_INT_FLAG(TIMER1) == 1)
{
/* Clear TIMER1 Timeout Interrupt Flag */
_TIMER_CLEAR_CMP_INT_FLAG(TIMER1);
}else
if (_TIMER_GET_CAP_INT_FLAG(TIMER1) == 1)
{
/* Clear TIMER1 Capture Interrupt Flag */
_TIMER_CLEAR_CAP_INT_FLAG(TIMER1);
}
g_au32TMRINTCount[1]++;
}
如果我将
TIMER1->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_IE_Msk | TIMER_TCSR_MODE_CONTINUOUS |
TIMER_TCSR_CTB_ENABLE
| TIMER_TCSR_TDR_EN_Msk | TIMER_TCSR_PRESCALE(1);
中橙色部份删除,即改为以下的语句
TIMER1->TCSR = TIMER_TCSR_CEN_Msk | TIMER_TCSR_IE_Msk | TIMER_TCSR_MODE_CONTINUOUS
| TIMER_TCSR_TDR_EN_Msk | TIMER_TCSR_PRESCALE(1);
对程序进行编译仿真。运行程序,通过超级终端选择TIMER1的外部捕捉功能测试,按任意键启动测试后,超级终端打印出来的数据如下:
# TIMER Settings:
TIMER0: Clock source is 12 MHz; Toggle-Out mode and frequency is 500 Hz; Disab
le interrupt.
TIMER3: Clock source is 12 MHz; Toggle-Out mode and frequency is 1 Hz; Disable
interrupt.
TIMER1: Clock source is HCLK(48 MHz); Periodic mode; Disable interrupt; Pre-sc
ale 1; TCMP is 0xFFFFFF;
Counter pin enable; Capture pin enable;
# Generate 500 Hz frequency of T0 and connect T0 to T1 counter pin.
# Generate 1 Hz frequency of T3 and connect T3 to T1EX capture pin.
# Get 500 ccounts from T1 pin when each T1EX pin interrupt occurred.
Press any key to start test ...
[1]- 99984
[2]- 199984
[3]- 299984
[4]- 399984
[5]- 499984
[6]- 599984
[7]- 699984
[8]- 799984
[9]- 899984
[10]- 999984
敲了这么多的字,实在不容易。请求各位大大,看看问题出在哪里。谢谢!
另外还有一个问题就是文件名为"DA00-M052_54_58_516SCA1.pdf"中,第242页和250页对TCAP0,TCAP1,TCAP2,TCAP3的R/W属性描述不一致,请问这四个定时器捕捉数据寄存器,用户是否可写在程序中清零?谢谢!
|