Internal oscillator must be wrong

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

I am currently developing the software for my new project and I use my brand new Dragon to do the ISP programming.

The setup:
I've set up timer/counter 0 with a prescaler of 1024 (7.8125kHz @ 8MHz internal osc.), that would yield 128us count period and thereby 32.768ms overflow period. This means it overflows 31 (30.52) times/s.

The problem:
It takes much longer than 1s to count 31 overflows (much as in 5-10s, haven't measured). It now runs at 4 overflows/s instead. This suggests the internal osc. is really 1MHz, not 8MHz as the fuse settings tell me.

I have checked the count period in avrstudio4 with 8MHz clock setting to be 32.78ms (expected 32.77ms) so my timer setup should be ok.

What could cause this?

Simon

edit:
I'll just throw some code in here, oh and the MCU is ATMega88 DIL28.

#include 
#include "timer.h"
#include "leds.h"
#include 

static unsigned char seconds = 0;
static unsigned char overflows = 0;


void startTimer() {
	// Set up timer/counter 0 
	TCCR0A = 0x0;
	TCCR0B = (1 << CS02) | (1 << CS00);

	// Enable the TIMER0 OVF interrupt handler
	TIMSK0 |= (1 << TOIE0);

	// With a prescaler of 1024 and a frequency of 8MHz, the counting is
	//  done at 7.8125kHz. that means a count takes 128us and a full overflow cycle takes
	//  32.768ms (8-bit counter). For ~1s delays we want to have 31 overflows between increases.
}

void resetTime() {
	overflows = 0;
	TCNT0 = 0;
}

unsigned char getTime() {
	return seconds;
}

ISR(TIMER0_OVF_vect) {
	if(++overflows == 4) {
		seconds++;
		overflows = 0;
	}

	if(seconds%2 == 1)
		setIdleLed(1);
	else
		setIdleLed(0);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
This suggests the internal osc. is really 1MHz, not 8MHz as the fuse settings tell me.

So you actually changed the fuses to get 8mHz (the default fuse settings put it at 1mHz, you need to turn off the CKDIV8 fuse)?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope, not the mega88 as it seems. I remember the mega16 was 1MHz default but I've tried two of the 88's (new ones) and both of them are set on 8MHz.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ah! CKDIV8! thaynks Steve! I owe you one