主题:关于ETR100的定时器 共有51853人关注过本帖 |
---|
百步笑五十步 |
1楼 |
![]() |
关于ETR100的定时器 ![]()
在ISRDemo中,安装完IRQ11后,通过NB_Delay(500)来检查500毫秒内IRQ11的中断次数,发现无论SetTMR2函数中参数为什么,中断次数都为4835,为什么?检查过程如下
cnt1 = IRQ11cnt; NB_Delay(500); cnt2 = IRQ11cnt; if( cnt2 > cnt1 )    cnt3 = cnt2-cnt1; else    cnt3 = 65536+cnt2-cnt1; printf( "num is %u", cnt3 ); |
单帖管理 | 引用 | 回复 ![]() |
x10 |
2楼 |
![]() |
![]()
我测试了,是正常的呀。对unsigned int你上面的cnt3计算有误。
我把我测试的代码贴在下面,供参考: #include <stdio.h> #include <stdlib.h> #include <conio.h> #include "etr100.h" #include "isr.h" #define   TMR2 0x42 #define   TMRCTRL 0x43 #define   IRQ11 0x73 int main( int argc, char** argv ) {    int i;    unsigned int cnt1, cnt2;    printf( "ETR100 TMR2 DEMO\n" );    /*//////////////////////////////////////////////////    // (0) timer2<|>s input clock = 1.14MHz    // (1) generate 10ms square wave output    // (2) timer2<|>s output is pending to IRQ11    //////////////////////////////////////////////////*/    if( argc > 1 ) i = atoi( argv[1] );    else           i = 10;    if( i <= 0 )   i = 10;    SetTMR2( 1140*i );    // clearup keyboard buffer    while( kbhit( ) )  { getch( ); }    // install interrupt service routines    i = InstallISR( IRQ11 );    for(  )       {       cnt1 = IRQ11cnt;       NB_Delay( 1000 );       cnt2 = IRQ11cnt;       if( cnt2 >= cnt1 )  {  printf( "diff=%u\r", cnt2-cnt1 );  }       else  {  printf( "diff=%u\r", 65536 - (cnt1-cnt2) );  }       /*       if( (cnt11 != IRQ11cnt) )  {  printf( "I11=%u\r", IRQ11cnt );  cnt11 = IRQ11cnt;  }       */       if( kbhit( ) ) { getch( ); break; }       }    i = UninstallISR( IRQ11 );    return 0; } |
单帖管理 | 引用 | 回复 ![]() |
百步笑五十步 |
3楼 |
![]() |
![]()
收到,谢谢
|
单帖管理 | 引用 | 回复 ![]() |
百步笑五十步 |
4楼 |
![]() |
![]()
我用你的程序测试了,我取i=5,10,20,diff的值始终是8768左右,不随i变化,和以前的一样
|
单帖管理 | 引用 | 回复 ![]() |
x10 |
5楼 |
![]() |
![]()
这就怪了,建议把板子寄回,我们来检查,如果有问题,会立即给你寄一片好的给你。
|
单帖管理 | 引用 | 回复 ![]() |