Go Down

Topic: ATTiny85 without an external oscilator? (Read 1 time) previous topic - next topic

Scott Baker

I was thinking about programming a raw ATTiny85 and using it do serial back to my main Arduino. Looking at this

video

I see that there is a pretty large disparity between the internal oscillator and an external crystal. For the purposes of doing serial, which I imagine is VERY time sensitive do I need an external crystal?

tim7

It looks like the internal oscillator is just under 5% too-fast in that example, although the internal oscillator can be up to 10% off.  5% is pretty much the limit for reliable serial communication.  I think you'd need to either set the clock calibration register, or program the baud-rate generator specially to compensate.

Scott Baker

What exactly does an oscillator do? It just provides more accurate timing for an IC? Ebay has a bunch of oscillators cheap. Do you need to match the mhz of the oscillator to your chip?

All that oscillator does is "tick" 16,000 times in a second? So the ATtiny just counts the ticks and when it gets to 16k it determines that was one second?

tim7

Be careful with the terminology:  An oscillator is a circuit which generates the clock signal required by the CPU.  A crystal is just one part of one type of oscillator circuit.

There are two types of oscillator built into the ATtiny85:

  • One type uses an on-chip resistor and capacitor to generate an 8MHz clock[1].  It needs no external components, but it is not very accurate.

  • The second type requires an external crystal[2] plus two capacitors.  The external components take up space and cost, but the resulting clock is very accurate.  You can also choose any frequency, within certain limits[3].



It's also possible to use the clock signal from an external oscillator, but note that this is not the same as using an external crystal.

Normally the software runs faster or slower in proportion to the clock frequency.  However the Arduino software is clever enough to take the CPU clock into account, so delay(1000); always produces a one-second delay.  It also tries to ensure that Serial.begin(9600) always produces serial data at 9600 bits per second.

What the Arduino software can't do is account for an inaccurate clock.  The simplest thing to do is to use an external crystal, as these are manufactured to a high accuracy.  Alternatively you can tune the frequency of the internal oscillator, by adjusting the value stored in the OSCCAL register (check the datasheet for more details).

-------
note [1]: There is also a 128kHz clock, but most people will find this too slow.
note [2]: Instead of a crystal a ceramic resonator may be used.  It is slightly less accurate, but cheaper and doesn't need the extra capacitors.
note [3]: 0.4 - 20MHz for the ATtiny85, although crystals are only available with certain frequencies in this range.  Below 5V the maximum clock frequency is less than 20MHz.

mrburnette

I have successfully used SoftwareSerial @9600 BAUD with the ATtiny85 running the 8MHz internal osc. Using these cores: http://hlt.media.mit.edu/?p=1695

Just remember, you must burn new fuse values!  See the MIT text.

I have not tries higher serial rates.

- Ray

Go Up