0

I try to calculate number of instruction cycles and delay cycles for HCS12. I have some information about HCS12

The HCS12 uses the bus clock (E clock) as a timing reference.

  • The frequency of the E clock is half of that of the onboard clock oscillator (clock, 48 MHz, E-clock, 24 MHz).
  • Execution times of the instructions are also measured in E clock cycles

  • I wonder the 24Mhz is crystal frequency? If so, only half of the crystal’s oscillator frequency is used for CPU instruction time. So, should it be halved?

  • How can I make 100-ms time delay for a demo board with a 24-MHz bus clock?

In order to create a 100-ms time delay, we need to repeat the preceding instruction sequence 60,000 times [100 ms ÷ (40 ÷ 24,000,000) μs = 60,000]. The following instruction sequence will create the desired delay: There is an example but I don't understand how 60000 and 40 values are calculated.

           ldx #60000       
loop       psha              ; 2 E cycles
           pula              ; 3 E cycles
           psha              ; 2 E cycles
           pula              ; 3 E cycles
           psha              ; 2 E cycles
           pula              ; 3 E cycles
           psha              ; 2 E cycles
           pula              ; 3 E cycles
           psha              ; 2 E cycles
           pula              ; 3 E cycles
           psha              ; 2 E cycles
           pula              ; 3 E cycles
           psha              ; 2 E cycles
           pula              ; 3 E cycles
           nop               ; 2 E cycles
           nop               ; 3 E cycles
           dbne x,loop
4

1 回答 1

1

您的第一部分解释了如果内部振荡器(或外部晶振)为 48 MHz,则 EClock 为 24 MHz。所以如果要延迟 100 毫秒,也就是 24,000,000 * 100 / 1,000 个 EClock,即 2,400,000 个指令周期。

可用的最大寄存器大小为 16 位,因此选择的循环计数器值 <= 65535。

方便地,60,000 是 2,400,000 的因数,即 60,000 * 40。因此,内部循环被设计为需要 40 个循环。但是最后 3 行的时间注释不正确,它们应该是

nop               ; 1 E cycle
nop               ; 1 E cycle
dbne x,loop       ; 3 E cycles

提供所需的 40 个周期执行时间。

注意,如果你有中断,其他进程,这种硬编码的方法不是很准确,用定时器中断会更好。

于 2016-03-22T12:32:49.753 回答