Go Down

Topic: Atmega168 internal osc. 8MHz, Wire.h library and compass (Read 346 times) previous topic - next topic

bluebird92

May 17, 2013, 11:10 pm Last Edit: May 17, 2013, 11:12 pm by bluebird92 Reason: 1
Hi,

I'm not sure if this fits in this section of forum but anyway.

I have a problem:    I have CMPS 10 compass like this http://www.robot-electronics.co.uk/acatalog/Compass.html

I have the code, like the one written on the pasted url under examples and some servos to move according to bearing from this compass.  With Uno everything works fine. When I use AtMega168(or Atmega8A) with internal clock, servos do not move with bearing anymore. I have excluded everything except Wire.h library, because servos and servo.write..   etc.  works fine.
Does it have anything to do with Wire.h and 8MHz clock ?
Another thing that comes to my mind is that AtMega168 in combination with Wire.h and Servo.h libraries simply runs out of memory ? Is AtMega168 any different from AtMega8A in this way, because I know that's the problem in AtMega8A ?

stonent

#1
May 18, 2013, 07:40 pm Last Edit: May 18, 2013, 07:42 pm by stonent Reason: 1
I know the chip uses the speed of the clock (either internal or external crystal) to time other things like delays and pulses.

If you wrote a program for a 20mhz chip for example and then dumped it into an 8mhz chip without fixing that in code, you may have timing problems, like the pulses to the servos are not correct because you're only running at 40% of the speed.

I found this out uploading a blink sketch to an attiny that was using a 1mhz internal clock. I thought it wasn't working because the light wasn't blinking, turns out it really was but the pulses were like 16 seconds apart because the clock wasn't compensated for.

In AVR C you have to set you chip speed at the beginning. The arduino IDE by default assumes you're just using the board speed.

When you're programming your other chips, do you have a separate entry for them in the target board with the speed set correctly?

bluebird92

Selected board is correct, fuses are set correctly according to frequency, etc. ...

Like I said, servos work fine.  I know that there is a problem with AtMega8 if you use Wire and Servo library together, it "freezes" due to memory...   But I don't know if maybe AtMega168 has the same problem ? Is it's arhitecture same as AtMega8 with increased flash or is it more similar to AtMega328 ?

Go Up