Pages: [1]   Go Down
Author Topic: ATTiny85 without an external oscilator?  (Read 979 times)
0 Members and 1 Guest are viewing this topic.
Canby, OR
Offline Offline
Full Member
***
Karma: 1
Posts: 158
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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



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?
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Canby, OR
Offline Offline
Full Member
***
Karma: 1
Posts: 158
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Atlanta, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1790
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had very mixed results with that core at 2400 and 9600 baud with the internal oscillator and a 8mhz crystal, sometimes it would work, sometimes it would spit garbage

look at

http://code.google.com/p/arduino-tiny/
Logged


Atlanta, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1790
AKA: Ray Burne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Never have had an issue ... maybe 6 projects using serial comms... with the MIT process.  I'm using 1.0.1 with no issues... BUT I am using a newer AVR tool chain mainly because I have multiple Mega2560.

- Ray
Logged

Pages: [1]   Go Up
Jump to: