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.

Hercules的定时器问题,如何获得一个10mS间隔的计数器

Other Parts Discussed in Thread: HALCOGEN

设计中需要用一个计数器作为软件计时器的标准,要求每隔10mS计数器增加一次,提供给软件计时器做基准。 我看规格书文档号:spn517里12.2.1节关于RTI计数器的说明, 是不是可以这样: RTIUCx 赋一个合适的值,使经过10mS能够增加到这个值,从而RTIFRCx即为10mS的次数。 应用程序中即可使用RTIFRCx的值,作为计数器基准。 请大家帮忙看看,这样是否可行,或者有没有什么更好的方法实现此功能。

  • Hi Wei,

        不是很懂您的问题。

        是要用RTI来做一个10ms间隔的中断吗?

        如果是的话,不妨直接使用HALCoGen来配置。

        原理是给RTI一个远小于10ms的时钟基础(为了提高分辨率),比如10MHz时钟,那么RTI就会在这个时钟基础上进行计数,每记一次RTIUCx都会加1。

        直到RTIUCx溢出(一般不会让这种情况发生)或RTIUCx的值等于RTICPUCx的值时,就可以产生一个中断信号。

        以上面例子来算,10MHz产生10ms间隔时间,RTICPUCx的值应该是100(0x64)。

      

        使用HALCoGen的话就方便很多了,只需要在Interval这里写入10ms即可。其他的计算HALCoGen都自动做了。

        如图:

        

        这里有个RTI的例子,请查收。

        

  • 规格书spnu517中是这么写的

    12.2.1 Counter Operation
    Each counter block consists of the following (see Figure 12-2):
    • One 32-bit prescale counter (RTIUC0 or RTIUC1)
    • One 32-bit free running counter (RTIFRC0 or RTIFRC1)
    The RTIUC0/1 is driven by the RTICLK and counts up until the compare value in the compare up counter
    register (RTICPUC0 or RTICPUC1) is reached. When the compare matches, RTIFRC0/1 is incremented
    and RTIUC0/1 is reset to 0. If RTIFRC0/1 overflows, an interrupt is generated to the vectored interrupt
    manager (VIM).

    我的意思是,RTIUCPUC0设置一个比较的值,让RTIUC0从0增加,当增加到等于RTIUCPUC0设置的值时(根据RTI的时钟源,使RTIUC0从0增加到RTIUCPUC0的值时间为10mS),此时,RTIFRC0为10mS间隔的次数,RTIUC0又会复位到零,再计数。而RTIFRC0的值不就是10mS的间隔次数么?

  • Hi Wei,

        没错,您的理解是正确的。

        不过这么使用的时候需要注意的是,如果用户要预设RTIFRC0计数器的值,那么要先在RTIGCTRL寄存器中把整个计数模块停掉。

        The counter can be preset by writing (in privileged mode only) to this register. The counter
        increments then from this written value upwards.
        Note: If counters must be preset, they must be disabled in the RTIGCTRL register to
        ensure consistency between RTIUC0 and RTIFRC0.

  • TI的IAR关于hercules关于rti的示例非常晦涩复杂,能帮忙在附件中提供需要的函数么?谢谢

    Hercules_IAR工程及问题描述.rar
  • 菜鸟想问一下,主函数怎么调用