timerinit();while(1){variable1=TCNT;  //save the TimerCounterRegister TCNT in variable1variable2=TCNT;  //...}The Timer has a resolution of 1µs. Now the problem: in the first cycle of the loop the difference between variable1 and variable2 is 6µs. from the second cycle the difference is only 1µs or 0µs. the reason of 0 is probably that the resolution is to big. But why 6µs in the first cycle? Do you have any idea? Thank you!
--
Alban Edit: Please always include FSL Part Number in Message Subject line.
Read anytime.
Write has no meaning or effect in the normal mode; only writable in special modes (SMODN = 0). The period of the first count after a write to the TCNT registers may be a different size because the write is not synchronized with the prescaler clock."
#include "stdlib.h"#include "stdio.h"#include "912d128.h"#include "sci.h"volatile int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23;void main(){ // Timer Setup TSCR   = 0x80; // Timer enable TMSK2  = 0x03; // Prescaler = 8 (1tick all 1µs) SCI0Init(); while(1)  {    a1=TCNT;   a2=TCNT;   a3=TCNT;   a4=TCNT;   a5=TCNT;   a6=TCNT;   a7=TCNT;   a8=TCNT;   a9=TCNT;   a10=TCNT;   a11=TCNT;   a12=TCNT;   a13=TCNT;   a14=TCNT;   a15=TCNT;   a16=TCNT;   a17=TCNT;   a18=TCNT;   a19=TCNT;   a20=TCNT;   a21=TCNT;   a22=TCNT;   a23=TCNT;   SCI_OutString("x");   SCI_OutUDec(a1);   SCI_OutString("y");   SCI_OutUDec(a2);   SCI_OutString("z");   SCI_OutUDec(a3);   SCI_OutString("zz");   SCI_OutUDec(a4);   SCI_OutString("y");   SCI_OutUDec(a5);   SCI_OutString("z");   SCI_OutUDec(a6);   SCI_OutString("zz");   SCI_OutUDec(a7);   SCI_OutString("y");   SCI_OutUDec(a8);   SCI_OutString("z");   SCI_OutUDec(a9);   SCI_OutString("zz");   SCI_OutUDec(a10);   SCI_OutString("y");   SCI_OutUDec(a11);   SCI_OutString("z");   SCI_OutUDec(a12);   SCI_OutString("zz");   SCI_OutUDec(a13);   SCI_OutString("y");   SCI_OutUDec(a14);   SCI_OutString("z");   SCI_OutUDec(a15);   SCI_OutString("zz");   SCI_OutUDec(a16);    SCI_OutString("y");   SCI_OutUDec(a17);   SCI_OutString("z");   SCI_OutUDec(a18);   SCI_OutString("zz");   SCI_OutUDec(a19);   SCI_OutString("zz");   SCI_OutUDec(a20);    SCI_OutString("y");   SCI_OutUDec(a21);   SCI_OutString("z");   SCI_OutUDec(a22);   SCI_OutString("zz");   SCI_OutUDec(a23);  }}
Message Edited by kef on 2007-09-24 02:24 PM
oops, thought it's a bug, but here is a notice in ECT docs, both 912D60A and S12 :
The newly selected prescale factor will not take effect until the next synchronized edge where all prescale counter stages equal zero.
So behaviour is expected
TMSK2 = 0x03;  // write prescaler
TSCR = 0x80;    // enable timer
I mean that in D60A, the write of non default prescaler to TMSK2 is granted but doesn't apply until 128 timer ticks.