Go Down

Topic: core13: An Arduino core for the Attiny13 *testers wanted* (Read 169777 times) previous topic - next topic

hansibull

It will not blink after you hit "Burn bootloader", since it actually just sets the correct fuses. Doesn't the regular blink example work for you?
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

caiopoit

Yes, I burnt the bootloader, and it blinks, but not every 1 sec, it blinks a little slower than that something about 1.3 seconds...

DrAzzy

What clock speed is the chip running at?


IIRC they don't run at 8mhz internal? The "stock" core's time calculations are only accurate if 64 is evenly divisible by the clock speed in mhz (otherwise... what was it, millis() works, but delay and micros don't?). In my attiny cores, to support timekeeping on other clock speeds, I rewrote that bit. You can't just use division, because then it's really slow - I used hand-selected combination of addition, subtraction, and bitshifts for other common and semi-common clock speeds.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

caiopoit

Quote
they don't run at 8mhz internal?
No, they don't. They have many frequencies and the one I was using was 9.6Mhz, actually, if I upload the same sketch (blink) with 128Khz the led blinks way faster!!!

hansibull

The clock (9.6 MHz) is divided down, but isn't dividable by 64. delay() are based om _delay_ms(), and is not accurate at all. mills(), micros() and delayMicroseconds should be pretty accurate. I haven't had time to rewrite the whole delay() fiction yet. Do you have any advice on this DrAzzy? :)
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

DrAzzy

The clock (9.6 MHz) is divided down, but isn't dividable by 64. delay() are based om _delay_ms(), and is not accurate at all. mills(), micros() and delayMicroseconds should be pretty accurate. I haven't had time to rewrite the whole delay() fiction yet. Do you have any advice on this DrAzzy? :)
Oh, you do delay() that way? Might I ask why?


I use this delay in my core:

Code: [Select]

void delay(unsigned long ms)
{
  uint16_t start = (uint16_t)micros();
  while (ms > 0) {
    if (((uint16_t)micros() - start) >= 1000) {
      ms--;
      start += 1000;
    }
  }
}



It's micros() where you have to fiddle with stuff - micros() stock implementation will merrily integer-math the division and give you garbage results for weird clock speeds. A naive fix using division results in a >100us runtime for micros(). My solution is here -
https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/cores/tiny/wiring.c#L218
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

hansibull

Quote
Oh, you do delay() that way? Might I ask why?
MicroCore is just a fork of Smeezekitty's Core13. That crude delay function isn't my work ;) Using millis/micros is definitely the way to go
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

caiopoit

Well, it's now working on 9.6Mhz and using millis() to blink, but it looks like the imprecision of the oscillator is at about 4 to 10%, and that's bad for my project because I wanted to make an inverter...

DrAzzy

Sounds right to me. It's spec'ed to +/- 10%, though you can tune it with osccal to get it closer, at least for a given temperature and voltage.

If you need accurate timing, you don't rely on a microcontroller 's internal oscillator - they're all varying levels of bad. That's what crystals are for.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

caiopoit

I understand. Thanks for the help guys. At least I can now do something with my aTTiny13.

hansibull

Quote
I use this delay in my core:

Code: [Select]


void delay(unsigned long ms)
{
  uint16_t start = (uint16_t)micros();
  while (ms > 0) {
    if (((uint16_t)micros() - start) >= 1000) {
      ms--;
      start += 1000;
    }
  }
}

The code works really well with the Attiny13, but the problem is that the mills/micros function takes up a huge amount of space (about 300 bytes if I'm using the delay function above compared to _delay_ms() ).

The delayMicroseconds function is mostly written in assembly, and should be pretty accurate. I thought I could scrape together a function like this, but the ATtiny13 just freezes. I have no idea why :(

Code: [Select]

void delay(uint16_t ms)
{
  while(ms--)
    delayMicroseconds(1000);
}
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

1413

Hi smeezekitty,

I made some fixs in boards.txt and platform.txt in v0.22 at https://sourceforge.net/projects/ard-core13/files/ I thought you could update your work over there.

Burn bootloader function of Arduino IDE should work fine now. Before that I had to set fuse using avrdude to get it run at 9.6Mhz. Slower than that, it wouldn't allow me to upload sketch directly from Arduino IDE.

Tested with Arduino 1.6.9 and 1.6.12 and should work with all 1.6.x

Cheer,

hansibull

Smeezekitty's core has some major flaws that I think makes it pretty unbearable. Timer 0 is used for millis() and micros(), and overflows every 256th clock cycle. That's 37500 times a second. As a result, delay(1) actually lasts 1.3 ms if interrupts are enabled (which they are by default).

Have a look at MicroCore, which solves a lot of the problems you introduced in core13. Forum post here.
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

dw23q

Amazing MCU with crazy price and small shape. But the resource is too limited. In some posts I have read, the chip is just enough for basic functions like miles, digitalRead, digitalWrite etc... And never seen using communication protocols. Why that. Is it only possible to work as standalone, single app?

swe-dude

That depends what kind of communication you are looking for, i have used these to read dht22 sensors and transmit the data with nrf24l01 and still have a few hundred bytes left...

Go Up