Go Down

Topic: Arduino-izing the AVR Butterfly (Read 11 times) previous topic - next topic

DaveK

#15
Dec 05, 2008, 02:54 am Last Edit: Dec 05, 2008, 04:41 am by DaveK Reason: 1
I went ahead and loaded Nick's Butterfly additions and got it working with no trouble at all. A simple LED blink sample works just fine (blinking the speaker).

Initially the clock was running at the default 1MHz setting which I presume is where the bootloader leaves it. Resetting it to 8Mhz leaves the delay function off by a factor of 2, but it works.

The ASCIITable example works too, although at half the specified baud rate.

[edit]Ok, I went and found the F_CPU setting and put it up to 8MHz to match my clock, then found that I was getting twice the baud rate. I cleared the U2X bit in UCSRA and now it's behaving as I expect. I also see that delay(1) doesn't delay for the expected time, but delayMicroseconds(1000) and delay(4) does, so that was just simple user error.[/edit]

Pretty neat.

Code: [Select]

int value = 0;                            // variable to keep the actual value
int ledPin = 13;                           // light connected to digital pin 9

void setup()
{
 // Reset clock prescale, no scaling for 8MHz
 CLKPR  = (1 << CLKPCE);
 CLKPR  = 0x00;

 pinMode(ledPin, OUTPUT);  
}

void loop()
{
 digitalWrite(ledPin, HIGH);   // sets the LED on
 delay(1);                           // waits 2mS
 digitalWrite(ledPin, LOW);    // sets the LED off
 delay(1);                           // waits 2mS
}

Mark Bramwell

I have been following this thread. I have some butterflys ordered but they are not here yet.

As I quickly read through the 169 specs, it seems to have a 168 compatibility mode.

Can I suggest something...  How about taking a bootloader meant for something like a lilypad (which I think is 8mhz without a xtal) and slightly change the fuse bits to put the butterfly into compatibility mode.  

I would think we could use arduino software as-is if we select lilypad from the board menu and the timings would be perfect.

I have already started making a library with nice to have functions to support the peripherals.

DaveK

I think I'd just as soon have settings for the butterfly, as Nick has it set up. The butterfly bootloader seems to work just fine, and it should be simple enough to update init() in wiring.c with the clock prescale settings (easy to set them up to work with multiple settings of F_CPU even) and U2X.

Nick Lott

#18
Dec 05, 2008, 07:48 am Last Edit: Dec 05, 2008, 07:55 am by Brokentoaster Reason: 1
Hi guys, I have the CPU speed in the file boards.txt set to 4MHZ which is why we get a factor of 2 error in the speeds

Change the section in boards .txt to the following and that should be fixed.

bfly.build.mcu=atmega169
bfly.build.f_cpu=8000000L
bfly.build.core=butterfly

I will update my files asap.

Is it possible to put the clock setup in somewhere so the user doesn't need to do this in the sketch. (EDIT: right ok in init() in wiring.c then jsut read the prev post properly. :) )

Writing a bootloader that will work with arduino is pretty straightforward but I would rather use the standard bootloader if possible although the button pressing thing is really annoying.

The ability to work with a std butterfly in my mind is far more useful as this avoids the need for programming hardware.

[EDIT: Just updated my files at http://www.brokentoaster.com/arduino012_butterfly.zip ]

dcb

Is it possible to focus on 1mhz?  One of the charms of the butterfly is low power consumption, as it runs on a button cell.  The CPU will draw about 4 times as much power at 4mhz than at 1mhz.

Go Up