Author Topic: Axon 32.768 KHz Clock Problem  (Read 2049 times)

0 Members and 1 Guest are viewing this topic.

Offline airman00Topic starter

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 3,650
  • Helpful? 21
  • narobo.com
    • Narobo.com - Mechatronics and related
Axon 32.768 KHz Clock Problem
« 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();
}

Check out the Roboduino, Arduino-compatible board!


Link: http://curiousinventor.com/kits/roboduino

www.Narobo.com

Offline billhowl

  • Supreme Robot
  • *****
  • Posts: 376
  • Helpful? 32
  • Your success is in your hands.
Re: Axon 32.768 KHz Clock Problem
« Reply #1 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

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Axon 32.768 KHz Clock Problem
« Reply #2 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

 


Get Your Ad Here