Sep 252010
 

I figured out how to let a 16 bit timer of the H8/3069R (that’s the CPU on that board) run in free counting mode which is useful for timing. It runs at 20MHz/8=2.5MHz which reaches 25000 in 10ms. Turns out that a loop like:


for (i=0; i<10000; ++i) { _nop(); };

takes quite exactly 10ms. That would be 20 clock cycles per loop which sounds about right.

Anyway, what I did is:

  • Run above loop and check the counter: 25010 was the counter in the timer register
  • Run above code with 1k interrupt/s: 25392 was the result
  • Run above code with 1k interrupt/s and stack in internal RAM: 25332
  • Run it again with 10k interrupt/s: 29487
  • Run it again with 10k interrupt/s and stack in internal RAM: 28687

What does that mean: The CPU slows down due to interrupts about 1.5% if it has 1k interrupt/s and about 18% for 10k interrupt/s (resp. 1.3% and 14% if the stack is in the faster internal 16 bit RAM).

Compare this with the LPC2148 where it slows down only about 3.4% at 10k interrupt/s. Quite a difference. Given the age of the H8 CPU though, I think it's reasonable enough. Also note that the 2MB memory is connected via an 8 bit memory bus compared to the 32 bit internal FLASH/RAM bus of the LPC2148.

Here the code to initialize the 16 bit timer into free running mode:

void Init_Timer16_0(void)
{
  T16TCNT0=1;
  GRA0=0xFFFF;
  T16TCR0=0x23; // Clear on Match GRA, internal clock: phi/8
  TISRA=0; // No interrupts
  TMDR=0; // No PWM mode
  TSNC=0; // All independant
  TSTR=1; // Start Timer 0
}