DT512 timer-delay calculation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DT512 timer-delay calculation

1,270 Views
changebusclock
Contributor I

I want to know whether i am correct in calculating the delay value...

 

My program goes this way

TSCR1=0x90//timer enable,fast clear flag enable.

TIOS_IOS0=1;

TSCR2=0x07;//PRESCALAR=128

TCTL2=0x01;

TFLG1_C0F=1;

 

TC0=0x124F;//  FOR 300ms DELAY.....

 while(!TFLG1_C0F);//waiting for timer to complete......

CALCULATION

count*time period = delay

=> count=300ms/timeperiod

            =300ms/(128/2MHz)

            =0x124f

 

Should i load 0x124f to TC0 or should i load (oxffff-0x124f) into TC0 to obtain 300millisecond delay...

Labels (1)
0 Kudos
1 Reply

337 Views
kef
Specialist I

TSCR1=0x90//timer enable,fast clear flag enable.

TIOS_IOS0=1;

TSCR2=0x07;//PRESCALAR=128

TCTL2=0x01;

 

TFLG1_C0F=1;

Keep in mind that this ^^ line clears all 8 timer flags, not just TC0 flag.

 TFLG1 = TFLG1_C0F_MASK; or TFLG1 &= TFLG1_C0F_MASK; will clear just TC0 flag.

Also, having fast flag clear enabled, writing one to timer flag may not work, you should check the datasheet.

TC0=0x124F;//  FOR 300ms DELAY.....

 while(!TFLG1_C0F);//waiting for timer to complete......

 

Your code depends on what is current free running TCNT counter value. It will wait until TCNT counter reaches TCNT=TC0. To wait for 0x124F timer ticks, you should assign TCNT+0x124F to TC0. Or, if you want to delay by 0x124F ticks from previous TC0 compare event, then TC0=TC0+0x124F.

 

 

CALCULATION

count*time period = delay

=> count=300ms/timeperiod

            =300ms/(128/2MHz)

            =0x124f

 

Should i load 0x124f to TC0 or should i load (oxffff-0x124f) into TC0 to obtain 300millisecond delay...

 

Do you have 2MHz bus clock? Then 0x124f is OK, but you should add starting TCNT value.

0 Kudos