Go Down

Topic: myAVR Board MK2 and arduino; Problems with CPU-Timing? (Read 1 time) previous topic - next topic

JanNow

Hi,
i am trying to run arduino code with the myAVR Board MK2 http://shop.myavr.com/Systemboards/myAVR%20Board%20MK2,%20equipped.htm?sp=article.sp.php&artID=40. It has an external crystal oscillator with 3.6 MHz and an Atmega 8. I changed programmes.txt to get the connection and boards.txt as seen below.

Code: [Select]

##############################################################

atmega8x.name= MyAVR ATmega8
atmega8x.upload.protocol=avr911
atmega8x.upload.maximum_size=7168
atmega8x.upload.speed=19200
atmega8x.bootloader.low_fuses=0xff
atmega8x.bootloader.high_fuses=0xc9
atmega8x.bootloader.extended_fuses=0xff
atmega8x.bootloader.path=optiboot
atmega8x.bootloader.file=optiboot_atmega8.hex
atmega8x.bootloader.unlock_bits=0x3F
atmega8x.bootloader.lock_bits=0x0F
atmega8x.build.mcu=atmega8
atmega8x.build.f_cpu=3686400L
atmega8x.build.core=arduino
#atmega8x.build.variant=standard

The compiling works fine but somethings wrong. The blink-sample causes an approx. 3 times longer delay than expected.

Does anyone know what's wrong? The f_cpu seems right, but i have to say that i copied the fuses from examples found in the internet as i do not understand the settings.

Greetings

Jan

johnwasser

The Arduino timer code only works correctly if F_CPU is a multiple of 8 MHz.  If you use any other clock then millis() delay() micros() and delayMicroseconds() will be off in different ways.

You can see the code in hardware/arduino/cores/arduino/wiring.c:

// the fractional number of milliseconds per timer0 overflow. we shift right
// by three to fit these numbers into a byte. (for the clock speeds we care
// about - 8 and 16 MHz - this doesn't lose precision.)
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
#define FRACT_MAX (1000 >> 3)
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

JanNow

Hi John,
thanks a lot. I think there are more problems with using a CPU clock different than a multiple of 8 MHz: My serial Monitor also doesn't work well. By using the real settings, there is nothing right. But if I type in F_CPU = 8 MHz, the serial data can be read by choosing 1200 baud in the Serial Monitor by choosing 9600 baud in the SW.

So it seems that I need another oszillator if i want to use arduino libs and toolchain.

Greetings

Jan

johnwasser

Perhaps you should try setting the fuses to use the internal calibrated RC oscillator.  You can select 1, 2, 4, or 8 MHz.  The 8 MHz option should work with the Arduino libraries.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp
See who has no social life: https://forum.arduino.cc/index.php?action=stats :)

Go Up