e-textile construction kit information for hackers
modifications I made to the Arduino hardware, firmware and software


hardware/firmware
I removed the crystal and slowed the ATMega8 clock speed to 4 MHz to reduce power consumption - important for wearables ;). I also turned on brown-out detection on the ATmega8. When the self-programming feature of the ATmega8 is enabled, if the power supply dips below ~3.7 volts (~3 volts for low power chip), the chip will randomly overwrite its own flash unless brown-out detection is enabled. I wanted to be able to use a battery and not worry about a voltage regulator. Here's how I did it:
  • Recompile the bootloader code for 4 MHz oscillator setting and load onto chip.
    Download the bootloader code here: http://svn.berlios.de/viewcvs/arduino/trunk/bootloader/
    In the Makefile, change DEFS= -DF_CPU=16000000 to DEFS= -DF_CPU=4000000.
    Recompile the code and burn it onto the ATmega8.
  • Remove the crystal.
  • Change the fuse settings on the ATmega8 or ATmega8L for 4 MHz oscillator and brown-out detection enabled:
    low fuse byte:    ATmega8: 0x23   ATmega8L: 0xA3
    high fuse byte:   ATmega8: 0xda   ATmega8L: 0xda

software
I modified the Arduino software to reflect the new chip clock speed. This includes modifying clock speed defines and changing the AD code, which is currently hard coded for the 16 MHz speed. I also wrote custom libraries and included them in the basic Arduino build so that they are accessible without include statements in Arduino programs. Here's how I did it:
  • In Arduino-000x/lib/preferences.txt change "build.f_cpu=16000000L" to "build.f_cpu=4000000L".
  • In Arduino-000x/lib/targets/wiring/WConstants.h change "#define F_CPU 16000000L" to "#define F_CPU 4000000L" and "#define CPU_FREQ 16000000L" to "#define CPU_FREQ 4000000L".
    Note: the location of F_CPU/CPU_FREQ defines is different for different Arduino versions. If you can't find them in WConstants.h, search through the Arduino directory. They might be found in global.h or some other file.
  • To change the AD settings, in Arduino-000x/lib/targets/arduino/wiring.c, in main (), change:

    // set a2d prescale factor to 128
    // 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
    // XXX: this will not work properly for other clock speeds, and
    // this code should use F_CPU to determine the prescale factor.
    sbi(ADCSRA, ADPS2);
    sbi(ADCSRA, ADPS1);
    sbi(ADCSRA, ADPS0);

    to:

    // F_CPU = 4000000
    // set a2d prescale factor to 128
    // 4 MHz / 32 = 125 KHz, inside the desired 50-200 KHz range.
    // XXX: this will not work properly for other clock speeds, and
    // this code should use F_CPU to determine the prescale factor.
    sbi(ADCSRA, ADPS2);
    cbi(ADCSRA, ADPS1);
    sbi(ADCSRA, ADPS0);

  • Change Arduino-000x/lib/targets/arduino/WProgram.h to include custom libraries.

back to intro
Click here to return to the main introduction page




This material is based upon work supported by the National Science Foundation under Grant No. 0326054.

Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation (NSF).