MC9S12XEP100 Cycle counter

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MC9S12XEP100 Cycle counter

ソリューションへジャンプ
1,675件の閲覧回数
spietari
Contributor I

Hello,

 

I'd like to implement a ten-millisecond counter on my MCU so that the cycle count representing ten milliseconds could be arbitrary. I need this to account for inaccuracies in the internal clock frequency.

 

For example my bus frequency is 36.864.000Hz and each 10ms period would be represented by 368.640 cycles. I get a reference time from a GPS module and I'd like to change this cycle count accordingly.

 

My problem is I don't know how to build a timer mechanism that would fire every n cycles, where n can be over 65536. I've tried to use PIT but it needs the timeout to be n * m cycles so a cycle count that is e.g. a prime number cannot be used and the resolution in general would be the minimum of n and m.

 

Using ECT this could be achieved by dynamically adjusting the compare register with the modulus of the desired cycle count but it seems inaccurate and inelegant.

 

Kind regards,

Seppo

ラベル(1)
0 件の賞賛
返信
1 解決策
769件の閲覧回数
kef
Specialist I

Is ECT not accurate? How? Do you mean you are going to prescale ECT clock? Just use least 1:1 prescaler and you won't lose accuracy or ECT resolution. Arbitrary timeout periods can be both generated and measured using ECT. Resolution and accuracy is as good as bus clock.

 

isr_10ms()

{

static short ect_overflow_counter;

 

   if(ect_overflow_counter)

   {

      ect_overflow_counter--;

   }

   else

   {

      ect_overflow_counter = 368640L / 65536;

      TCx += 368640L % 65536;

 

      increment_10ms_counter();

   }

   clear_TCx_flag();

}

 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
770件の閲覧回数
kef
Specialist I

Is ECT not accurate? How? Do you mean you are going to prescale ECT clock? Just use least 1:1 prescaler and you won't lose accuracy or ECT resolution. Arbitrary timeout periods can be both generated and measured using ECT. Resolution and accuracy is as good as bus clock.

 

isr_10ms()

{

static short ect_overflow_counter;

 

   if(ect_overflow_counter)

   {

      ect_overflow_counter--;

   }

   else

   {

      ect_overflow_counter = 368640L / 65536;

      TCx += 368640L % 65536;

 

      increment_10ms_counter();

   }

   clear_TCx_flag();

}

 

0 件の賞賛
返信
769件の閲覧回数
spietari
Contributor I

Perfect.

 

Thank you!

 

 

0 件の賞賛
返信