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.

tivaC系列芯片定时器计数周期如何计算,另,UART模块连续发送数据时,各帧(字节)之间的间隔时间通常是多少?

Other Parts Discussed in Thread: TM4C123GH6PM

最近在参考freemodbus源码做tivaC系列tm4c123gh6pm芯片的modbus通信协议移植,因为需要计算通信的超时时间,所以产生标题中提到的两个问题:

1:tivaC系列芯片的timer是按照振荡周期计数还是按照机器周期计数?(查阅网上部分51单片机资料提到51系列好像是按照机器周期计数,与振荡周期的比值为1/12,不知道tiva系列定时器的周期如何计算?)

2:按照freemodbus源码中给出的计算公式,超时判断的时间值为传输3.5个bit所需要的时间,因此想知道UART在连续发送数据时,各帧(字节)之间时间间隔大致为多少,如此设置是否合理?

还请不吝赐教,谢谢。

freemodbus源代码如下:

        /* If baudrate > 19200 then we should use the fixed timer values
         * t35 = 1750us. Otherwise t35 must be 3.5 times the character time.
         */
        if( ulBaudRate > 19200 )
        {
            usTimerT35_50us = 35;       /* 1800us. */
        }
        else
        {
            /* The timer reload value for a character is given by:
             *
             * ChTimeValue = Ticks_per_1s / ( Baudrate / 11 )
             *             = 11 * Ticks_per_1s / Baudrate
             *             = 220000 / Baudrate
             * The reload for t3.5 is 1.5 times this value and similary
             * for t3.5.
             */
            usTimerT35_50us = ( 7UL * 220000UL ) / ( 2UL * ulBaudRate );

  • 51和ARM是不同的,ARM中的指令是不能那么算的。以M3为例,cortex-m3是三级流水线,同时执行3条指令,指令周期不定,分支指令也可能清空流水线,导致预先执行的指令失效。ARM官方的数字是1.25MIPS/MHz,大概就是每个周期平均执行1.25条指令。大概指令的执行时间可以用keil跟踪得到。

  • 对于第二个问题,由于这个建个时间很短。代码执行时间应该都超过这个时间了,我认为应该不用考虑,可以连续发送的,你可以看看。连续发送前判断上一次返回的状态即可。

  • 谢谢您的回答,请问timer的计数周期应该按照指令执行时间计算?还是直接按照分频值计算呢?

  • 计数周期肯定是按照定时器加载的值计算的。

  • 提问者问的是定时器计数一下用的时间怎么计算

  • Hi Pengyang lan, i don't know chinese so please forgive me, I'm also working with freemodbus and the uc TM4C123, in order to calculate the counts that the timer needs i use the next code:

    porttimer.c


    USHORT usMBMulDiv(USHORT a, USHORT b, USHORT c){
    	ULONG x;
    	x = a;
    	x *= b;
    	x /= c;
    return ( USHORT ) x;
    }
    
    //the time argument usTim1Timerout50us is in multiples of 50us
    //so in order to calculate the timer ticks use the function usMBMulDiv 
    BOOL
    xMBPortTimersInit( USHORT usTim1Timerout50us )
    {
    
      ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
      ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT);//Full width 32bits and for freemodmus requirements Timer needs to be one-shot
    //
        // specifies the interrupt to be enabled
    //
    usDelta = usMBMulDiv(usTim1Timerout50us, 800, 100);
    ROM_IntMasterEnable();//enable all processor int
      ROM_IntEnable(INT_TIMER0A);//inc/hw_ints.h header defines
      ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);//select timer source// TIMEOUT interrupt
    //Define number to load in register  
        return TRUE;
    }
    

    What i did was calculate the Ticks to reach 50us --> 16Mhz/20Khz = 800 then just multiplied and divide by 100 

    i'm using TivaWare for the peripheral libraries and the IDE IAR 8.0 maybe we can help each other because i'm still working on this here is one post in TI E2E forum http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/598083/2199548#2199548