This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

【求助】关于TM4C123GH6PM的Timer0定时时间的计算。



系统时钟和Timer0的配置如下  不知道上面的计算对不对的。这样的话的ui32Period的值是多少啊,定时器溢出一次是定时了多长时间啊?感觉不会算了。虚心求教啊。

    1. #include <stdint.h>  
    2. #include <stdbool.h>  
    3. #include <stdio.h>  
    4. #include "inc/hw_memmap.h"  
    5. #include "inc/hw_types.h"  
    6. #include "inc/hw_gpio.h"  
    7. #include "inc/hw_nvic.h"  
    8. #include "inc/hw_ints.h"  
    9. #include "driverlib/debug.h"  
    10. #include "driverlib/gpio.h"  
    11. #include "driverlib/pin_map.h"  
    12. #include "driverlib/sysctl.h"  
    13. #include "driverlib/interrupt.h"  
    14. #include "driverlib/timer.h"  
    15. #include "utils/uartstdio.h"  
    16.   
    17. void Timer0B_Int_Handler();  
    18. int main(void)  
    19. {  
    20.         //system config  
    21.     SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL  
    22.                       |SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);  
    23.   
    24.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);  
    25.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);  
    26.     SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);  
    27.     SysCtlDelay(200);//配置完系统寄存器后要延时一段时间  
    28.   
    29.         //GPIO config  
    30.     GPIOPinConfigure(GPIO_PB7_T0CCP1);  
    31.     GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_7);  
    32.   
    33.         //Timer config  
    34.     TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_CAP_TIME_UP);  
    35.     TimerControlEvent(TIMER0_BASE, TIMER_B, TIMER_EVENT_POS_EDGE);  
    36.       
    37.         //Int config  
    38.     IntEnable(INT_TIMER0B);  
    39.     TimerIntEnable(TIMER0_BASE, TIMER_CAPB_EVENT);  
    40.     IntMasterEnable();  
    41.     TimerEnable(TIMER0_BASE, TIMER_B);  
    42.   
    43.         while(1);  
    44. }  
    45. void Timer0B_Int_Handler()  
    46. {  
    47.     TimerIntClear(TIMER0_BASE, TIMER_CAPB_EVENT);  
    48. }  
    49. 在PB7上接入高电平,就可以检测到上升沿进入中单咯~  
    50. 要特别注意的:  
    51. _要记得在中断向量表(startup_ccs.c)中先声明中断处理函数(extern Timer0B_Int_Handler();),  
    52. 并将对应的中断的中断处理函数(IntDefaultHandler)替换为自己写的函数名。  
  • 应该是50/10/2吧,或者你翻转下IO,量下波形就知道了

  • SysCtlClockGet(void) 是返回的系统 processor clock, 不是 PLL 时钟, 看你的系统设置应该是 50MHz.

  • 代码注释写得很清楚了,一处频率是10Mhz,也就是溢出一次的时间为0.1ms