Timer - time is wrong


hello,
i have problem timer , dont problem is.
it arduino mega1280 board , using timer3 believe 16bit timer.

so thought, if prescaler set 128 countintervall is:
1/(16 000 000/128) = 0,000008 seconds = 8µs

then if timer resetted 0 after overflow 16 bit  (65536)
so should take timer 8µs *65536 = 524,288 ms overflow.

this how set timer up:
code: [select]
/* first disable timer overflow interrupt while we're configuring */
 timsk3 &= ~(1<<toie3);  

 /* configure timer2 in normal mode (pure counting, no pwm etc.) */
 tccr3a &= ~((1<<wgm31) | (1<<wgm20));  
 tccr3b &= ~(1<<wgm32);  

 /* select clock source: internal i/o clock */
 assr &= ~(1<<as2);  

 /* disable compare match interrupt enable (only want overflow) */
 timsk3 &= ~(1<<ocie3a);  

 tccr3b |= (1<<cs32)  | (1<<cs20); // set bits  
 tccr3b &= ~(1<<cs31);             // clear bit  
 tcnt3 = 0;
 tcnt3 = tcnt3;

code: [select]
isr(timer3_ovf_vect) {  
 /* reload timer */
 tcnt3 = tcnt3;  
 serial.println(millis()-measure);
 measure = millis();
}  


now 4194 ms on serial monitor...
what wrong this?

is clock 16mhz or have measure first du real times in seconds?

is timer connected pin ? dont need connection of timer pins, because use every pin on board else.
can use timers, without happing pins?
-flo

can show whole thing , not snippets?

code: [select]
/* configure timer2 in normal mode (pure counting, no pwm etc.) */
  tccr3a &= ~((1<<wgm31) | (1<<wgm20)); 
  tccr3b &= ~(1<<wgm32); 


how about:

code: [select]
tccr3a = 0;
tccr3b = 0;


then know reset.

code: [select]
isr(timer3_ovf_vect) { 
  /* reload timer */
  tcnt3 = tcnt3; 
  serial.println(millis()-measure);
  measure = millis();


don't serial prints in isr.

code: [select]
  tccr3b |= (1<<cs32)  | (1<<cs20); // set bits 

this timer 3 should cs30:

code: [select]
  tccr3b |= (1<<cs32)  | (1<<cs30); // set bits 

see page 161 of datasheet.

those bits give prescaler of 1024. there no prescaler of 128 timer 3.

quote
is clock 16mhz or have measure first du real times in seconds?


it code problem.


Arduino Forum > Using Arduino > Programming Questions > Timer - time is wrong


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial