Society of Robots - Robot Forum

Software => Software => Topic started by: airman00 on August 17, 2009, 08:29:21 PM

Title: Axon 32.768 KHz Clock Problem
Post by: airman00 on August 17, 2009, 08:29:21 PM
Hi,
I'm trying to make a simple second clock using the Axon and its Timer2 timer.
The timer2 timer is run off of 32.768 KHz internal oscillator on the Axon. Prescale is set at 1024.
Time Resolution = Prescale/ Clock Frequency
Time Resolution = 1024/32768
Time Resolution = .03125 seconds or 31.25mS
So for one second I would need 1000/31.25 = 32 "ticks"

But when I run my code, for 32 ticks, the seconds are displayed at more than two times the speed they should be.
Any idea whats up with this?
Code: [Select]
int Timer_Value(void) {
return Timer2Reg0;
}

void Clear_Timer_Value(void) {
Timer2Reg0 = 0;
}


Clear_Timer_Value();
while(1) {
if (Timer_Value() >= 31) {
rprintf("%d \r",temp);
temp = temp + 1;
Clear_Timer_Value();
}

Title: Re: Axon 32.768 KHz Clock Problem
Post by: billhowl on August 17, 2009, 11:30:20 PM
Hi, I have a question, how do you set the internal oscillator on the Axon to 32.768 KHz?
What I learn from the datasheet is that the Timer2 clock is run of the system clock which is 16MHz.
If you set the Prescale to 1024, the clock output will 15625Hz
Title: Re: Axon 32.768 KHz Clock Problem
Post by: Admin on August 18, 2009, 12:54:53 PM
But when I run my code, for 32 ticks, the seconds are displayed at more than two times the speed they should be.
Is 2x an estimate or the actual speed? Knowing how much faster, exactly, will help find the error.

What is your desired frequency? 31.91 Hz?

Lastly, what 32.768 KHz oscillator? I only see 8MHz and 128kHz internal clocks. And the respective divide clock by 8 CKDIV8 fuse. If you use 128kHz and CKDIV8, that'll give you 16kHz . . . a factor of 2x :P