Attiny84 using external clock (not crystal)

Hi all,

Hopefully the right forum to ask for help. I've been spending a few days working out my issue and can't seem to find a clear way through - little clear advice on this particular issue.

I have an attiny84 operating at 5v. I'm utilising a GPS module to create an 8mhz 50% duty cycle clock signal to drive the clock pin (2). I can use any number of bootloaders... attiny, damellis' etc and it works perfectly. No problems.

However, if I change the clock frequency generated by the GPS module upwards... I've tried both 12mhz and 16mhz, and update the bootloader using the appropriate fuses and boards.txt, the attiny84 still works fine, but the timing of the system is out of whack.

For example:
At 12mhz, the simple blink routine using 1000ms delay on/off actually measures 1600ms. 1.6 times as long.

At 16mhz, the blink routines' delay is exactly 2000ms - 2x as long as it should be.

What am I missing? Is there a prescaler I'm not setting properly. I've trawled through the data sheet and can't find anything that seems to explain this.

Any pointers or concepts you think I should be researching would be greatly appreciated.

Can you try changing the clock pre-scaler in software?

	// change system clock pre-scaler to 1
	CLKPR = 0<<CLKPCE | 0<<CLKPS3 | 0<<CLKPS2 | 0<<CLKPS1 | 0<<CLKPS0;

It must be done in setup() before anything else.


	CLKPR = 0<<CLKPCE | 0<<CLKPS3 | 0<<CLKPS2 | 0<<CLKPS1 | 0<<CLKPS0;

// all other code


Thanks hzrnbgy,

I just tried that at 16Mhz and it made no difference. I assume then the pre-scaler is/was already set at 1. Still getting 2000ms blinks out of 1000ms delay code.

It's odd that I can't find any references to anyone else having these same problems. Most of the problems others are dealing with seem to be centred on CKDIV8 not being set properly or worrying about aligning their external clock source frequency with their F_CPU.

Maybe it's the chip i'm using?

To be sure, to be sure, I ran the chip at 16Mhz and set the prescaler to 2 and the blink routine runs at 4000ms/4000ms.

Setting it back to prescaler of 1, the blink routine runs at 2000ms/2000ms again.

Okay. So after thinking there was something going on with the equipment. I wanted to make sure there wasn't any user error.

I started with my clock source (ublox neo gps module). While I was changing the frequency using the U-Centre software, I realised I was changing the wrong ublox neo timer parameter, so here I am thinking I'm switching back and forth between 8Mhz and 16Mhz, in fact the neo was always sitting at 8mhz the whole time unchanged. When I was first testing the neo, I must have changed the right timer parameter and promptly forgot about it from then on.

So here I was happily changing bootloaders and frequencies, but all the time the clock source was always sitting at 8Mhz.

Makes me wonder why there wasn't a communication error while I had all the software thinking I as at 16Mhz, but only ever giving it a 8Mhz clock source.

Anyway - issue solved. User error.

Thanks again hzrnbgy for your input.

Well was anything actually using Serial? Or was it all ISP programming and clocked communication protocols (SPI, I2C/TWI) Serial is the big thing that breaks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.