Arduino Forum

Using Arduino => Microcontrollers => Topic started by: smeezekitty on Feb 01, 2012, 04:28 am

Title: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 01, 2012, 04:28 am
I am writing [have written] an Arduino core for the Attiny13.
It will [does] support a subset of the Arduino functions and is of relatively small size.
So far it seems to work but I have not tested it completely.
I have not tested it thoroughly and I only tested it with 128khz internal oscillator.
Supports 128KHz, 600KHz, 1MHz, 1.2MHz, 4MHz, 4.8MHz, 8MHz, 9.6MHz, 10MHz, 12MHz and 16MHz clock speeds (Although not all are tested) - More frequency support soon
If anyone gets a chance give it a try.
Although programming a microcontroller with this little flash space with a Arduino core is alittle impractical, it helps the beginners greatly. Core13 is optimized for size so you have more space for user code.

For the most part, I read the Arduino core source code and rewrote most of it from scratch.
It may work for other 8 pin Attiny series but I cannot promise.
Currently supported functions:
* = Partial support
Code: [Select]

map()
random()
randomSeed()
millis()
micros()
delay()
delayMicroseconds() *
analogRead()
analogWrite()
pinMode()
digitalRead()
digitalWrite()
pulseIn() (Untested)
shiftIn() (Untested)
shiftOut() (Untested)

edit: fixed bugs and attached new version.
edit: Added support for 4, 4.8Mhz and improved support for 9.6Mhz
edit: Released 0.15 that fixes bugs
edit: Released 0.19 and removed old version attached. Please download from sourceforge
edit: Released 0.20 which improves delayMicroseconds() considerably

(If you cannot download from SF (like because their site bloat hangs your machine :) then PM me and I can provide a direct download)

Supports the old Arduino IDE (pre-1.0) and Arduino 1.0.x. Support for Arduino 1.5 is untested and may not work
From now on download from sourceforge.net for the newest release http://sourceforge.net/projects/ard-core13/ (http://sourceforge.net/projects/ard-core13/)
Licensing note: Core13 is under a mixed license (as marked at the top of each source file) this is because I included
some Arduino core files. Most of the code is under a very unrestricted license while a few files are under the standard Arduino core license
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 03, 2012, 02:38 am
NULL
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on Feb 03, 2012, 04:56 am

Dude.  Patience.  A large number of users only visit the forum weekly or less often.  In addition, from an Arduino perspective, the core is for an esoteric processor.

For what it's worth, I plan to look it over this weekend.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: westfw on Feb 03, 2012, 05:23 am
Needs instructions for how to add it to the IDE...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 03, 2012, 07:08 am


Dude.  Patience.  A large number of users only visit the forum weekly or less often.

Ok. I am not often a patient person.
Quote
In addition, from an Arduino perspective, the core is for an esoteric processor.

Limited but hardly esoteric.
[/quote]
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 03, 2012, 07:12 am

Needs instructions for how to add it to the IDE...


On windows it will usually go in
Code: [Select]

C:\arduino\arduino-<version>\hardware\arduino\cores\core13

in my case it would be
Code: [Select]

C:\arduino\arduino-0022\hardware\arduino\cores\core13

I added this to my boards.txt:
Code: [Select]

attiny13.name=Attiny 13A standalone

attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200

attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty

attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF

attiny13.build.mcu=attiny13a
attiny13.build.f_cpu=128000
attiny13.build.core=core13

But be sure to change the fuses, f_cpu and programmer to match what you will be using.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: danimal1228 on Feb 18, 2012, 11:18 pm
I downloaded your file. Moved it into the Arduino directory. Selected ATTINY 13A Standalone as the board and Arduino as ISP for the programmer.

When I try and verify or upload the code, it says 'pinMode' was not declared in this scope.

I am sure it is something as simple as not including a file thats required but I thought I would ask here first before I start messing with stuff.

Also, thanks for taking the time to work on the Tiny13...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 19, 2012, 09:16 pm

I downloaded your file. Moved it into the Arduino directory. Selected ATTINY 13A Standalone as the board and Arduino as ISP for the programmer.

When I try and verify or upload the code, it says 'pinMode' was not declared in this scope.

I am sure it is something as simple as not including a file thats required but I thought I would ask here first before I start messing with stuff.


I failed to make the instructions clear enough.
You have to extract the zip file to
Code: [Select]

C:\arduino\arduino-<version>\hardware\arduino\cores\core13

Note: The folder core13 will not exist.
Note2: I have not tested this with IDE version 1.0 although it should work.
Quote

Quote

Also, thanks for taking the time to work on the Tiny13...

Most people are put off by only 1k of flash...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 26, 2012, 02:24 am
Nice work and thank you for taking on this project! I've been looking for Tiny13 core for a very small project and was agonizing over the decision to embark on writing my own  :smiley-red: - too small a project ... And finally I've found yours!

Anyhow, I've tried it with 0022 and 1.0 on Linux

I'm still looking into the code but the result so far as follows:

0022 complies the code fine though avrdude is not finding the MCU (I'm using AVRISP MKII programmer) - it looks for t13 but sees attiny13a and throws an error.

1.0 does not compile - it's not finding the core at either of the two possible locations:

~/sketchbook/hardware/arduino/codes/core13
or
~/arduino_directory/hardware/arduino/cores/core13

trying to burn a bootloader with the programmer on V1.0 does not go either - same error as on 0022 (wrong MCU name)

I'm still looking around but maybe you can see what I'm doing wrong here?

Cheers!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 26, 2012, 04:06 am
All right, thanks again, smeezekitty!

I am blinking some LEDs here using Arduino 1.0 (linux) with ATtiny13  :D

The problem was indeed the file locations. As far as I can tell, it depends on which  boards.txt file you are adding your ATtiny13 entry to. I already had the ATtiny libraries by Damellis (https://github.com/damellis/attiny/tree/Arduino1) installed (ATtiny13 is missing there) and therefore I was using the boards.txt located at
Code: [Select]
~/sketchbook/hardware/tiny/boards.txt
So, I just added an entry to the other ATTiny cores' boards.txt:

Code: [Select]

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

attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)

attiny13.upload.using=arduino:arduinoisp
# attiny13.upload.protocol=avrispv2
# attiny2313at1.upload.using=pololu

attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200

attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty

attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF

attiny13.build.mcu=attiny13
attiny13.build.f_cpu=128000
attiny13.build.core=core13

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


In this case the smeezekitty's core had to be located at
Code: [Select]
~/sketchbook/hardware/tiny/cores/core13/

Additionally, since this is Arduino 1.0, a small Arduino.h file needs to be added. I just copied one from the other core package:
Code: [Select]
#ifndef Arduino_h
#define Arduino_h

#include <WProgram.h>

#endif


The timer seems a bit off (actually, runs twice as fast as far as I can tell) but that's a 128kHz oscillator, I haven't looked at the prescaler and also, it may just be very inaccurate. I'll look into it later.

That was pretty much it!

Anyhow, great job, smeezekitty!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 26, 2012, 05:03 am


The timer seems a bit off (actually, runs twice as fast as far as I can tell) but that's a 128kHz oscillator, I haven't looked at the prescaler and also, it may just be very inaccurate. I'll look into it later.

That was pretty much it!

Anyhow, great job, smeezekitty!


This could be a bug.
The 128khz oscillator is inaccurate but not that inaccurate. Its about +- 30%.
It seems to run about the correct speed here although I have not tested it on Linux or Arduino 1.0.
Please post the code you used to make it blink.
I will investigate this further.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 26, 2012, 06:09 am
I've also looked at it and it turns out that I had to use the "Burn Bootloader" feature in IDE 1.0 which for a Tiny simply means that the fuses are burned correctly. Until then the timer was not setup correctly. Also I've switched to the internal 9.6MHz calibrated oscillator is the timing is perfect now. Here are the fuses:

Code: [Select]
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff


Please note that I'm sort of integrating your core with Demellis'es . I honestly could not find a way to burn the fuses with yours - the bootloader file was missing or I simply failed to find it. How'd you do it? 

Cheers!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 26, 2012, 06:52 am

I've also looked at it and it turns out that I had to use the "Burn Bootloader" feature in IDE 1.0 which for a Tiny simply means that the fuses are burned correctly. Until then the timer was not setup correctly. Also I've switched to the internal 9.6MHz calibrated oscillator is the timing is perfect now. Here are the fuses:

Code: [Select]
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff


Be sure to adjust F_CPU as well.
Quote

Please note that I'm sort of integrating your core with Demellis'es . I honestly could not find a way to burn the fuses with yours - the bootloader file was missing or I simply failed to find it. How'd you do it? 

Cheers!

I did not include a bootloader file because the attiny13 is too small for a bootloader.
I burned the fuses with avr-dude on the command line prior to using the Arduino IDE.
BTW I uploaded a new version that fixes a few minor bugs relating to clock speed.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: nikone on Feb 26, 2012, 02:45 pm
Sorry but the attiny 13 nave only 1 k of flash , and only the sketch blink is 1.2k , what worldwide you do whit the attiny 13 ?, thanks for the core
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 26, 2012, 06:36 pm

Sorry but the attiny 13 nave only 1 k of flash , and only the sketch blink is 1.2k , what worldwide you do whit the attiny 13 ?, thanks for the core
1.2K is a lot of bytes for a blink! The code must be not well optimized or sometin'  . You can do plenty of useful things with 1K of command space. For example, here is a code for a 10-LED light chaser (can convert it into Cylon eyes  or some other such blinking toy) and it compiles into only 562 bytes. In fact, there might even be some saving there still, I just didn't have too much time to optimize it.
Code: [Select]

/*
  Charlieplexing example for ATtiny13
  This code is for a 10-LED bargraph display. You can increase the amount of LEDs controller by the Tiny to 20 if needed.
  Code by Elabz.com
http://elabz.com/
  This example code is in the public domain. If you end up using it in a project, please drop me a message, I'd be happy to
  know it was of some use. I'll also be happy to feature your project on my site, so send some pictures, too: http://elabz.com/site/contact/
 
//       ATMEL ATTINY13 / ARDUINO
//
//                 +-\/-+
// ADC0 (D 5) PB5 1|    |8 Vcc
// ADC3 (D 3) PB3 2|    |7 PB2 (D 2) ADC1
// ADC2 (D 4) PB4 3|    |6 PB1 (D 1) PWM1
//            GND 4|    |5 PB0 (D 0) PWM0
//                 +----+

 
 
*/
int j; // just a counter
boolean d; // direction forward=true
//int bitmap[]={1,2,1,4,1,8,2,4,2,4};
byte bitmap[]={B00000001,B00000010,B00000001,B00000100,B00000001,B00001000,B00000010,B00000100,B00000010,B00001000};
byte outModes[]={B00000011,B00000011,B00000101,B00000101,B00001001,B00001001,B00000110,B00000110,B00001010,B00001010};



void setup() {
d=true;
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
/*  for(int i=0;i<5;i++) {
    pinMode(i, OUTPUT);   
} */

}

void loop() {
 
byte outModeNow =  outModes[j] ;
  byte bitmapNow=bitmap[j];
  if(j>8)
  { d=false;
  }else if(j<1)
  { d=true;}
  if(d){j++;}else{j--;}
  DDRB = outModeNow;
// PORTB = B00000000;
  PORTB = bitmapNow;
  delay(50);              // wait

}


Hope this helps,

Cheers!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 26, 2012, 07:43 pm

Sorry but the attiny 13 nave only 1 k of flash , and only the sketch blink is 1.2k , what worldwide you do whit the attiny 13 ?, thanks for the core

Not sure what is going on here.
The standard blink sketch compiles to 370 bytes with my core.
Even with the standard Arduino core its a bit less then 1KB.
Which blink sketch, compiler, etc? Blink should certainly not be over 1KB.
@ElectroNick
You can most likely use a byte for "j" and operations on a byte may be slightly smaller
I also guess there is a better way to do this
Code: [Select]

if(j>8)
  { d=false;
  }else if(j<1)
  { d=true;}
  if(d){j++;}else{j--;}

but I cannot think very well right now.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: nikone on Feb 26, 2012, 09:20 pm
Excusme for my english but i'm italian, now i understand how your core work , it's vero interesting , at the moment i haven't some attiny 13 but i'll test the core when i can , Thanks you vero much for this core
Niko
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 27, 2012, 01:58 am
smeezekitty, I seem to have hit a brick wall here  :smiley-sad-blue:, wonder if you have a few pointers for me.

delay() function seems to be acting up: if you call it as delay(500);, it works as expected. But if you're calling it as delay(someVariable); , the program just stops and sits there indefinitely.  I've tried passing it int, long and byte  type variables (in my case, looked up values from an array defined as either of those types) and it hangs on all of them except when you literally just type the value in ( i.e. delay(500); ).

I'm trying to modify my own light chaser sketch (code below) to include a sort of a pseudo-PWM brightness control. It compiles fine but when executed, the LED matrix sits dark. If you type in, say delay(100) instead of delay(onDelay) and do the same for delay(offDelay), the LEDs work but of course, the gradual brightness increase does not happen.

It's a rather simple change to an already working code and I just can't wrap my head around the issue. That's why the question about the delay() implementation came up. Any critique or tips would be appreciated.

Cheers!

Code: [Select]

int j; // just a counter
boolean d; // direction forward=true
byte bitmap[]={B00000001,B00000010,B00000001,B00000100,B00000001,B00001000,B00000010,B00000100,B00000010,B00001000};
byte outModes[]={B00000011,B00000011,B00000101,B00000101,B00001001,B00001001,B00000110,B00000110,B00001010,B00001010};
//byte waveforms[16] = {1,4,15,31,50,69,85,96,100,96,85,69,50,31,15,4}; // happens to be 1/2 of sine wave. Just for test - some other profile may look better.
int waves[]={25,50,100,50,25}; // even simpler waveform
int cycleDelay=100;

void setup() {
d=true;
}

void loop() {
 
byte outModeNow =  outModes[j] ;
  byte bitmapNow=bitmap[j];
  if(j>8)
  { d=false;
  }else if(j<1)
  { d=true;}
  if(d){j++;}else{j--;}

  for(int x=0; x<5; x++){ // counter for the waveform
      int onDelay = waves[x];
      int offDelay = cycleDelay - onDelay;
     
      DDRB = outModeNow;
      PORTB = bitmapNow; // turn LED on
      delay(onDelay);   // then wait
      DDRB = B00000000; // turn everything off
      delay(offDelay); // wait for the off period
  }

}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 27, 2012, 03:24 am

smeezekitty, I seem to have hit a brick wall here  :smiley-sad-blue:, wonder if you have a few pointers for me.

delay() function seems to be acting up: if you call it as delay(500);, it works as expected. But if you're calling it as delay(someVariable); , the program just stops and sits there indefinitely.  I've tried passing it int, long and byte  type variables (in my case, looked up values from an array defined as either of those types) and it hangs on all of them except when you literally just type the value in ( i.e. delay(500); ).

I'm trying to modify my own light chaser sketch (code below) to include a sort of a pseudo-PWM brightness control. It compiles fine but when executed, the LED matrix sits dark. If you type in, say delay(100) instead of delay(onDelay) and do the same for delay(offDelay), the LEDs work but of course, the gradual brightness increase does not happen.

It's a rather simple change to an already working code and I just can't wrap my head around the issue. That's why the question about the delay() implementation came up. Any critique or tips would be appreciated.

Cheers!

Code: [Select]

int j; // just a counter
boolean d; // direction forward=true
byte bitmap[]={B00000001,B00000010,B00000001,B00000100,B00000001,B00001000,B00000010,B00000100,B00000010,B00001000};
byte outModes[]={B00000011,B00000011,B00000101,B00000101,B00001001,B00001001,B00000110,B00000110,B00001010,B00001010};
//byte waveforms[16] = {1,4,15,31,50,69,85,96,100,96,85,69,50,31,15,4}; // happens to be 1/2 of sine wave. Just for test - some other profile may look better.
int waves[]={25,50,100,50,25}; // even simpler waveform
int cycleDelay=100;

void setup() {
d=true;
}

void loop() {
 
byte outModeNow =  outModes[j] ;
 byte bitmapNow=bitmap[j];
 if(j>8)
 { d=false;
 }else if(j<1)
 { d=true;}
 if(d){j++;}else{j--;}

 for(int x=0; x<5; x++){ // counter for the waveform
     int onDelay = waves[x];
     int offDelay = cycleDelay - onDelay;
     
     DDRB = outModeNow;
     PORTB = bitmapNow; // turn LED on
     delay(onDelay);   // then wait
     DDRB = B00000000; // turn everything off
     delay(offDelay); // wait for the off period
 }

}


T
he code you provided did not compile. I had to change all the Bxxxxxxxx values to 0Bxxxxxxxx format (added 0 prefix).
But after making that change, it seemed to work but I did not have to proper LED array hooked up to test it fully.
I also tested the delay in another test program and again it works with no problems with variable values.
Either there is a problem with Arduino IDE 1.0 or clock speeds other then 128khz.
I may have to break down and try IDE version 1.0.


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 27, 2012, 07:24 am
I think I got the issue down to the ATtiny13 hardware limitation - with only 64 bytes of SRAM you really have to be very careful with sizes of the variables  and arrays. I think the problem with my code was that the RAM would fill up really quickly.

I've tried to remove everything I could and had to do linear brightness increase, which isn't really a very attractive option  :. I had to strip almost everything down (eliminate variables unless absolutely necessary, reduce int to byte where possible and so on) in order to get it to work and I had to give up trying to control the brightness with sine and other complex waveforms - the only way I could do it was to go 0-100% in the first quarter of the cycle and  hold it for the rest of the cycle. The effect of the gradual brightness increase is almost imperceptible, but that was the best I could do. Hope someone could come up with a better code!
Here is it:

Code: [Select]

/*
  Charlieplexing example for ATtiny13 with some brightness control using pseudo-PWM
  This code is for a 10-LED bargraph display. You can increase the amount of LEDs controller by the Tiny to 20 if needed.
  Code by Elabz.com
  http://elabz.com/
  This example code is in the public domain. If you end up using it in a project, please drop me a message, I'd be happy to
  know it was of some use. I'll also be happy to feature your project on my site, so send some pictures, too.
 
  LED hookup can be gleaned from the bitmap[] array values. For example, first LED's value is B00000001 which means that
  to light the LED the D0 has to ho HIGH and D1 - LOW, so the LED's anode is facing D0. LED #2 is between the same legs but in reverse.
  LED #3 is between D0 and D2, LED #4 is the same legs but in reverse and so on.
 
//       ATMEL ATTINY13 / ARDUINO
//
//                 +-\/-+
// ADC0 (D 5) PB5 1|    |8 Vcc
// ADC3 (D 3) PB3 2|    |7 PB2 (D 2) ADC1
// ADC2 (D 4) PB4 3|    |6 PB1 (D 1) PWM1
//            GND 4|    |5 PB0 (D 0) PWM0
//                 +----+

 
 
*/
byte bitmap[]={0B00000001,0B00000010,0B00000001,0B00000100,0B00000001,0B00001000,0B00000010,0B00000100,0B00000010,0B00001000};
byte outModes[]={0B00000011,0B00000011,0B00000101,0B00000101,0B00001001,0B00001001,0B00000110,0B00000110,0B00001010,0B00001010};
boolean d; // direction forward=true
byte j=0; // just a counter
long periodPWM;
long periodNow;
int cycleDelay=3000;
void setup() {
periodPWM = cycleDelay/200;
d=true;
}

void loop() {
int offDelay;

  for(byte x=0; x<50; x++){ // counter for the waveform
      offDelay = 50 - x;
      periodNow = millis();
     
      while(millis()-periodNow < periodPWM)
      {
      DDRB = 0B00000000; // turn everything off
      delayMicroseconds(offDelay); // wait for the off period
      DDRB = outModes[j];
      PORTB = bitmap[j]; // turn LED on
      delayMicroseconds(x);   // then wait
     }
  }
delay(cycleDelay*3/4);

  if(j>8)
  { d=false;
  }else if(j<1)
  { d=true;}
  if(d){j++;}else{j--;}

}
 
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on Feb 27, 2012, 07:38 am

The correct datatype is unsigned...
[font=Courier New]unsigned long periodPWM;
unsigned long periodNow;[/font]

cycleDelay is a constant and should be declared as such...
[font=Courier New]const int cycleDelay=3000;[/font]

bitmap is not only constant but it is a perfect candidate for PROGMEM which will free some SRAM.

outModes is not only constant but it is a perfect candidate for PROGMEM which will free some SRAM.

periodNow does not need to be global.  Making it local will free 4 bytes of SRAM.

offDelay is too large of a datatype.  Make it byte.

offDelay does not need to be global.  Make it a local variable.

periodNow and periodPWM can both be reduced to a 16 bit datatype.

Initializing d should knock one machine instruction out of Flash...
boolean d = true; // direction forward=true
void setup() {
...
d=true;
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 27, 2012, 07:47 am

bitmap is not only constant but it is a perfect candidate for PROGMEM which will free some SRAM.

outModes is not only constant but it is a perfect candidate for PROGMEM which will free some SRAM.

I thought the same thing.
For more information about progmem see:
www.nongnu.org/avr-libc/user-manual/pgmspace.html
http://arduino.cc/en/Reference/PROGMEM
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 28, 2012, 05:44 am
@Coding Badly, smeezekitty:
guys, thank you very much for the tip! Moving the arrays with constant values to Flash using PROGMEM did the trick! I'm happily perusing relatively complex waveforms now like 48-values sine and there's room for more if 48 is too coarse for your application). 

I'll dress the code up a little and post it later. Maybe even finally get the schematics done - I understand that charlieplexing code can be really difficult to read without looking at the schematics because so much depends on how the LEDs are connected.

Thanks again for the tips and the nice core: I now have another tool on my belt! (well, OK, chain  :D )

Cheers!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 29, 2012, 08:27 pm
I played some more with my ATtiny running the charlieplexing code trying to make it work from a 3V battery. If I understood the datasheet correctly, it should be able to work all the way down to 1.8V if the clock speed is below 1MHz. So I thought if I make use of the internal 128kHz oscillator, I should be fine.

Not so fast! (pun intended)  ;)

First of all, it was a rather dumb idea to begin with because the code depends very much on the delayMicroseconds() function and it ain't gonna be no microseconds if the internal clock is running at 128kHz, then gets divided by 8 (by default).  There's also a clock prescaler that further divides it by 8? I have to admit, I'm scraping the bottom of the barrel of my understanding of the hardware and it was a rather small barrel to begin with :)  So, is it then running at a whopping 2kHz clock speed if the suggested 0x7B low fuse is used?

Anyhow, it looks like the timer with 128kHz internal oscillator gets severely off, maybe because I was trying to make it run the above mentioned delayMicroseconds() command several thousand times per second and it just did not have enough clocks in the second to actually do that?

In addition to the timer issues that I'm still struggling with (if I use anything other than the default 9.6MHz osc., 1/8 clock prescaler it ships with) , there's a less obvious issue with 128kHz clock. Once you burn the fuse for 128kHz, you lose communication to the chip! This is pretty scary, especially if you are not prepared (and I wasn't :) ). The programmer is now running too fast for the chip to respond during ICSP programming and it pretty much plays dead. I did not see it mentioned here, and it may not be a feature of the IDE 0022 that smeezekitty tested with, but for IDE 1.0 I think the boards.txt record has to be changed (changes lifted from the other ATtiny core):

Code: [Select]

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

attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)
attiny13.upload.using=arduino:arduinoisp
# attiny13.upload.protocol=avrispv2
attiny13.upload.maximum_size=1024
attiny13.upload.speed=250
attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.unlock_bits=0x3F
attiny13.bootloader.lock_bits=0x3F
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=128000
attiny13.build.core=core13
###############################################################


note the attiny13.upload.speed=250 line - that should slow the programmer down enough.

Anyhow, getting back to the top of this post: I only messed with 128kHz trying to bring the Vcc down to 3V, and failed, even at 128kHz (never mind that the program did not run as expected because of timer issues anyhow). It only works from 5V supply.

Does anyone have any suggestions on how to make this chip run from a lower voltage? Oh, and I neglected to mention before: all ATtiny13 chips I have are labeled ATTINY13 20PU  - so are they ATtiny13 or ATtiny13A or does it even matter for the voltage supply?

Thanks!



Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on Feb 29, 2012, 09:10 pm
Quote
If I understood the datasheet correctly, it should be able to work all the way down to 1.8V...


Only if you have an ATtiny13V or ATtiny13A.  If you have a processor with no A or V in the model number then the minimum voltage is 2.7.

Which model do you have?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 29, 2012, 09:16 pm

I played some more with my ATtiny running the charlieplexing code trying to make it work from a 3V battery. If I understood the datasheet correctly, it should be able to work all the way down to 1.8V if the clock speed is below 1MHz. So I thought if I make use of the internal 128kHz oscillator, I should be fine.

This is correct.
In fact I can run it down to 1.3V.
[/quote]
First of all, it was a rather dumb idea to begin with because the code depends very much on the delayMicroseconds() function and it ain't gonna be no microseconds if the internal clock is running at 128kHz, then gets divided by 8 (by default).  There's also a clock prescaler that further divides it by 8? I have to admit, I'm scraping the bottom of the barrel of my understanding of the hardware and it was a rather small barrel to begin with :)  So, is it then running at a whopping 2kHz clock speed if the suggested 0x7B low fuse is used?
[/quote]
Not exactly.
With 0x7B fuse, the prescaler is off.
Furthermore, the core does not make use of the prescaler either. So the the clock is actually 128khz (actually anywhere from 100khz to 140khz).
For my perticular projects, the 128khz oscillator is highly desirable.
Quote

Anyhow, it looks like the timer with 128kHz internal oscillator gets severely off, maybe because I was trying to make it run the above mentioned delayMicroseconds() command several thousand times per second and it just did not have enough clocks in the second to actually do that?

Function overhead becomes a large issue on slow clock speeds. Even with the 1 MHz oscillator this can be a problem.
If you are using fixed values, you can use the _delay_us() function which is faster but is very large if you pass a variable parameter
Quote

In addition to the timer issues that I'm still struggling with (if I use anything other than the default 9.6MHz osc., 1/8 clock prescaler it ships with) , there's a less obvious issue with 128kHz clock. Once you burn the fuse for 128kHz, you lose communication to the chip! This is pretty scary, especially if you are not prepared (and I wasn't :) ). The programmer is now running too fast for the chip to respond during ICSP programming and it pretty much plays dead. I did not see it mentioned here, and it may not be a feature of the IDE 0022 that smeezekitty tested with, but for IDE 1.0 I think the boards.txt record has to be changed (changes lifted from the other ATtiny core):

Code: [Select]

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

attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)
attiny13.upload.using=arduino:arduinoisp
# attiny13.upload.protocol=avrispv2
attiny13.upload.maximum_size=1024
attiny13.upload.speed=250
attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.unlock_bits=0x3F
attiny13.bootloader.lock_bits=0x3F
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=128000
attiny13.build.core=core13
###############################################################


note the attiny13.upload.speed=250 line - that should slow the programmer down enough.

Many programmers are buggy and do not correctly implement slow SCK.
This is the fault of the programmer.
There is a Arduino ISP sketch that I wrote that correctly implements slow SCK that I use for programming my slow chips.
I will try to find the link in a few min.
Quote

Anyhow, getting back to the top of this post: I only messed with 128kHz trying to bring the Vcc down to 3V, and failed, even at 128kHz (never mind that the program did not run as expected because of timer issues anyhow). It only works from 5V supply.

I had no problem going down to 1.8 or even 1.3v.
Maybe the LEDs need higher voltage?
[/quote]
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Feb 29, 2012, 09:54 pm


Only if you have an ATtiny13V or ATtiny13A.  If you have a processor with no A or V in the model number then the minimum voltage is 2.7.

Which model do you have?



@Coding Badly: Mine's labeled ATTINY13 20PU, so I guess it's not an "A" after all. Still should work from a 3V battery, no?

@smeezekitty:
thanks for your input, I guess I got all confused with the combination of clocks and prescalers. It appears that all the way down to 128K may not work for my application anyway, but it's great to know that there's still ways to go in terms of lowering power consumption if the application allows for such slow speeds.

I've seen 1MHz and I believe 4MHz settings in your wiring.c file - what fuse settings would get me there? I've tried various combinations (all internal oscillators though - 128kHz, 9.6MHz and 4.8MHz) but none comes up to the exact figures in the wiring.c codes. How would it have to be changed in order to run properly at the speeds produced by internal  clocks? I think it would be important for wider acceptance of your cores because such a small part will probably be used without an external Xtal most of the time.

As far as the programming speed, I only tried AVRISP mkII so far and, when it knows to slow down, it talks to the chip fine.  So I would not call it a bug as much as it is just a necessary setting for comms with an MCU running at 128kHz internal clock.
I've reviewed my last night's notes and it looks like I've been burning it with 0x6B fuse, not 0x7B. That might explain why the timing was way off. I have to admit, once I realized that I won't get correct operation due to the use of delayMicroseconds(), I just went back to 9.6MHz and did not investigate further.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on Feb 29, 2012, 11:17 pm
Quote
@Coding Badly: Mine's labeled ATTINY13 20PU, so I guess it's not an "A" after all. Still should work from a 3V battery, no?


You should be fine.

The specifications are essentially guarantees.  Atmel guarantees that your processor works correctly at 2.7 volts / 4 MHz.  If the voltage is lowered or the frequency is increased, Atmel no longer guarantees correct operation.  In practical terms that means the more you exceed the limits the more likely the processor will not work correctly.

For all three models, the maximum guaranteed processor speed is 4 MHz at the minimum voltage (2.7 volts in your case, 1.8 volts for the other two).
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 01, 2012, 12:16 am



@smeezekitty:
thanks for your input, I guess I got all confused with the combination of clocks and prescalers. It appears that all the way down to 128K may not work for my application anyway, but it's great to know that there's still ways to go in terms of lowering power consumption if the application allows for such slow speeds.

I am not sure about the newest version of your code but it seems alittle in-precession may not make much difference in operation.
PWM is usually somewhat uncritical.
Quote

I've seen 1MHz and I believe 4MHz settings in your wiring.c file - what fuse settings would get me there? I've tried various combinations (all internal oscillators though - 128kHz, 9.6MHz and 4.8MHz) but none comes up to the exact figures in the wiring.c codes. How would it have to be changed in order to run properly at the speeds produced by internal  clocks? I think it would be important for wider acceptance of your cores because such a small part will probably be used without an external Xtal most of the time.

4 and 4.8mhz are not supported yet. I may work on that today.
As far as the internal oscillators support, 9.6Mhz currently uses the 8Mhz code.
For millis() I will probably add the proper division to increase accuracy.
The delay() code is conphensated inside avr-libc and nothing needs to be done.
For delayMilliseconds(), it uses a binary shift to multiply by 2. It actuality, it would need to be multiply by 2.4.
The problem is, multiplying by 2.4 would be significantly slower then shifting left by one.
The error is about 20%. I cannot really fix it very easily without risking making the error worse with calculation time.
Quote

As far as the programming speed, I only tried AVRISP mkII so far and, when it knows to slow down, it talks to the chip fine.  So I would not call it a bug as much as it is just a necessary setting for comms with an MCU running at 128kHz internal clock.
I've reviewed my last night's notes and it looks like I've been burning it with 0x6B fuse, not 0x7B. That might explain why the timing was way off. I have to admit, once I realized that I won't get correct operation due to the use of delayMicroseconds(), I just went back to 9.6MHz and did not investigate further.

That 0x6B could be a significant problem. 16khz is pretty slow.
As stated above, timing errors may or may not be a problem.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 01, 2012, 12:55 am
I uploaded a new version with support for 4MHz, 4.8Mhz and better support for 9.6MHz.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Mar 01, 2012, 01:05 am
Thanks, smeezekitty, I'm looking forward to trying what will come out for the slower internal clock speeds.

regarding this tho:
Quote
For millis() I will probably add the proper division to increase accuracy.

I tried to mess with  these lines in the the millis() code in your core:
Code: [Select]
#elif F_CPU == 1000000
x = ovrf / 4;


to make it look more like this (hopefully my math was correct):

Code: [Select]

#elif F_CPU == 1200000 /* 9.6MHz internal oscillator with sys clock divided by 8 (default) */
x = ovrf / 4.687; /*  1,200,000/256/1000  =  4.6875 overflows per millisecond */


And the result was that the compiled sketch became so big that it would no longer fit into the Flash (it added a whole 1kB if my memory serves) . It seems to really-really not like long type instead of int in this case. I'm honestly not sure what can you do about it: unless the clock speed is the exact amount in MHz, dividing it by a fractional number seems to really screw things up.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Pelletta on Mar 01, 2012, 01:09 am
Simply fantastic, thanks for sharing this project.
I have five Attiny13A and tomorrow morning I will try to use them.
I am not very expert on programming but you if need a tester, you have found it.
Greetings from Italy
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Mar 01, 2012, 01:10 am

I uploaded a new version with support for 4MHz, 4.8Mhz and better support for 9.6MHz.


Sorry, did not see your latest post before sending mine. I'll try that tonight.
Question though:
what would the boards.txt now look like? I've got so many versions already that I feel like I have to wipe everything and start afresh. Could you make the required boards.txt file a part of the package please?

Cheers!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 01, 2012, 02:01 am
Quote

And the result was that the compiled sketch became so big that it would no longer fit into the Flash (it added a whole 1kB if my memory serves) . It seems to really-really not like long type instead of int in this case. I'm honestly not sure what can you do about it: unless the clock speed is the exact amount in MHz, dividing it by a fractional number seems to really screw things up.

Thats because it pulls in the float point emulation library which is about 750 bytes!
You will have to divide by 5 which will still give you an error of less then 10%.
Remember the tolerance of the internal oscillator is only 5-25% tolerance anyway so you cannot really use it for precise timing anyway.
Quote

Simply fantastic, thanks for sharing this project.
I have five Attiny13A and tomorrow morning I will try to use them.
I am not very expert on programming but you if need a tester, you have found it.
Greetings from Italy

Thank you!
Quote

Sorry, did not see your latest post before sending mine. I'll try that tonight.
Question though:
what would the boards.txt now look like? I've got so many versions already that I feel like I have to wipe everything and start afresh. Could you make the required boards.txt file a part of the package please?

Just set F_CPU to equal your clock speed.
To be honest I don't understand boards.txt very well either.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Mar 01, 2012, 02:11 am
Code: [Select]
Just set F_CPU to equal your clock speed.
To be honest I don't understand boards.txt very well either.

OK, no prob. I'll try to get through all the clutter and come up with a reasonably clean boards.txt file containing the fuses and F_CPU values needed.  I see that you've added a few F_CPU options in wiring.c millis() function - those will need to be coordinated with the boards.txt file. Also, a proper boards.txt file will be needed to burn the fuses without leaving the Arduino IDE - that would be my personal preference - so I'll have to verify all the fuses I've played with so far.
Cheers!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: blackir on Mar 06, 2012, 08:31 pm
Thanks, smeezekitty,
I am blinking some LEDs here using Arduino 1.0 (Windows) with ATTINY13V-10PU, 8-bit microcontroller 10Mhz with 1Kb Flash.

Function delay (1000) which is 1 second duration lasts just over one second but for my use of ATtiny it suits me.
Here is my setup:

The smeezekitty's core had to be located at  "~/sketchbook/hardware/tiny/cores/core13/"

board.txt
Quote

attiny13.name=Attiny13
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000
attiny13.build.core=core13



~/sketchbook/hardware/arduino/codes/core13/Arduino.h
Quote

#ifndef Arduino_h
#define Arduino_h
#include <WProgram.h>
#endif



I noticed a problem in wiring.c, ";" was missing on line 32.
Quote

#elif F_CPU == 9600000
x = ovrf / 37;


Although technically a 10MHZ crystal is, I used the config to 9.6MHZ, it's probably just that the latency in the function delay ().
Avrdude back when a problem on behalf of the microcontroller, I had to change the line to put attiny13.build.mcu ATTINY13 the end, as above.

Can you open a page on sourceforge?


Great job, smeezekitty!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Mar 06, 2012, 10:46 pm
I played with Arduino 1.0 some more and then summarized the findings in a blog post here:  http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/ (http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/) There's a slightly different version of boards.txt file there.
In my case I simply copied the Arduino.h file from another core to make it version 1.0 - compatible ( it has the same content as blackir's though) - this was the only thing needed for 1.0 compatibility. In fact, I haven't noticed that many differences between 0022 and 1.0 while programming a "normal" Arduino. For ATtiny however, version 1.0 is much more comfortable because all functions specific to an MCU without bootloader are implemented inside the menus and there's no need to leave the IDE to do anything - burn fuses or load via programmer.

smeezekitty, if you haven't switched yet, definitely try 1.0.  Even just in general,  since we are talking about an open source, free software, I don't know if it makes any sense to support previous versions when it's so easy to upgrade (they can both co-exist).
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 07, 2012, 12:34 am

Thanks, smeezekitty,
I am blinking some LEDs here using Arduino 1.0 (Windows) with ATTINY13V-10PU, 8-bit microcontroller 10Mhz with 1Kb Flash.

Function delay (1000) which is 1 second duration lasts just over one second but for my use of ATtiny it suits me.
Here is my setup:

Thats because the the avr-libc delay function is too slow. I think I will re-implement it soon.
Quote

I noticed a problem in wiring.c, ";" was missing on line 32.
Quote

#elif F_CPU == 9600000
x = ovrf / 37;


Fixed in next release.
Quote

Although technically a 10MHZ crystal is, I used the config to 9.6MHZ, it's probably just that the latency in the function delay ().
Avrdude back when a problem on behalf of the microcontroller, I had to change the line to put attiny13.build.mcu ATTINY13 the end, as above.

I added a provision that should make millis() slightly more accurate on 10 and 12mhz crystals.
delayMicroseconds() will still be somewhat off which is *very* difficult to fix because I can only device and multiply by factors of two because I am using binary shifts for speed.
Quote

Can you open a page on sourceforge?

I was going to but got sidetracked. I think I may do that soon.
Quote

Great job, smeezekitty!

:)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 07, 2012, 12:51 am

I played with Arduino 1.0 some more and then summarized the findings in a blog post here:  http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/ (http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/) There's a slightly different version of boards.txt file there.

One thing is a bit wrong bit wrong:
Quote

So far I came across three different sets of libraries suitable for programming of ATtiny13 microcontrollers:

Actually, my core is the only one that supports the Attiny13. The other only support attiny25 and better from what I can tell.
It should be
Quote

So far I came across three different sets of libraries suitable for programming of ATtiny microcontrollers:

Quote

In my case I simply copied the Arduino.h file from another core to make it version 1.0 - compatible ( it has the same content as blackir's though) - this was the only thing needed for 1.0 compatibility.

This should be fixed in the newest release
Quote

This should be In fact, I haven't noticed that many differences between 0022 and 1.0 while programming a "normal" Arduino. For ATtiny however, version 1.0 is much more comfortable because all functions specific to an MCU without bootloader are implemented inside the menus and there's no need to leave the IDE to do anything - burn fuses or load via programmer.

smeezekitty, if you haven't switched yet, definitely try 1.0.  Even just in general,  since we are talking about an open source, free software, I don't know if it makes any sense to support previous versions when it's so easy to upgrade (they can both co-exist).

I guess I have heard too many horror stories

New release!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 07, 2012, 02:24 am
Inital source-forge page created:https://sourceforge.net/projects/ard-core13/
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Mar 07, 2012, 02:43 am

One thing is a bit wrong bit wrong:
Quote

So far I came across three different sets of libraries suitable for programming of ATtiny13 microcontrollers:

Actually, my core is the only one that supports the Attiny13. The other only support attiny25 and better from what I can tell.
It should be
Quote

So far I came across three different sets of libraries suitable for programming of ATtiny microcontrollers:

Good catch, smeezekitty. Yes, the wording of that paragraph is wrong. Damellis'es ATtiny core can actually be adapted for ATtiny13 and he posted a mini how-to on that. But the other one seems to have abandoned the 13 in exchange for support of the SoftwareSerial library (useful for chips with no UART). I shall go change that!   :smiley-mr-green:
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: blackir on Mar 07, 2012, 10:03 am
Hy,

Thank you for changes.
I noticed a problem in wiring.c (core13_0_135), ";" was missing on line 28.
Quote

Correction :
#elif F_CPU == 4000000
x = ovrf / 16;


I noticed a problem in wiring.c (core13_0_135), "12000000" was replaced by "10000000" on line 58.
Quote

Correction :
#if F_CPU == 16000000 || F_CPU == 12000000


After corrections, core13_0_135 work well.

Thanks, smeezekitty!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Bobnova on Mar 07, 2012, 06:00 pm
Seeing this makes me very happy, now I can order some incredibly cheap chips to play with.
Thank you!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 07, 2012, 09:19 pm

Hy,

Thank you for changes.
I noticed a problem in wiring.c (core13_0_135), ";" was missing on line 28.
Quote

Correction :
#elif F_CPU == 4000000
x = ovrf / 16;


I noticed a problem in wiring.c (core13_0_135), "12000000" was replaced by "10000000" on line 58.
Quote

Correction :
#if F_CPU == 16000000 || F_CPU == 12000000


After corrections, core13_0_135 work well.

Thanks, smeezekitty!

To be honest, I never compiled this for speeds other then 128khz and 1Mhz so those errors are hard to find.
Quote

Seeing this makes me very happy, now I can order some incredibly cheap chips to play with.
Thank you!

Thats primarily why I started this project.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: blackir on Mar 13, 2012, 03:35 pm
hello,

I found a bookstore that uses a library ATTINY13 for ATtiny 8.
I forwarded this can still be useful:

located at  "~/sketchbook/hardware/attiny/"

~/sketchbook/hardware/attiny/board.txt
Quote

attiny13.name=ATtiny13 (internal 9.6 MHz clock)
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff
attiny13.upload.maximum_size=1024
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000L
attiny13.build.core=arduino:arduino
attiny13.build.variant=tiny8


~/sketchbook/hardware/attiny/variants/tiny8/pins_arduino.h
Quote

/*
  pins_arduino.c - pin definitions for the Arduino board
  Part of Arduino / Wiring Lite

  Copyright (c) 2005 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $

  Modified 28-08-2009 for attiny84 R.Wiersma
  Modified 09-10-2009 for attiny45 A.Saporetti
*/

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

// ATMEL ATTINY45 / ARDUINO
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

#define digitalPinToPCICR(p)    ( ((p) >= 0 && (p) <= 4) ? (&GIMSK) : ((uint8_t *)0) )
#define digitalPinToPCICRbit(p) ( PCIE )
#define digitalPinToPCMSK(p)    ( ((p) <= 4) ? (&PCMSK) : ((uint8_t *)0) )
#define digitalPinToPCMSKbit(p) ( (p) )

#ifdef ARDUINO_MAIN

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing) tiny45 only port B
const uint16_t PROGMEM port_to_mode_PGM[] = {
   NOT_A_PORT,
   NOT_A_PORT,
   (uint16_t) &DDRB,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
   NOT_A_PORT,
   NOT_A_PORT,
   (uint16_t) &PORTB,
};

const uint16_t PROGMEM port_to_input_PGM[] = {
   NOT_A_PIN,
   NOT_A_PIN,
   (uint16_t) &PINB,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
   PB, /* 0 */
   PB,
   PB,
   PB,
   PB,
   PB, // 5
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
   _BV(0), /* 0, port B */
   _BV(1),
   _BV(2),
   _BV(3), /* 3, port B */
   _BV(4),
   _BV(5),
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
   TIMER0A, /* OC0A */
   TIMER0B,
   NOT_ON_TIMER,
   NOT_ON_TIMER,
   NOT_ON_TIMER,
   NOT_ON_TIMER,
};

#endif

#endif


bye
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 14, 2012, 07:54 pm

hello,

I found a bookstore that uses a library ATTINY13 for ATtiny 8.

I've never heard of an Attiny8.
Quote

/*
  pins_arduino.c - pin definitions for the Arduino board
  Part of Arduino / Wiring Lite

  Copyright (c) 2005 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: pins_arduino.c 565 2009-03-25 10:50:00Z dmellis $

  Modified 28-08-2009 for attiny84 R.Wiersma
  Modified 09-10-2009 for attiny45 A.Saporetti
*/

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

// ATMEL ATTINY45 / ARDUINO
//
//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

#define digitalPinToPCICR(p)    ( ((p) >= 0 && (p) <= 4) ? (&GIMSK) : ((uint8_t *)0) )
#define digitalPinToPCICRbit(p) ( PCIE )
#define digitalPinToPCMSK(p)    ( ((p) <= 4) ? (&PCMSK) : ((uint8_t *)0) )
#define digitalPinToPCMSKbit(p) ( (p) )

#ifdef ARDUINO_MAIN

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing) tiny45 only port B
const uint16_t PROGMEM port_to_mode_PGM[] = {
   NOT_A_PORT,
   NOT_A_PORT,
   (uint16_t) &DDRB,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
   NOT_A_PORT,
   NOT_A_PORT,
   (uint16_t) &PORTB,
};

const uint16_t PROGMEM port_to_input_PGM[] = {
   NOT_A_PIN,
   NOT_A_PIN,
   (uint16_t) &PINB,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
   PB, /* 0 */
   PB,
   PB,
   PB,
   PB,
   PB, // 5
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
   _BV(0), /* 0, port B */
   _BV(1),
   _BV(2),
   _BV(3), /* 3, port B */
   _BV(4),
   _BV(5),
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
   TIMER0A, /* OC0A */
   TIMER0B,
   NOT_ON_TIMER,
   NOT_ON_TIMER,
   NOT_ON_TIMER,
   NOT_ON_TIMER,
};

#endif

#endif

The problem with this is those tables take alot of memory if you are developing for one chip. And on the ATtiny13, you need all the memory you can get.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Bobnova on Mar 31, 2012, 04:56 am
Finally got around to testing this!  Took a bit.

So far I've only run into two very minor issues:

1) I have attiny13 chips rather than attiny13a, or at least that is what my USBtinyISP wanted me to say I had in the boards file. (I had to edit the boards file to say what I'm using to upload of course, that is to be expected)  This was an easy fix for me, just deleted the a and presto!

2) My Attiny13 chips have a default clock of 1MHz on the internal oscillator rather than 128kHz.  Again an easy fix in the boards file.

That's it so far!
Thanks for your work, now I can play with $1.13 MCUs instead of those big expensive $2.26 attiny85 chips :D
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Mar 31, 2012, 05:38 am

Thanks for your work, now I can play with $1.13 MCUs instead of those big expensive $2.26 attiny85 chips :D

It's the effort needed to squeeze everything you need into a smaller box, so to speak, that makes it all the more fun.   :D For a one-of hobby project the difference between $1.13 and $11.30 is not even all that important. But knowing that you did not use a chip larger than absolutely required (in resources, not even necessarily price) could be.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 31, 2012, 05:52 am

Finally got around to testing this!  Took a bit.

So far I've only run into two very minor issues:

1) I have attiny13 chips rather than attiny13a, or at least that is what my USBtinyISP wanted me to say I had in the boards file. (I had to edit the boards file to say what I'm using to upload of course, that is to be expected)  This was an easy fix for me, just deleted the a and presto!

2) My Attiny13 chips have a default clock of 1MHz on the internal oscillator rather than 128kHz.  Again an easy fix in the boards file.

That's it so far!
Thanks for your work, now I can play with $1.13 MCUs instead of those big expensive $2.26 attiny85 chips :D

The boards.txt was just a clobbered together example. I will be honest, I do not understand the boards.txt very well.
Quote

It's the effort needed to squeeze everything you need into a smaller box, so to speak, that makes it all the more fun.   smiley-grin For a one-of hobby project the difference between $1.13 and $11.30 is not even all that important. But knowing that you did not use a chip larger than absolutely required (in resources, not even necessarily price) could be.

Yes, exactly. Getting by with minimum resources is a fun challenge.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Bobnova on Apr 01, 2012, 07:46 am
It looks (from the fuses) like the default clock speed is 1.2MHz (9.6MHz internal RC clock divided by 8), so 1200000L in place of 128000L will fix that.
I can only speak for my chips and my usbtinyisp, but despite the chip having Attiny13A printed on it avrdude and the usbtinyisp wanted to see attiny13 called.

I've been enjoying myself with this thing so far, thanks again :D

My only project that I actually sell and have to buy chips for requires the attiny85's oddball timer1, but I like the concept of working on efficiency and already have a couple projects in mind that should fit quite nicely and require a MCU for long term deployment.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Apr 01, 2012, 09:55 am

I can only speak for my chips and my usbtinyisp, but despite the chip having Attiny13A printed on it avrdude and the usbtinyisp wanted to see attiny13 called.

avr-dude is somewhat of a fuss-pot as far as chip naming goes.
Quote

It looks (from the fuses) like the default clock speed is 1.2MHz (9.6MHz internal RC clock divided by smiley-cool, so 1200000L in place of 128000L will fix that.

I am fairly certain the fuses are correct but most people won't want to run it at 128khz.
I happen to need operability down to 1.6v and very low power consumption so the 128khz clock is a good choice for most of my projects.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Pelletta on Jul 05, 2012, 02:45 pm
Hi all, I'm doing tests with attiny13a and I see that delay function is not very accurate; i set the fuse to work at 9.6MHz, 1.2MHz and 128KHz but I have the same problem, for example the sketch "blink" set with delay(10000) makes the led blinking in 14 seconds instead of 10.
There is a way to fix this?
I tell you the low fuse I am using:
9.6MHz   0x7A
1.2MHz   0x6A
128KHz   0x7B
Thank you and greetings from Italy
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Jul 05, 2012, 03:09 pm
There is a whole lot of rounding up/down going on in this core for the sake of avoiding floating point calculations. I think this is what contributes to the difference.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 06, 2012, 07:35 am

Hi all, I'm doing tests with attiny13a and I see that delay function is not very accurate; i set the fuse to work at 9.6MHz, 1.2MHz and 128KHz but I have the same problem, for example the sketch "blink" set with delay(10000) makes the led blinking in 14 seconds instead of 10.
There is a way to fix this?
I tell you the low fuse I am using:
9.6MHz   0x7A
1.2MHz   0x6A
128KHz   0x7B
Thank you and greetings from Italy

The delay() function tends to create a delay that is somewhat longer then is desired. I will work on tuning it in the future.
That said a 40% increase is far in excess of what I measured, but I never really tried it with long delays.
I will work on it soon.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: malukens on Jul 10, 2012, 09:18 am
smeezekitty,
This forum is awesome.  I'm really new to Arduino and a complete newbie to programming microcontrollers.  After I  got your core13 and boards.txt uploaded and installed correctly and actually read the "Arduino as ISP" instructions closely enough to properly setup my Uno as an ISP, I finally got my ATtiny13A-10PU to obediently blink on pin PB0.  Turns out I can get any of the five digital outputs (PB0, PB1, PB2, PB3 and PB4) to blink.  What I can't do is get any of the ADC's to read an analog signal.  I'm using code that runs great on my Arduino but I obviously either don't know how to address the ADC port or there is something beyond my knowledge as to how to tell the Arduino_as_ISP or the ATtiny which ports should be digital I/O and which ones should be analog inputs.

I am selecting this entry from boards.txt:
##############################################################
attiny13.name=Attiny 13A standalone
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x7A
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13a
attiny13.build.f_cpu=1000000L
attiny13.build.core=core13
##############################################################


****************************************************
The sketch I'm trying to run is:
/*
  Blink_Core13
  Turns on an LED on for one second, then off for one second, repeatedly.
*/

void setup() {               
  // setup Pin 5 (PB0) as a digital output
  pinMode(0, OUTPUT);     
}

void loop() {
  digitalWrite(0, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(0, LOW);    // set the LED off
  delay(1000);              // wait for a second
 
  //  read the pot value on Pin 2 (PB3/ADC3)
  int potValue = analogRead(3);
}

****************************************************
I have a potentiometer that I have used on other projects hooked up but when I run the program the LED on PB0 blinks once and then hangs.  If I comment out the analogRead line it blinks forever.  I have searched online for several hours but I am unable to find any examples where someone actually shows how to configure, test and verify using one of the ADCx ports on the ATtiny13/24/44/84/25/45/85/...

I suspect that I need to somehow set or override the PORTB, DDRB or PINB settings but I am at a loss as to how to do that.  I'm hoping someone (or everyone) out there knows exactly how to do it and can point me in the right direction.  Thanks
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 10, 2012, 09:44 am

smeezekitty,
This forum is awesome.  I'm really new to Arduino and a complete newbie to programming microcontrollers.  After I  got your core13 and boards.txt uploaded and installed correctly and actually read the "Arduino as ISP" instructions closely enough to properly setup my Uno as an ISP, I finally got my ATtiny13A-10PU to obediently blink on pin PB0.  Turns out I can get any of the five digital outputs (PB0, PB1, PB2, PB3 and PB4) to blink.  What I can't do is get any of the ADC's to read an analog signal.  I'm using code that runs great on my Arduino but I obviously either don't know how to address the ADC port or there is something beyond my knowledge as to how to tell the Arduino_as_ISP or the ATtiny which ports should be digital I/O and which ones should be analog inputs.

<snip>


****************************************************
I have a potentiometer that I have used on other projects hooked up but when I run the program the LED on PB0 blinks once and then hangs.  If I comment out the analogRead line it blinks forever.  I have searched online for several hours but I am unable to find any examples where someone actually shows how to configure, test and verify using one of the ADCx ports on the ATtiny13/24/44/84/25/45/85/...

This could be a bug and I will investigate it. In the mean time, does it hang even if you try other pins? (try them all, even the non-ADC ones).

I think it is almost certainly hanging on the ADC wait loop on line 16 of wiring_analog.c. But I do not know why.
I will have to debug it (which on an embedded platform is quite a challenge)
Quote

I suspect that I need to somehow set or override the PORTB, DDRB or PINB settings but I am at a loss as to how to do that.  I'm hoping someone (or everyone) out there knows exactly how to do it and can point me in the right direction.  Thanks


That should not be necessary. The core should setup all the registers and ports correctly on initialization.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 10, 2012, 07:09 pm
There is an unusual bug.
The code operates perfectly without hanging and the ADC reads correctly with the clock at 128 KHz but it fails at any faster settings.
Further debugging will be necessary.

BTW I always bricked one chip while debugging by setting HFUSE instead of LFUSE Arghh...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: malukens on Jul 12, 2012, 06:41 am
I'll test the ADCx on all of the other ports at 9.6MHz and I'll also try them at 128KHz.  I need to measure times intervals in the microsecond range so I wasn't sure the micro() command would even work at the slower clock speeds.  I'll let you know what I discover as soon as I get some bench time.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 12, 2012, 08:47 pm

I need to measure times intervals in the microsecond range so I wasn't sure the micro() command would even work at the slower clock speeds.  I'll let you know what I discover as soon as I get some bench time.

Uhm... This could be a bit of a problem. micros() is not completely implemented because I am still devising a way to make it small. This means micros() is highly inaccurate and probably will not do what you expect.

I apologize for this and I will look for a solution soon. You may need to devise a different method of measurement (like pulse counting?)

Also it is true that timing will be somewhat inaccurate at slow clock speeds, but the internal oscillator is not all that accurate anyway (probably between 2% and 10% off).
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: tartakynov on Jul 17, 2012, 08:10 am
Hello everybody!
I've got 2 questions:
1. Is the internal clock frequency correlated to the battery voltage? In other words - is "delay(1000)" on 3V battery actually longer than "delay(1000)" on 5V?
2. Who ever used analogRead or digitalRead functions on ATtiny13? Is it possible? My chip (ATtiny13A-20PU) hangs when I call these functions, so I can't run this simple primer:
Code: [Select]

void setup()
{
     pinMode(0, OUTPUT);
     pinMode(A2, INPUT);
}

void loop()
{
     int v = analogRead(A2);
     digitalWrite(0, HIGH);
     delay(v);
     digitalWrite(0, LOW);
     delay(v);
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 17, 2012, 08:16 am

Hello everybody!
I've got 2 questions:
1. Is the internal clock frequency correlated to the battery voltage? In other words - is "delay(1000)" on 3V battery actually longer than "delay(1000)" on 5V?

Yes and no. The clock frequency of the internal oscillator does vary with voltage but it seems to go slightly faster on lower supply voltages.
Quote

2. Who ever used analogRead or digitalRead functions on ATtiny13? Is it possible? My chip (ATtiny13A-20PU) hangs when I call these functions, so I can't run this simple primer:
Code: [Select]

void setup()
{
     pinMode(0, OUTPUT);
     pinMode(A2, INPUT);
}

void loop()
{
     int v = analogRead(A2);
     digitalWrite(0, HIGH);
     delay(v);
     digitalWrite(0, LOW);
     delay(v);
}


This is a bug with the analogRead() code (see above) - I am investigating a solution.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: tartakynov on Jul 17, 2012, 08:40 am
Thanks, I've modified analogRead function in wiring_analog.c and it helped (you can see the code below), but now I'm getting very unstable signal from sensor and don't know yet where is the problem

Code: [Select]

//                 +-\/-+
// ADC0 (D 5) PB5 1|    |8 Vcc
// ADC3 (D 3) PB3 2|    |7 PB2 (D 2) ADC1
// ADC2 (D 4) PB4 3|    |6 PB1 (D 1) PWM1
//            GND 4|    |5 PB0 (D 0) PWM0
//                 +----+
int analogRead(uint8_t pin){
uint8_t l,h;
ADMUX |= (1 << ADLAR) | (pin & 7); //Setup ADC
ADCSRA |= (1 << ADEN)| // Analog-Digital enable bit
(1 << ADPS1)| // set prescaler to 8 (clock / 8)
(1 << ADPS0); // set prescaler to 8 (clock / 8)
ADCSRA |= (1 << ADEN); // Analog-Digital enable bit
ADCSRA |= (1 << ADSC); // Discard first conversion
while (ADCSRA & (1 << ADSC)); // wait until conversion is done
ADCSRA |= (1 << ADSC); // start single conversion
while (ADCSRA & (1 << ADSC)); // wait until conversion is done
ADCSRA &= ~(1<<ADEN); // shut down the ADC
l = ADCL;  //Read and return 10 bit result
h = ADCH;
return (h<<8) | l;
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Pelletta on Jul 19, 2012, 12:07 am
Hi guys, I'm trying to use the ledControl library for the MAX7219 led driver but the sketch does not complile.
After a little search I've found that variables of this kind
Code: [Select]
B01111110
are not recognized.
No problems with ATtiny85/84/2313 core.
Do you know if it is easy to fix this?
If it may be usefull I am using IDE 0022 under kubuntu 11.04.
Thanks.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 19, 2012, 12:38 am

Hi guys, I'm trying to use the ledControl library for the MAX7219 led driver but the sketch does not complile.
After a little search I've found that variables of this kind
Code: [Select]
B01111110
are not recognized.
No problems with ATtiny85/84/2313 core.
Do you know if it is easy to fix this?
If it may be usefull I am using IDE 0022 under kubuntu 11.04.
Thanks.

This is non-standard C. change it to 0B01111110 and it should work.
----edit----
Edit, FWIW this is also non-standard C but is support by gcc which is what is used for Arduino.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 19, 2012, 03:49 am

Thanks, I've modified analogRead function in wiring_analog.c and it helped (you can see the code below), but now I'm getting very unstable signal from sensor and don't know yet where is the problem

Code: [Select]

//                 +-\/-+
// ADC0 (D 5) PB5 1|    |8 Vcc
// ADC3 (D 3) PB3 2|    |7 PB2 (D 2) ADC1
// ADC2 (D 4) PB4 3|    |6 PB1 (D 1) PWM1
//            GND 4|    |5 PB0 (D 0) PWM0
//                 +----+
int analogRead(uint8_t pin){
uint8_t l,h;
ADMUX |= (1 << ADLAR) | (pin & 7); //Setup ADC
ADCSRA |= (1 << ADEN)| // Analog-Digital enable bit
(1 << ADPS1)| // set prescaler to 8 (clock / 8)
(1 << ADPS0); // set prescaler to 8 (clock / 8)
ADCSRA |= (1 << ADEN); // Analog-Digital enable bit
ADCSRA |= (1 << ADSC); // Discard first conversion
while (ADCSRA & (1 << ADSC)); // wait until conversion is done
ADCSRA |= (1 << ADSC); // start single conversion
while (ADCSRA & (1 << ADSC)); // wait until conversion is done
ADCSRA &= ~(1<<ADEN); // shut down the ADC
l = ADCL;  //Read and return 10 bit result
h = ADCH;
return (h<<8) | l;
}


This code looks overcomplicated.
How are you testing the sensor readings?
I will investigate soon.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: tartakynov on Jul 19, 2012, 05:46 am
Quote

How are you testing the sensor readings?

changing led brightness on the sensor readings, when I do so the led is blinking randomly.
I assume that the problem actually is on analogWrite function, because when I sent half power signal to my arduino board by "analogWrite(PIN, 64);"
I expected to see values near 512 on my Arduino but I got 1023
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 19, 2012, 05:49 am

Quote

How are you testing the sensor readings?

changing led brightness on the sensor readings, when I do so the led is blinking randomly.
I assume that the problem actually is on analogWrite function, because when I sent half of the power signal to my arduino board by "analogWrite(PIN, 64);"
I expected to see values near 512 on my Arduino but I got 1023

PWM works fine for me. Many meters will not read PWM correctly. Can you try the fading example?
Also I used a variable blink rate to check the adc output.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: tartakynov on Jul 19, 2012, 06:07 am
Yes sure, I'll run it tonight when I'll be at home :) It will be great if you could open issue tracker on sourceforge to discuss specific issues on their own threads
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 19, 2012, 06:25 am

Yes sure, I'll run it tonight when I'll be at home :) It will be great if you could open issue tracker on sourceforge to discuss specific issues on their own threads


Are you using the Arduino ADC to read the PWM directly? If so, that is not correct.
You need to low pass filter it. Feed the PWM pin into a capacitor between 0.1uf and 1uf through a resistor between 220 ohms and 1k (values are fairly uncritical for testing)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: etatoby on Aug 13, 2012, 11:43 am
Hi

Thank you for writing core13, I've been trying it out on an ATtiny13A, using my Uno as programmer.
It's very easy to use and everything I need is supported!
I've even built a handy ATtiny Programmer Shield, but that's a topic for another post.

Problem is, whatever I do I can't get it to run at the right clock speed.
It's either .74x too slow, when running at 9.6MHz, or 1.43x too fast, when running at 4.8MHz.

Can you help me fix the issue?

I'm using core13_014 from Sourceforge. Here is my boards.txt:

Code: [Select]
attiny13at4.name=ATtiny13 @ 4.8MHz
# 1.43x too fast
attiny13at4.upload.using=arduino:arduinoisp
attiny13at4.upload.maximum_size=1024
attiny13at4.upload.speed=19200
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13

attiny13at9.name=ATtiny13 @ 9.6MHz
# .74x too slow
attiny13at4.upload.using=arduino:arduinoisp
attiny13at4.upload.maximum_size=1024
attiny13at4.upload.speed=19200
attiny13at9.bootloader.low_fuses=0x6a
attiny13at9.bootloader.high_fuses=0xff
attiny13at9.build.mcu=attiny13
attiny13at9.build.f_cpu=1200000
attiny13at9.build.core=core13
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Tom Carpenter on Aug 13, 2012, 12:16 pm
For a starter, there is this line:
Code: [Select]
attiny13at4.build.f_cpu=600000
If it is 4.8MHz, this should be 4800000.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 14, 2012, 02:50 am
Code: [Select]
[quote author=whatfireflies link=topic=89781.msg890760#msg890760 date=1344851025]
Hi

Thank you for writing core13, I've been trying it out on an ATtiny13A, using my Uno as programmer.
It's very easy to use and everything I need is supported!
I've even built a handy ATtiny Programmer Shield, but that's a topic for another post.

Problem is, whatever I do I can't get it to run at the right clock speed.
It's either .74x too slow, when running at 9.6MHz, or 1.43x too fast, when running at 4.8MHz.

Can you help me fix the issue?

I'm using core13_014 from Sourceforge. Here is my boards.txt:

[code]attiny13at4.name=ATtiny13 @ 4.8MHz
# 1.43x too fast
attiny13at4.upload.using=arduino:arduinoisp
attiny13at4.upload.maximum_size=1024
attiny13at4.upload.speed=19200
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13

attiny13at9.name=ATtiny13 @ 9.6MHz
# .74x too slow
attiny13at4.upload.using=arduino:arduinoisp
attiny13at4.upload.maximum_size=1024
attiny13at4.upload.speed=19200
attiny13at9.bootloader.low_fuses=0x6a
attiny13at9.bootloader.high_fuses=0xff
attiny13at9.build.mcu=attiny13
attiny13at9.build.f_cpu=1200000
attiny13at9.build.core=core13

[/quote]
Wow all the support requests come in at the same time.

This is a known bug. It currently relies on the library implementation of delay() which works poorly.
Try replacing the wiring.c delay with this somewhat larger but more accurate code:
Code: [Select]

void delay(unsigned ms){
unsigned s = millis();
while(millis()-s < ms);
}

[/quote]
The millis() implementation should always be within 15%. But remember the internal clock can be off by 10% or more worst case. Very precise timing on a device with limited flash and a marginal clock source is nearly impossible.[/code]
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 14, 2012, 05:16 am
***New version***
Version 0.15 released which fixes the nasty intermittent analogRead() hang!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: etatoby on Aug 14, 2012, 11:18 am
Code: [Select]

#elif F_CPU == 1200000 /* 9.6MHz internal oscillator with sys clock divided by 8 (default) */
x = ovrf / 4.687; /*  1,200,000/256/1000  =  4.6875 overflows per millisecond */


If you need to divide by 4.687 without using floating point, you can use any of the "best rational approximations" of the number, to the precision required:

4.687 = 5 ± 6.7%
4.687 = 14/3 ± 0.4%
4.687 = 75/16 ± 0.01%
4.687 = 539/115 ± 0.001%
. . .

For example, choosing the ±0.01% value:

x = ovrf * 16 / 75;

Just remember to do the multiplication before the division, because the division truncates, and not to use too large a multiplication as to cause overflow. (If times 16 is too much in this case, you could use 14/3 ± 0.4% and only multiply by 3.)

I have attached a Python program to compute these fractions for a given floating number, based on this example (http://www.daniweb.com/software-development/python/code/223956/best-rational-approximations-of-a-float).

smeezekitty: maybe you could use this trick to increase the precision of millis()?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: etatoby on Aug 14, 2012, 11:43 am
Thank you for the delay() workaround smeezekitty, and for the updated files. Will try ASAP.


Hi all, I'm doing tests with attiny13a and I see that delay function is not very accurate; i set the fuse to work at 9.6MHz, 1.2MHz and 128KHz but I have the same problem, for example the sketch "blink" set with delay(10000) makes the led blinking in 14 seconds instead of 10.


14 seconds instead of 10 looks a lot like my measurement of 0.74x too slow. But I was using the wrong fuses, so I will have to redo my timing measurements. Here is a reference for low_fuses in boards.txt, just in case others find it as confusing as I do:

0x69 = 4.8MHz / 8 = 0.6MHz
0x6a = 9.6MHz / 8 = 1.2MHz
0x79 = 4.8MHz
0x7a = 9.6MHz
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 14, 2012, 07:42 pm

Code: [Select]

#elif F_CPU == 1200000 /* 9.6MHz internal oscillator with sys clock divided by 8 (default) */
x = ovrf / 4.687; /*  1,200,000/256/1000  =  4.6875 overflows per millisecond */


If you need to divide by 4.687 without using floating point, you can use any of the "best rational approximations" of the number, to the precision required:

4.687 = 5 ± 6.7%
4.687 = 14/3 ± 0.4%
4.687 = 75/16 ± 0.01%
4.687 = 539/115 ± 0.001%
. . .

For example, choosing the ±0.01% value:

x = ovrf * 16 / 75;

Just remember to do the multiplication before the division, because the division truncates, and not to use too large a multiplication as to cause overflow. (If times 16 is too much in this case, you could use 14/3 ± 0.4% and only multiply by 3.)

I have attached a Python program to compute these fractions for a given floating number, based on this example (http://www.daniweb.com/software-development/python/code/223956/best-rational-approximations-of-a-float).

smeezekitty: maybe you could use this trick to increase the precision of millis()?

Note you do have to watch flash use very carefully to maximize the space available for the main program.
6.7% is not really an unreasonable for an attiny chip and obviously not the biggest error.
Nonetheless I will probably try your method while watching flash usage.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 15, 2012, 05:09 pm
I have read this and several other posts on programing an ATtiny13 (13A in my case).
I have owned an Arduino Uno R3 for about a week so be prepared for nube questions. I have been searching the web and have seen several tutorials that refer to using the arduino as an ISP but then go on to use something else to actually program the ATtiny so I am a bit lost. If there is aArduino ISP ATtiny programing for dummies pleas provide a link :smiley-roll:
I have the latest version of core 13_014 installed as follows C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13. I have seen at least three different boards.txt modifications in this thread, which one should I use???
I see use a bootloader then statements that the ATtiny can't ???

I understand the pin assignments have to be changed to match the ATtiny but at the moment I need to figure out how to get the ISP to communicate with the MCU without generating numerous error messages. this is what I get when attempting upload arduinoISP from the examples

C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp: In function 'int main()':
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:11: error: 'init' was not declared in this scope
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:12: error: 'setup' was not declared in this scope
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:13: error: 'loop' was not declared in this scope

Attempting to run tools/burn bootloader produces

avrdude: stk500_getsync(): not in sync: resp=0x00

.1uf capacitor between reset and ground does not have any effect.

Here is the code I have hacked and would like to have my ATtiny execute, strobes and anti collision lights for an RC aircraft.
Code: [Select]
/*
  Blink
  Turns on an LED on for three 250 ms blinks, then off for one second, repeatedly.

  This example code is in the public domain.
*/


// give it a name:
int led = 13;
int ledpin = 10;
int fadePin = 9;
// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT); 
  pinMode(ledpin, OUTPUT);
 
}

// the loop routine runs over and over again forever:
void loop() {

 
  digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for a second
  digitalWrite(led, LOW);
  digitalWrite(ledpin, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);       
  digitalWrite(ledpin, LOW);
  digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 14 second
  digitalWrite(led, LOW);
  digitalWrite(ledpin, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);
  digitalWrite(ledpin, LOW);
  digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 1/4 second
  digitalWrite(led, LOW);
  digitalWrite(ledpin, HIGH);
  delay(100);
  digitalWrite(ledpin, LOW);   // turn the LED off by making the voltage LOW
                               // turn the LED off by making the voltage LOW
  delay(100);                 // wait for a second
 



  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(20);                           
  }
}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 15, 2012, 07:16 pm
After hours spent getting errors I have discovered that using the files in core 13_014 and core 13_015 do not work with my UNO R3. Something in the instruction set points to invalid functions causing the Uno to not accept any new instructions. I have modified #include "WProgram.h" per the instructions in  Read this before posting a programming question ...  still no luck.
I have verified this issue by deleting the core13 folder and uploading the blink example and my altered version posted above which would not upload previously. Now both sketches are working just fine on the Uno and bread board with resistors & LEDs installed.
Can anyone verify that the file set provided actually works with an Uno R3 with an ATMEGA328P-PU and software ver arduino-1.0.1 or provide instructions on how to modify the code to work properly?
I am running Win Vista home basic with SP2
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 15, 2012, 10:33 pm
Let me first suggest going here: http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/

I have read this and several other posts on programing an ATtiny13 (13A in my case).
I have owned an Arduino Uno R3 for about a week so be prepared for nube questions. I have been searching the web and have seen several tutorials that refer to using the arduino as an ISP but then go on to use something else to actually program the ATtiny so I am a bit lost. If there is aArduino ISP ATtiny programing for dummies pleas provide a link :smiley-roll:

I haven't had any problems using my Duemillanove to program an Attiny13A and I have head that the Uno R3 works fine as an ISP but I do not have one to try it.
Quote

I have the latest version of core 13_014 installed as follows C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13. I have seen at least three different boards.txt modifications in this thread, which one should I use???

The boards.txt file is a confusing creature.
This works for me:
Code: [Select]

attiny13.name=Attiny 13A standalone
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x6A
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000L
attiny13.build.core=core13

Quote

I see use a bootloader then statements that the ATtiny can't ???

The attiny13 is too small to support a bootloader so the upload bootloader command only burns the fuses. It should not be strictly necessary but it may run the wrong clock speed if you do not.
Quote

I understand the pin assignments have to be changed to match the ATtiny but at the moment I need to figure out how to get the ISP to communicate with the MCU without generating numerous error messages.

Changing pin assignments is trivial once it is working.
Quote

this is what I get when attempting upload arduinoISP from the example

C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp: In function 'int main()':
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:11: error: 'init' was not declared in this scope
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:12: error: 'setup' was not declared in this scope
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:13: error: 'loop' was not declared in this scope

The files on your system should be located in C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13.
You have them one directory too deep.
Quote

Attempting to run tools/burn bootloader produces

avrdude: stk500_getsync(): not in sync: resp=0x00

Ensure the ArduinoISP sketch is installed properly and recheck your wiring. In any case, we will deal with these errors once we get rid of the compiler errors.
Quote

.1uf capacitor between reset and ground does not have any effect.

Ensure the capacitor is disconnected when uploading to the Arduino and connected when uploading to the attiny.
Quote

Here is the code I have hacked and would like to have my ATtiny execute, strobes and anti collision lights for an RC aircraft.
Code: [Select]
/*
 Blink
 Turns on an LED on for three 250 ms blinks, then off for one second, repeatedly.

 This example code is in the public domain.
*/


// give it a name:
int led = 13;
int ledpin = 10;
int fadePin = 9;
// the setup routine runs once when you press reset:
void setup() {                
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT);  
 pinMode(ledpin, OUTPUT);
 
}

// the loop routine runs over and over again forever:
void loop() {

 
 digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
 delay(100);                  // wait for a second
 digitalWrite(led, LOW);
 digitalWrite(ledpin, HIGH);  // turn the LED off by making the voltage LOW
 delay(100);      
 digitalWrite(ledpin, LOW);
 digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
 delay(100);                  // wait for 14 second
 digitalWrite(led, LOW);
 digitalWrite(ledpin, HIGH);  // turn the LED off by making the voltage LOW
 delay(100);
 digitalWrite(ledpin, LOW);
 digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
 delay(100);                  // wait for 1/4 second
 digitalWrite(led, LOW);
 digitalWrite(ledpin, HIGH);
 delay(100);
 digitalWrite(ledpin, LOW);   // turn the LED off by making the voltage LOW
                              // turn the LED off by making the voltage LOW
 delay(100);                 // wait for a second
 



 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {
   // sets the value (range from 0 to 255):
   analogWrite(fadePin, fadeValue);        
   // wait for 30 milliseconds to see the dimming effect    
   delay(40);                            
 }

 // fade out from max to min in increments of 5 points:
 for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
   // sets the value (range from 0 to 255):
   analogWrite(fadePin, fadeValue);        
   // wait for 30 milliseconds to see the dimming effect    
   delay(20);                            
 }
}




That uses the wrong pins so the attiny will not do anything but this should be addressed after the other errors are addressed.
Quote

After hours wasted I have discovered that using the files in core 13_014 do not work with my UNO R3. Something in the instruction set points to invalid functions causing the Uno to not accept any new instructions.

This is most likely because of the wrong directory structure.
Quote

Can anyone verify that the file set provided actually works with an Uno R3 with an ATMEGA328P-PU and software ver arduino-1.0.1 or provide instructions on how to modify the code to work properly? I need the ATtiny13 programmed to run this sketch as size and weight are an issue for my project.

I can verify that the file set works on Arduino-1.0.1 but cannot verify it works on the Uno since I do not have one. I do not see any reason why it would not work though.
Quote

I am running Win Vista home basic with SP2

Windows Vista SP1 here but it should not matter much.

Also: It is very important that the correct board be selected
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 16, 2012, 04:06 am

Let me first suggest going here: http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/

I have read this and several other posts on programing an ATtiny13 (13A in my case).
I have owned an Arduino Uno R3 for about a week so be prepared for nube questions. I have been searching the web and have seen several tutorials that refer to using the arduino as an ISP but then go on to use something else to actually program the ATtiny so I am a bit lost. If there is aArduino ISP ATtiny programing for dummies pleas provide a link :smiley-roll:

I managed to get to step 8 in the EZlab link before I got error "avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny13
I searched and found this error can be ignored?
Quote
Quote
I haven't had any problems using my Duemillanove to program an Attiny13A and I have head that the Uno R3 works fine as an ISP but I do not have one to try it.

Quote

I have the latest version of core 13_014 installed as follows C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13. I have seen at least three different boards.txt modifications in this thread, which one should I use???

Quote
The boards.txt file is a confusing creature.
This works for me:

Code: [Select]

attiny13.name=Attiny 13A standalone
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x6A
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000L
attiny13.build.core=core13

I got more errors using your example ended up using the one from EZlab,it produced less errors
Quote
Quote

I see use a bootloader then statements that the ATtiny can't ???

The attiny13 is too small to support a bootloader so the upload bootloader command only burns the fuses. It should not be strictly necessary but it may run the wrong clock speed if you do not.
Quote

I understand the pin assignments have to be changed to match the ATtiny but at the moment I need to figure out how to get the ISP to communicate with the MCU without generating numerous error messages.

Changing pin assignments is trivial once it is working.
Quote

this is what I get when attempting upload arduinoISP from the example

C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp: In function 'int main()':
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:11: error: 'init' was not declared in this scope
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:12: error: 'setup' was not declared in this scope
C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino\core13\main.cpp:13: error: 'loop' was not declared in this scope

Quote
The files on your system should be located in C:\arduino\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13.
You have them one directory too deep.

Thanks I missed that one completely, reloaded with the correct directory structure and things seem to be working much better.
Quote
Quote

Attempting to run tools/burn bootloader produces

avrdude: stk500_getsync(): not in sync: resp=0x00

Ensure the ArduinoISP sketch is installed properly and recheck your wiring. In any case, we will deal with these errors once we get rid of the compiler errors.
Quote

.1uf capacitor between reset and ground does not have any effect.

Ensure the capacitor is disconnected when uploading to the Arduino and connected when uploading to the attiny.
Quote

Here is the code I have hacked and would like to have my ATtiny execute, strobes and anti collision lights for an RC aircraft.
Code: [Select]
/*
 Blink
 Turns on an LED on for three 250 ms blinks, then off for one second, repeatedly.

 This example code is in the public domain.
*/

int led = PB3;
int ledpin = PB4;
int fadePin = PB1;
// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(PB3, OUTPUT); 
  pinMode(PB4, OUTPUT);
 
}

// the loop routine runs over and over again forever:
void loop() {

 
  digitalWrite(PB3, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for a second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);       
  digitalWrite(PB4, LOW);
  digitalWrite(PB3, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 14 second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);
  digitalWrite(PB4, LOW);
  digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 1/4 second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);
  delay(100);
  digitalWrite(PB4, LOW);   // turn the LED off by making the voltage LOW
                               // turn the LED off by making the voltage LOW
  delay(100);                 // wait for a second
 



  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(20);                           
  }
}
}




Quote
That uses the wrong pins so the attiny will not do anything but this should be addressed after the other errors are addressed.

Changed pin assignments to PB3,PB4,&PB1
Quote
Quote

After hours wasted I have discovered that using the files in core 13_014 do not work with my UNO R3. Something in the instruction set points to invalid functions causing the Uno to not accept any new instructions.

Quote
This is most likely because of the wrong directory structure.

Fixed structure and most of the errors went away
Quote
Quote

Can anyone verify that the file set provided actually works with an Uno R3 with an ATMEGA328P-PU and software ver arduino-1.0.1 or provide instructions on how to modify the code to work properly? I need the ATtiny13 programmed to run this sketch as size and weight are an issue for my project.

I can verify that the file set works on Arduino-1.0.1 but cannot verify it works on the Uno since I do not have one. I do not see any reason why it would not work though.
Quote

I am running Win Vista home basic with SP2

Windows Vista SP1 here but it should not matter much.

Also: It is very important that the correct board be selected
[/quote]

I changed the code above to something I think the ATtiny will be able to use
opened the new sketch and hit the verify icon and get the following error

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13\main.cpp:8: error: expected constructor, destructor, or type conversion before '.' token

I don't even have a clue to search for an explanation for this error  :smiley-red:  I looked for a misplaced . but don't see one.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 16, 2012, 05:48 am


I managed to get to step 8 in the EZlab link before I got error "avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny13
I searched and found this error can be ignored?

This "error" is totally irrelevant and must be ignored. For some odd reason AVRDUDE complains when you haven't defined the PAGEL and BS2 signals even though the attiny series processors do not support this. It will upload without issues regardless though.
Quote
Thanks I missed that one completely, reloaded with the correct directory structure and things seem to be working much better.

That it a good sign.

Quote

I changed the code above to something I think the ATtiny will be able to use
opened the new sketch and hit the verify icon and get the following error

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13\main.cpp:8: error: expected constructor, destructor, or type conversion before '.' token

I don't even have a clue to search for an explanation for this error  :smiley-red:  I looked for a misplaced . but don't see one.



That is a weird error. Can you post the file? (It shouldn't be very long) Also ensure the notice block at the top is commented out.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 16, 2012, 02:03 pm
Code: [Select]
/*
  Blink
  Turns on an LED on for three 250 ms blinks, then off for one second, repeatedly.

  This example code is in the public domain.
*/


// give it a name:
int led = PB3;
int ledpin = PB4;
int fadePin = PB1;
// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(PB3, OUTPUT); 
  pinMode(PB4, OUTPUT);
 
}

// the loop routine runs over and over again forever:
void loop() {

 
  digitalWrite(PB3, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for a second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);       
  digitalWrite(PB4, LOW);
  digitalWrite(PB3, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 14 second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);
  digitalWrite(PB4, LOW);
  digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 1/4 second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);
  delay(100);
  digitalWrite(PB4, LOW);   // turn the LED off by making the voltage LOW
                               // turn the LED off by making the voltage LOW
  delay(100);                 // wait for a second
 



  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) {
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect   
    delay(20);                           
  }
}




Here is the file specifically called out in the error message:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13\main.cpp:8: error: expected constructor, destructor, or type conversion before '.' token
Code: [Select]
/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty"
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.14
*/Arduino.h
int main(){
init(); //Call init routine
setup(); //Call user provided setup()
while(1){loop();} //Continuiously call user provided loop()
}


Is ti possible that I have bricked the ATtiny and that is now causing strange errors?

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Tom Carpenter on Aug 16, 2012, 02:10 pm
Code: [Select]
/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty"
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.14
*/Arduino.h
int main(){
init(); //Call init routine
setup(); //Call user provided setup()
while(1){loop();} //Continuiously call user provided loop()
}


should be:
Code: [Select]
/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty"
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.14
*/
#include "Arduino.h"
int main(){
init(); //Call init routine
setup(); //Call user provided setup()
while(1){loop();} //Continuiously call user provided loop()
}


The error is essentially saying that it can't find a class named 'Arduino' with member 'h'. It is there because the line "*/Arduino.h" is not put inside the #include statement like it should be.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 16, 2012, 06:05 pm
Thanks Tom,
Iwill make the required adjustment the code and program some chips when I get home   :D
Thanks to John "smeezekitty" for all the assistance and work on the code to allow us to program these chips.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 17, 2012, 02:47 am
Thanks again guys, I have my first ATtiny13 programmed and blinking away :D
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 22, 2012, 03:18 am
***Version 0.16 released***
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 23, 2012, 02:37 pm
Ver 16 downloaded, hopefully will have spare time soon to experiment with new code.

I noticed the clock seems to have changed on the last chip I programmed, fuses were burned, and it looked good on the bread board.
Once all the resistors/LEDs were soldered on the clock seems to be running faster by about 30%.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 23, 2012, 07:39 pm

Ver 16 downloaded, hopefully will have spare time soon to experiment with new code.

I noticed the clock seems to have changed on the last chip I programmed, fuses were burned, and it looked good on the bread board.
Once all the resistors/LEDs were soldered on the clock seems to be running faster by about 30%.

Different power source? Which oscillator?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: malukens on Aug 24, 2012, 09:00 am
John,  I'm back.  A lot Arduino smarter and experienced but still short on both.  I downloaded your latest cores (V16) and was able to get it installed fairly easily.  I didn't see a boards.txt included with the cores so I created a new one using the text you posted in Reply #78 on: August 15, 2012, 12:33:07 PM

Also, your page 1 post now says you "Support 128KHz, 600KHz, 1MHz, 1.2MHz, 4MHz, 4.8MHz, 8MHz, 9.6MHz, 10MHz, 12MHz and 16MHz clock speeds".  Is there a place I can download a more complete boards.txt to get those different configs?

I have successfully uploaded a simple program that initializes three digital outputs and then reads an analog input and uses that analog value to select and then flash one of LEDS on the three digital outputs. 

void setup() {
    // verify all digital outputs are wired properly
    pinMode (0, OUTPUT); pinMode (1, OUTPUT); pinMode (2, OUTPUT);
    digitalWrite(0, HIGH); delay(1000) ;  digitalWrite(0,LOW);
    digitalWrite(1, HIGH); delay(1000) ;  digitalWrite(1,LOW);
    digitalWrite(2, HIGH); delay(1000) ;  digitalWrite(2,LOW);
}

void loop() {
  // read the value from the sensor:
  int potValue = analogRead(3) ;
 
  // select ledPin based upon analogRead value
  int ledPin = 0;
  if (potValue > 350) ledPin=1;
  if (potValue > 700) ledPin=2;
   
  // turn the selected ledPin on
  digitalWrite(ledPin, HIGH); delay(500);         
  digitalWrite(ledPin, LOW);  delay(500);                 
}

The program runs as expected on the Uno and a Tiny85 (@8Mhz) but on the Tiny13 with the boards.txt contents referenced above it had two oddities:
First, it runs about 50x slower than the Uno or Tiny85. 
Second, the analogRead produces its full range (0 - 1023) in the first 1/4 turn of the POT.  That is, potValue goes from 0 to 1023 with a very short amount of turn.  It was very smooth and gradual on the Uno and took the complete turn to produce values from 0-1023.  Any ideas what would be causing the analogRead to behave so weird?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 24, 2012, 07:38 pm
I didn't see a boards.txt included with the cores so I created a new one using the text you posted in Reply #78 on: August 15, 2012, 12:33:07 PM

This is true, currently the core does not ship with a boards.txt.

Quote

Also, your page 1 post now says you "Support 128KHz, 600KHz, 1MHz, 1.2MHz, 4MHz, 4.8MHz, 8MHz, 9.6MHz, 10MHz, 12MHz and 16MHz clock speeds".  Is there a place I can download a more complete boards.txt to get those different configs?

It is not quite that simple.
128KHz is set from the internal watchdog oscillator and is easily selected.
600KHz is the 4.8MHz clock with the /8 fuse set.
1 MHz must be created with an external clock on the '13
1.2MHz is the 9.6MHz clock with the /8 fuse set
4 MHz must be created with an external clock on the '13
4.8MHz is the 4.8MHz internal RC oscillator
8MHz must be created with an external clock on the '13
9.6 MHz is the 9.6MHz internal RC oscillatr
10,12,16 MHz all need to be created with external clocks.
Quote

I have successfully uploaded a simple program that initializes three digital outputs and then reads an analog input and uses that analog value to select and then flash one of LEDS on the three digital outputs. 

void setup() {
    // verify all digital outputs are wired properly
    pinMode (0, OUTPUT); pinMode (1, OUTPUT); pinMode (2, OUTPUT);
    digitalWrite(0, HIGH); delay(1000) ;  digitalWrite(0,LOW);
    digitalWrite(1, HIGH); delay(1000) ;  digitalWrite(1,LOW);
    digitalWrite(2, HIGH); delay(1000) ;  digitalWrite(2,LOW);
}

void loop() {
  // read the value from the sensor:
  int potValue = analogRead(3) ;
 
  // select ledPin based upon analogRead value
  int ledPin = 0;
  if (potValue > 350) ledPin=1;
  if (potValue > 700) ledPin=2;
   
  // turn the selected ledPin on
  digitalWrite(ledPin, HIGH); delay(500);         
  digitalWrite(ledPin, LOW);  delay(500);                 
}

The fuse on the section was wrong with the /8 fuse accidentally set
Change
Quote

attiny13.bootloader.low_fuses=0x6A

to
Quote

attiny13.bootloader.low_fuses=0x7A

The program runs as expected on the Uno and a Tiny85 (@8Mhz) but on the Tiny13 with the boards.txt contents referenced above it had two oddities:
Quote
First, it runs about 50x slower than the Uno or Tiny85. 

It should be 8x too slow, I am not sure where 50x would come from?
Quote

Second, the analogRead produces its full range (0 - 1023) in the first 1/4 turn of the POT.  That is, potValue goes from 0 to 1023 with a very short amount of turn.  It was very smooth and gradual on the Uno and took the complete turn to produce values from 0-1023.  Any ideas what would be causing the analogRead to behave so weird?

The ADC might be under-clocked from the bad fuse settings. Correct those and try again.
If it persists, I will test later.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 24, 2012, 08:42 pm


Ver 16 downloaded, hopefully will have spare time soon to experiment with new code.

I noticed the clock seems to have changed on the last chip I programmed, fuses were burned, and it looked good on the bread board.
Once all the resistors/LEDs were soldered on the clock seems to be running faster by about 30%.

Different power source? Which oscillator?


#1 Yes Arduino power on the bread board vs voltage from the RC receiver on final install voltage is 3.8Vdc

#2 ATtiny13  @4.8MHz boards.txt located at:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino
Code: [Select]

attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 24, 2012, 09:00 pm



#1 Yes Arduino power on the bread board vs voltage from the RC receiver on final install voltage is 3.8Vdc

The voltage can cause the clock to change quite significantly but 30% seems excessive. 10-15% is common of the voltage range of 1.7-5.
Quote

#2 ATtiny13  @4.8MHz boards.txt located at:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino
Code: [Select]

attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13


FWIW This has the clock/8 fuse set so it is running at 600KHz and not 4.8MHz.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on Aug 24, 2012, 09:13 pm
10-15% is common of the voltage range of 1.7-5.


If the frequency of either internal oscillator varies by more than 3% over the voltage range the processor grossly violates the published specifications.  In other words, your processor is defective.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 24, 2012, 09:29 pm

10-15% is common of the voltage range of 1.7-5.


If the frequency of either internal oscillator varies by more than 3% over the voltage range the processor grossly violates the published specifications.  In other words, your processor is defective.


Man! I'm going to demand my .99 cents back!  For what we pay for these I am not surprised they don't perform to the specifications. This just a minor inconvenience for me as I am only driving lights for an RC toy.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 24, 2012, 09:36 pm




#1 Yes Arduino power on the bread board vs voltage from the RC receiver on final install voltage is 3.8Vdc

Quote
The voltage can cause the clock to change quite significantly but 30% seems excessive. 10-15% is common of the voltage range of 1.7-5.

Would installing a transistor between VCC & Reset force the clock to run at the same on both voltages?
Quote


#2 ATtiny13  @4.8MHz boards.txt located at:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino
Code: [Select]

attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13


Quote
FWIW This has the clock/8 fuse set so it is running at 600KHz and not 4.8MHz.

Thanks, I will look up the proper fuse setting for the 4.8MHz setting
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 24, 2012, 10:02 pm


Would installing a transistor between VCC & Reset force the clock to run at the same on both voltages?

???

Quote

Thanks, I will look up the proper fuse setting for the 4.8MHz setting

http://www.engbedded.com/fusecalc/
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 24, 2012, 10:50 pm



Would installing a transistor between VCC & Reset force the clock to run at the same on both voltages?

Quote
???

Just asking as a light set I purchased using an ATtiny13 has a component resembling a resistor (SMD 0603 style ) with  code E0l or E01 installed between VCC & reset pins. That number seems to belong to a transistor but my electronics searching often turn up bum results.
Quote

Thanks, I will look up the proper fuse setting for the 4.8MHz setting

http://www.engbedded.com/fusecalc/


Thanks I will check out the link
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 25, 2012, 12:29 am
Actually that is a resistor.
Some microcontrolers experience spurious resets without an external pull up resistor.
If it randomly resets, try a pull of resistor between 2k and 68k.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: malukens on Aug 25, 2012, 08:17 am
John, I changed the low fuse to 7A and now the timing is relatively close for both 9.6 MHz and 4.8MHz; it takes only 7 sec for a 10 sec delay to finish (approx 40% fast).  The analogRead is still exhibiting the same end-biased behavior as before; the read goes from 0-1023 in approximately 25% of the rotation of the POT. 

In an article on Instructables (Make an Attiny13 based IR proximity sensor for $2.42) the author says that you need the command:
Code: [Select]
analogReference(0);//analogread won't work on Atiny13 w/o this line. Won't work on others WITH it prob'ly.

The article references your core13 but I'm not sure how since the analogReference command is not supported in your core.  I appreciate your interest in this platform.  Let me know if there is anything else I can test.

Thanks, Mark



Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 25, 2012, 05:44 pm
testing pulseIn this morning with Ver1.16 and getting error that I think states there is an argument in wiring.h it can't process

Quote

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h: In function 'void loop()':
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h:76: error: too few arguments to function 'long unsigned int pulseIn(unsigned char, unsigned char, long unsigned int)'
SwitchRC_AUX:10: error: at this point in file


Here is the sketch that  generates the error during verification

Code: [Select]
int duration;

void setup()
{
  pinMode(PB2, INPUT);
  pinMode(PB0, OUTPUT);
}

void loop()
{
  duration = pulseIn(PB2, HIGH);
  digitalWrite(PB0, LOW);
  if (duration < 1300)
  {
    digitalWrite(PB0, HIGH);
  }
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 25, 2012, 07:23 pm

John, I changed the low fuse to 7A and now the timing is relatively close for both 9.6 MHz and 4.8MHz; it takes only 7 sec for a 10 sec delay to finish (approx 40% fast). 

The delay being spotty is a well know problem.
I will try to find a small solution but for now you can use the millis() wait loop work around if you can afford a bit more flash.
Quote

The analogRead is still exhibiting the same end-biased behavior as before; the read goes from 0-1023 in approximately 25% of the rotation of the POT. 

I will check it out soon (not sure when I will get to it though).
Quote

In an article on Instructables (Make an Attiny13 based IR proximity sensor for $2.42) the author says that you need the command:
Code: [Select]
analogReference(0);//analogread won't work on Atiny13 w/o this line. Won't work on others WITH it prob'ly.


analogReference is just a stub so I think this would just increase code size with no other effect.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 25, 2012, 07:26 pm

testing pulseIn this morning with Ver1.16 and getting error that I think states there is an argument in wiring.h it can't process

Quote

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h: In function 'void loop()':
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h:76: error: too few arguments to function 'long unsigned int pulseIn(unsigned char, unsigned char, long unsigned int)'
SwitchRC_AUX:10: error: at this point in file


Here is the sketch that  generates the error during verification

Code: [Select]
int duration;

void setup()
{
  pinMode(PB2, INPUT);
  pinMode(PB0, OUTPUT);
}

void loop()
{
  duration = pulseIn(PB2, HIGH);
  digitalWrite(PB0, LOW);
  if (duration < 1300)
  {
    digitalWrite(PB0, HIGH);
  }
}


On core13, pulseIn requires a time out argument.
You could set this to 0xFFFFFFFF which is the maximum of a 32 bit number. This would set the time out to about 1.2hours.
Sorry for the inconvenience.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 26, 2012, 05:18 pm


testing pulseIn this morning with Ver1.16 and getting error that I think states there is an argument in wiring.h it can't process

Quote

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h: In function 'void loop()':
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h:76: error: too few arguments to function 'long unsigned int pulseIn(unsigned char, unsigned char, long unsigned int)'
SwitchRC_AUX:10: error: at this point in file



On core13, pulseIn requires a time out argument.
You could set this to 0xFFFFFFFF which is the maximum of a 32 bit number. This would set the time out to about 1.2hours.
Sorry for the inconvenience.


I have searched several C++ tutorials and numerous posts that refer to timeout but have found nothing that references timeout in relation to pulseIn
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Tom Carpenter on Aug 26, 2012, 06:57 pm
in this case, 'timeout' is a variable which you pass to pulseIn to say how long it should wait for a pulse to be detected before giving up.

The error "too few arguments to function" is generic and means that a function (in this case pulseIn) requires you to give it more values than you have.
For example:
Code: [Select]
void functionWithThreeArguments(int arg1, byte arg2, float arg3){
   //Whatever...
}
...
  functionWithThreeArguments(someVariable); //This is not valid as only 'arg1' is given a value, not the other two.
  functionWithThreeArguments(someVariable, aSecondVariable); //This is not valid as only 'arg1' and 'arg2' are given values, not the other.
  functionWithThreeArguments(someVariable, aSecondVariable, aThirdVariable); //This is valid as the compiler knows what to put in each of the three arguments.
...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Aug 29, 2012, 05:29 am

in this case, 'timeout' is a variable which you pass to pulseIn to say how long it should wait for a pulse to be detected before giving up.

The error "too few arguments to function" is generic and means that a function (in this case pulseIn) requires you to give it more values than you have.
For example:
Code: [Select]
void functionWithThreeArguments(int arg1, byte arg2, float arg3){
   //Whatever...
}
...
  functionWithThreeArguments(someVariable); //This is not valid as only 'arg1' is given a value, not the other two.
  functionWithThreeArguments(someVariable, aSecondVariable); //This is not valid as only 'arg1' and 'arg2' are given values, not the other.
  functionWithThreeArguments(someVariable, aSecondVariable, aThirdVariable); //This is valid as the compiler knows what to put in each of the three arguments.
...



Ok I understand that as written the 3 variables must be provided, but are three really needed? Can I rewrite the line in wiring.h to only require one argument & accompanying variable? Does the variable have to be listed as a # define statement?
I read a couple of C++ tutorials over the weekend and generated more questions than answers.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 29, 2012, 09:52 am
You could but the time out parameter could be very useful to prevent the code from blocking for very long periods of time or infinity.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Sep 01, 2012, 08:47 pm
Time out was the one parameter I was going to try figure out how to keep.
Where can I find a good C++ for dummies type tutorial?
I am not opposed to learning a bit about programming but I don't have
a lot of free time to spend scrounging through the endless list of tutorials that my
search engine produces.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 03, 2012, 08:24 am

Where can I find a good C++ for dummies type tutorial?
I am not opposed to learning a bit about programming but I don't have
a lot of free time to spend scrounging through the endless list of tutorials that my
search engine produces.

Its easier said then done to find a good tutorial. Most people pick up the more slightly more advanced stuff by doing and learning.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Sep 08, 2012, 06:45 pm


Thats just sweet, someone asks a question and gets a non answer, what gives???
I am a user attempting to learn to use a product that is delivered with no standardized instructions. I have spent over 20 hours of time reading tutorials that do not explain how to use this product, Best I can find states there are many ways to code a function and that some are better than others.
I have managed to get Attiny 13A standalone to work, I have programmed a chip with the following and it does not work as expected.
Code: [Select]

int duration;

void setup()
{
  pinMode(PB5, INPUT); 
  pinMode(PB0, OUTPUT);
}

void loop()

{
  duration = pulseIn(PB5, HIGH, 0xFFF);
  digitalWrite(PB0, LOW);
  if (duration < 1500)
  {
    digitalWrite(PB0, HIGH);
  }
}


The MCU does not generate a change in the state of the output pin based on input from the radio control receiver signal pin.
I have verified that the RX is outputting a pulse width of 1500us at center with a span from 1048us low to 1952us high.
I have powered the MCU using RX power and separate power for the MCU and RX with no change.
The only way that the code generates a state change is by completely disconnecting the signal from the input pin.
I have altered
Code: [Select]
if (duration < 1500) using values from 1 to 2000 with no change, I have substituted < for > and the input from the RX still produces no change, removing the signal input produces a reversed effect on the output pin.
I have attempted several different input and output pins with no change in results
I have no clue at this point if the problem is hardware, software, or operator related.

[/quote]
Its easier said then done to find a good tutorial. Most people pick up the more slightly more advanced stuff by doing and learning.

[/quote]
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 08, 2012, 09:04 pm



Thats just sweet, someone asks a question and gets a non answer, what gives???
I am a user attempting to learn to use a product that is delivered with no standardized instructions. I have spent over 20 hours of time reading tutorials that do not explain how to use this product, Best I can find states there are many ways to code a function and that some are better than others.

Settle down. Their are no standardized instructions because I suck at writing them.
Debugging embedded code is not an easy task. Especially time-critical code.
Ensure you are using a sufficient clock speed.
When working with uS, you want as much speed as you can get.
9600000 will give you 27uS granularity while 1200000 will only provide a lousy 213uS granularity.


There is also a high likely-hood of a core bug.
Having no serial support on the '13 makes this problem even harder.

Also, try this version of pulseIn
Code: [Select]

unsigned long pulseIn_new(unsigned char pin, unsigned char stat, unsigned long timeout){
while(digitalRead(pin) != stat){if(micros() - st > timeout){return 0;}}
unsigned long st = micros();
while(digitalRead(pin) == stat){if(micros() - st > timeout){return micros()-st;}}
return micros()-st;
}

Which may correct a possible bug.
Quote

The MCU does not generate a change in the state of the output pin based on input from the radio control receiver signal pin.
I have verified that the RX is outputting a pulse width of 1500us at center with a span from 1048us low to 1952us high.

Ok this is doable but should be easier at a higher clock rate.
Quote

I have powered the MCU using RX power and separate power for the MCU and RX with no change.

The power source should have little effect since this is most likely a software bug.
Quote

I have no clue at this point if the problem is hardware, software, or operator related.

Probably software with the possibility of a mixed issue.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Sep 08, 2012, 11:04 pm
Quote
Ensure you are using a sufficient clock speed.
When working with uS, you want as much speed as you can get.
9600000 will give you 27uS granularity while 1200000 will only provide a lousy 213uS granularity.


you mentioned in an earlier post the board was running slow so I attempted to start from scratch with ATTiny13 standalone
which is supposed to run faster "attiny13.build.f_cpu=9600000L" but I can not get Bootloader to run this board.txt file
error produced
Quote
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny13
                                avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny13
                                ***failed; 
                                avrdude: verification error, first mismatch at byte 0x0000
                                0xff != 0x3f
                                avrdude: verification error; content mismatch

Other boards.txt files load fine but are all set for lower clock speeds and may be contributing to the problem running my sketch.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 08, 2012, 11:15 pm
This
Code: [Select]

attiny13at9m.name=ATtiny13 @ 9.6 Mhz
attiny13at9m.bootloader.low_fuses=0x7A
attiny13at9m.bootloader.high_fuses=0xff
attiny13at9m.upload.maximum_size=1024
attiny13at9m.build.mcu=attiny13
attiny13at9m.build.f_cpu=9600000
attiny13at9m.build.core=core13

should make it run at 9.6MHz. If this gives errors then I am at a loss.
It would be kind of nice if Arduino would develop something easier then boards.txt.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gizmoDave on Sep 09, 2012, 12:32 am

This
Code: [Select]

attiny13at9m.name=ATtiny13 @ 9.6 Mhz
attiny13at9m.bootloader.low_fuses=0x7A
attiny13at9m.bootloader.high_fuses=0xff
attiny13at9m.upload.maximum_size=1024
attiny13at9m.build.mcu=attiny13
attiny13at9m.build.f_cpu=9600000
attiny13at9m.build.core=core13

should make it run at 9.6MHz. If this gives errors then I am at a loss.
It would be kind of nice if Arduino would develop something easier then boards.txt.

That one loads fine.
Now I'm off to figure out "unsigned long pulseIn_new"
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 09, 2012, 03:26 am
Quote

Now I'm off to figure out "unsigned long pulseIn_new"


Simply put it at the top of your source file and replace all uses of pulseIn with pulseIn_new.
The new version might fix a possible bug. If it works better I will merge it with the core in the next version.
Please understand this is prealpha software and in the early testing stages so tons of bugs is to be expected.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Sep 15, 2012, 12:31 pm
I'm really looking forward to try this new core, but how should I connect the attiny13 to the arduino? is there some kind of connection diagram out there? and do I need to use arduinoISP to program it, an arduino with the 328p installed(or not installed), or can I use a FTDI breakout.

If someone have the answer it would be great! :D
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 15, 2012, 08:51 pm

but how should I connect the attiny13 to the arduino? is there some kind of connection diagram out there?

Wire it just like this. http://hlt.media.mit.edu/?p=1229 But ignore the instructions about installing the 45/85 core.
Quote

and do I need to use arduinoISP to program it

Yes.
Quote

, an arduino with the 328p installed(or not installed), or can I use a FTDI breakout.

Yes. Use an Arduino with the Atmega installed and the arduinoISP loaded. An FTDI board will not work since the attiny13 does not support serial.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: AgeBee on Nov 13, 2012, 01:08 pm
Hi,
I just wanted to test your core13 sources on my platform here.
I run Ubuntu 12.10 with Arduino 1.0.1 and installed your version 16 (core13_016.zip).
As a programmer I use USBtiny and got that programmer into boards.txt.
It compiles well with no errors.

However, I get the following error from avrdude while uploading the blink sketch:

avrdude: Expected signature for ATtiny13 is 1E 90 07
         Double check chip, or use -F to override this check.


Do I have burn some fuses beforehand ?

When I run avrdude with 'avrdude -c usbtiny -p t2313' I get the following answer:

avrdude: Device signature = 0x1e910a
avrdude: safemode: Fuses OK


What does that 'device signature' mean and why is it different from the 'expected signature' ?

Thanks for your help.

Regards
AgeBee
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Tom Carpenter on Nov 13, 2012, 03:05 pm
An attiny2313 is not an attiny13. Thus their unique device signatures don't match.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Nov 22, 2012, 04:18 am

Hi,
I just wanted to test your core13 sources on my platform here.
I run Ubuntu 12.10 with Arduino 1.0.1 and installed your version 16 (core13_016.zip).
As a programmer I use USBtiny and got that programmer into boards.txt.
It compiles well with no errors.

However, I get the following error from avrdude while uploading the blink sketch:

avrdude: Expected signature for ATtiny13 is 1E 90 07
        Double check chip, or use -F to override this check.



"Tom Carpenter" is correct. The attiny2313 is not an attiny13.
Also, core13 will only work on 8 pin devices.
http://code.google.com/p/arduino-tiny/ probably will work with an attiny2313.

Also I have been out of down and had two(!) computer failures so support and development is delayed.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mrares on Jan 02, 2013, 07:43 pm
Hello,

I've just started using the arduino and successfully uploaded the blinker to my attiny13a following:
http://tekstop.wordpress.com/2011/12/30/programming-attiny13-using-arduino-isp-and-all-the-hacking-involved/
and
http://hlt.media.mit.edu/?p=1229

I've ran into the default fuses problem and fixed it by "installing bootloader" in the IDE but now I have a question that wasn't answered around here:

Can you use all the pins on this device (the reset pin, too) without a bootloader?! (my reading from various forums says NO, not without setting the fuse so the pin is no longer RESET and needing a high-voltage programmer to reprogram the device)

Can you help me understand if and how this works?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ElectroNick on Jan 02, 2013, 07:57 pm

Can you use all the pins on this device (the reset pin, too) without a bootloader?! (my reading from various forums says NO, not without setting the fuse so the pin is no longer RESET and needing a high-voltage programmer to reprogram the device)


"Burn Bootloader" as far as ATtiny13 and other chips burned using a programmer are concerned, is a euphemism. There's no bootloader (and no need for one either)  - all this Arduino IDE function does is to burn proper configuration fuses so the MCU operates using the right clock frequency and so your time-dependent programs, such as the LED blinker, work properly. There are plenty of other configuration variables set by the config fuses but the timing is probably most important from the practical stand point - most others are left on defaults.

You cannot use the Reset pin if you're planning to re-flash the MCU using an ICSP programmer. Unless you have a high-voltage programmer, just consider ATtiny13 a 5xI/O MCU - makes development easier.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mrares on Jan 03, 2013, 02:38 pm
Got it! Once reading the spec of the attiny13a it looks like with a bit of elbow grease and a 12V power supply one can reset the fuses off a chip with the help of an Uno and a custom sketch.

Is it possible to write the fuses from within the code on the chip? (eg: set the reset pin enabled or disabled from your sketch, say... on a spi command received)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Tom Carpenter on Jan 03, 2013, 03:01 pm

Is it possible to write the fuses from within the code on the chip? (eg: set the reset pin enabled or disabled from your sketch, say... on a spi command received)

No, you can't. The device can only be programmed when held in Reset (ISP), or with a high voltage programmer.
Furthermore, if the reset pin is disabled, then the ISP won't work as there is no way for it to hold the chip in reset.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: pswag on Feb 11, 2013, 10:48 am
ADMUX = (1<<REFS0) | pin & 7; //Setup ADC

Hi,

the analog mux has only 4 channels on T13. Ain't it better giving the user the ability to select the analog reference?
What about this:

ADMUX = ADMUX & _BV(REFS0) | pin & 3; //Setup ADC, preserve REFS0

and implement analogReference():

void analogReference(uint8_t mode){
   if(mode==INTERNAL)
      ADMUX |= _BV(REFS0)
   else
      ADMUX &= ~_BV(REFS0)
}

Cheers, Peter
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 11, 2013, 08:12 pm

ADMUX = (1<<REFS0) | pin & 7; //Setup ADC

Hi,

the analog mux has only 4 channels on T13. Ain't it better giving the user the ability to select the analog reference?
What about this:

ADMUX = ADMUX & _BV(REFS0) | pin & 3; //Setup ADC, preserve REFS0

and implement analogReference():

void analogReference(uint8_t mode){
   if(mode==INTERNAL)
      ADMUX |= _BV(REFS0)
   else
      ADMUX &= ~_BV(REFS0)
}

Cheers, Peter

To be quite honest, I did not realize the '13 had an analog reference other than +V. The "& 7" is a bug. I will fix it in the next release.

I still do not really see the point in supporting analogReference.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: pswag on Feb 14, 2013, 01:25 am
I am wondering why analogRead() explicitely sticks the REFS0 bit to 1 every time it is called (1<<REFS0), which selects the INTERNAL 1V1 reference, hence A/D range is limited to an input voltage from 0 to 1.1 V. This is no good.

However the Arduino uses 0 to VCC by default.

The datasheet says:
0 VCC used as analog reference. -> #define DEFAULT 0
1 Internal Voltage Reference. -> #define INTERNAL 1

Users would actually not expect that analogRead() was setting the analog reference.
analogReference() is intended for doing the job.

#defines are provided in wiring.h

See also
http://arduino.cc/en/Reference/AnalogReference

What's the problem with implementing analogReference()? This is pretty easy, and the T13 can do it. So people can make use of it.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: pswag on Feb 14, 2013, 01:37 am
I'd like to share the modifications I have already done to your code.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 14, 2013, 07:24 am

I am wondering why analogRead() explicitely sticks the REFS0 bit to 1 every time it is called (1<<REFS0), which selects the INTERNAL 1V1 reference, hence A/D range is limited to an input voltage from 0 to 1.1 V. This is no good.

Oh yikes. Thanks for catching that. It is a bug.
These things are hard to debug without a Serial interface.


Although quite honestly I was not even aware of the 1.1V reference. I thought that was only on the higher end chips.


I will evaluate your changes and determine if it is worth including. Please standby.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Somnitec on Mar 02, 2013, 07:12 pm
A small feature request: Could you add PinMode(pin,INPUT_PULLUP)?  This makes simple buttons easier!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 03, 2013, 05:38 am

A small feature request: Could you add PinMode(pin,INPUT_PULLUP)?  This makes simple buttons easier!

I could. As it is, it uses Arduino 022 style so
Code: [Select]

pinMode(pin,INPUT);
digitalWrite(pin,1);

will enable the pullup.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Mar 03, 2013, 04:20 pm
Quote
These things are hard to debug without a Serial interface.


You might be interested in this:

Using Coding Badly's TinyISP and knockbang library, it is posiible to get debug output from a tiny13 and your core:

http://arduino.cc/forum/index.php/topic,123388.msg1033756.html#msg1033756
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 03, 2013, 07:36 pm
You know, oddly enough I created an synchronous serial debugging system for the Attiny13 but I got fed up of flashing the Arduino between the ISP sketch and the serial receive sketch.

I will look at that. Thanks.

Side note: Version 0.18 is in progress.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 16, 2013, 03:22 am
New version released!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Mar 19, 2013, 02:17 pm
Is the newest core called 017 ?

I downloaded from the link in the first post in this thread
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 21, 2013, 03:20 am

Is the newest core called 017 ?

I downloaded from the link in the first post in this thread

No, the new version is 0.18.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Mar 21, 2013, 10:15 am
Quote
No, the new version is 0.18.


Thanks, what I meant to ask was: where to get it.

This links leads me to version 0.17

http://sourceforge.net/projects/ard-core13/
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 23, 2013, 06:34 pm

Sorry for the slow response.

http://sourceforge.net/projects/ard-core13/files/
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 07, 2013, 01:27 pm
Hi There:

Attiny13 is employed in flashlight drivers to control the led. For example, using PWM for obtaining different amount of light (high, medium, low) and for flashing/strobing.

Some drivers using the Attiny13 are very versatile. You can change the modes available, just employing the switch, and some of them show that the battery is low.

I am very interested in this project, as I would like to develop my own software for the flashlight driver, and there is a large community of people (flashlight lovers) interested in this topic.

Therefore, I will have a look to this thread.

Just one quick question. Is PWM fully implemented? Which is the pin for PWM? I think only one is available.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on May 07, 2013, 05:20 pm
Quote
Which is the pin for PWM? I think only one is available


There are two, PB0 and PB1
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 08, 2013, 02:32 am
Yes that is correct PB0 and PB1 support PWM. PWM is fully implemented although the next version should improve PWM performance.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 08, 2013, 12:16 pm
Thanks for the answers. I am waiting for some Attiny13 for beginning to write the software for the led driver.

Let me show the driver that it is used in many good flashlights:

(http://www.el34world.com/Misc/bike/images/IMG_6596.png)

You can see in the picture the Attiny13 and 4 AMC7135 current regulators, that are controlled via PWM. There are more AMC7135 on the other side.

The stars 2, 3 and 4 are used to modify the program on the Attiny13. Soldering one start to ground, i.e., one input is connected to ground, modify the light modes available.

It is a very interesting project for me and for many flashlight lovers. We want to improve the light modes.

One question, ... so no bootloader is loaded, so.. how much memory is available for the program since the maximum is 1K?



Title: resolved clock issue now at 9.6Mhz e Attiny13 *testers wanted*
Post by: nanouser on May 09, 2013, 08:42 pm
hello, just wanted to share my success
after a day of fighting just made my atatiny13a run on 9.6 mhz (or is it rather 8?) (for batch fiile solution see end of the message)
i am using arduino nano v3.0 with a 10mf capacitor to programm the attiny13
following the instructions at http://arduinodiy.wordpress.com/2012/02/28/program-an-attiny-with-an-arduino-nano/
and using the great core13 v18 files and information provided here
the programming worked very well right away with one issue: the clock was somewhere
around one tenth of the 9.6 Mhz the led blink turned on or off every 10 secs instead of the every single second.
after playing with settings in boards.txt i realized that my arduino IDE 1.04 was not programming the fuses when uploading the program (no if this is by definition) so that my fuse settings to adjust the clock had no effect whatever)
when i tryed to upload the bootloader to change fuses avrdude called by the arduino ide complained with the verification error "first mismatch at byte 0x0000" and failed
here is my boards.txt
attiny13.name=Attiny 13A standalone
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000
attiny13.build.core=core13

so after tinkering and trying i have crearted a batch file which directly calls the AVRDUDE from arduino to programm the fuses.
i used the http://www.engbedded.com/fusecalc/ to calculate the hex values for fuses
note: you might need to change the com18 to whatever comport your programmer is using (check it out in the arduino IDE) and the actual 0x7a and 0xff fuses accourding to frequency/configuration you need
also not forget to change the base path to your arduino ide folder
here is the batch-----------------------------------
c:
cd c:\arduino\arduino-1.0.4\hardware\tools\avr\bin
avrdude -C ..\etc\avrdude.conf -p attiny13 -P com18 -b 19200 -c arduino -U lfuse:w:0x7A:m -U hfuse:w:0xFF:m -B250
pause
--------------------------
hope that can help somebody else as well.
--------
p.s: a blink for 40 seconds now gives me around 44secs (at over 5 Volts)
so it looks to me  like it actually runsaround 10% slower on (9.6mhz -0.96) = at around 8.4 Mhz instead of the promised 9.6
is this normal?
but anyway it is fast enough, i dont care about the right timing so much
Peter
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on May 10, 2013, 12:36 am
There is a way to slow down avrdude for the IDE programming but it is a global default setting, so it will affect all programming.

In the avrdude.conf file  look for this around line 314:
Code: [Select]

#
# Overall avrdude defaults
#
default_parallel   = "lpt1";
default_serial     = "com1";
# default_bitclock = 2.5


Change to at least:
Code: [Select]
default_bitclock = 150;

Note: don't forget the ';' to terminate the line.  The example comment left it out.

This worked fine programming an ATtiny13A @9.6MHz and even down to @ 128KHz.

Edit: Hehe, I actually was able to work the tiny13A @16KHz (128KHz/8).  I had to modify the wiring.c to add F_CPU = 16000.  It not very accurate, but Blink works reasonably.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on May 15, 2013, 01:47 pm
Quote
p.s: a blink for 40 seconds now gives me around 44secs (at over 5 Volts)
so it looks to me  like it actually runsaround 10% slower on (9.6mhz -0.96) = at around 8.4 Mhz instead of the promised 9.6
is this normal?


The datasheet state the factory clock setting is within +-10%, so that is normal.

I was just playing with an ATtiny13 to see how close I could tune the osscillator, and it was quite easy to get within the +-2% mentioned in the datasheet by changing the OSCCAL value.
It is not very stable though, it jumps up and down.

One thing that surprised me:

Changing the OSCCAL dos not change the frequence of the 128 kHz internal Oscillator.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on May 15, 2013, 08:28 pm
Changing the OSCCAL dos not change the frequence of the 128 kHz internal Oscillator.


Two separate clocks.  The 128 kHz oscillator is the same clock used for the watchdog; which cannot be tuned.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on May 15, 2013, 10:47 pm
Thanks Coding Badly,
Yes I can see it now, I just didn't think about it before.
On my particular t13 it is off by 8,8%, although it is not a problem.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 16, 2013, 09:12 am
Internal clocks, being RC oscillators won't be too accurate.
They are not really stable over varying voltage either. Good enough for many cases though.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 17, 2013, 08:22 pm
One question about using the internal voltage reference...

Is it implemented? in which pin?

Could you please show me how to use it in this Arduino core?

I am employing analogReference(INTERNAL) and I obtain the following error:

"AnalogReference was not declared...."

Please, if it is not implemented, I really need it for my project. and it must be the internal reference.  =(

Thanks in advance
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 18, 2013, 10:04 am

One question about using the internal voltage reference...

Is it implemented? in which pin?

Could you please show me how to use it in this Arduino core?

I am employing analogReference(INTERNAL) and I obtain the following error:

"AnalogReference was not declared...."

Please, if it is not implemented, I really need it for my project. and it must be the internal reference.  =(

Thanks in advance

The two references supported are ~1.1v and VIN. External reference is not supported in hardware.

Make sure analogReference is spelled right. Make sure the core is installed properly. Before version 0.18 analogReference was stub so make sure you update.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 18, 2013, 10:21 am


One question about using the internal voltage reference...

Is it implemented? in which pin?

Could you please show me how to use it in this Arduino core?

I am employing analogReference(INTERNAL) and I obtain the following error:

"AnalogReference was not declared...."

Please, if it is not implemented, I really need it for my project. and it must be the internal reference.  =(

Thanks in advance

The two references supported are ~1.1v and VIN. External reference is not supported in hardware.

Make sure analogReference is spelled right. Make sure the core is installed properly. Before version 0.18 analogReference was stub so make sure you update.


This is very strange. I am using version 18. The same code can be compiled for Attint85, but it does not work for Attiny13. That means that it is correctly spelled. The code that fails follows:

void setup() {
analogReference(INTERNAL);
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT);

time = millis();
memooculto = EEPROM.read(0); delay(80);
if (memooculto == 0) { maxmodereal = maxoculto;}
else  {maxmodereal = maxmode;}

mode = EEPROM.read(1);
delay(80);
if (mode == 0) {mode = 1;}
if (mode > maxmodereal) {mode = maxmodereal;}
}

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on May 18, 2013, 01:46 pm
A closer look at wiring.h show that analogReference() has been commented out for some reason?

Also the INTERNAL and EXTERNAL definitions are both defined as zero for some reason?

According to the datasheet, the INTERNAL 1.1V reference  is REFS0 = 1.  And the EXTERNAL Vcc reference is REFS0 = 0.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on May 18, 2013, 03:07 pm
I tested uncommenting the analogReference() and corrected the definitions in the core13\wiring.h file:

Code: [Select]

#define INTERNAL 1
#define EXTERNAL 0

void analogReference(uint8_t mode);



Seems to work reasonably well between INTERNAL and EXTERNAL settings.
Test code:
Code: [Select]


int led = 3;
const int inPin = 2;    // analog in, to ADC2 for temp sensor TMP36, pin 3 on ATtiny13

void setup() {               
  pinMode(led, OUTPUT);

  // initialize the ADC voltage reference
  analogReference(EXTERNAL);    // Vref = Vcc
//  analogReference(INTERNAL);    // Vref = 1.1V
}

void loop() {
  // Read temperature sensor
  int value = analogRead(inPin);
//  float millivolts = (value / 1024.0) * 1100;  // Internal 1.1V
//  float millivolts = (value / 1024.0) * 4800;  // External VCC 4.8V
//  float celsius = (millivolts / 10.0) - 50;    // TMP 36 offset
//  float fahrenheit = (celsius *9)/5 + 32;

//  if ( value > 692) {  // Internal threshold for temp 76 deg
  if ( value > 158) {  // External theshold for temp 76 deg
     digitalWrite(led, HIGH);   // temp above threshold
  } else {
     digitalWrite(led, LOW);    // temp equal or below threshold
  }
  delay(1000);
}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 18, 2013, 07:40 pm
Quote

This is very strange. I am using version 18. The same code can be compiled for Attint85, but it does not work for Attiny13. That means that it is correctly spelled. The code that fails follows:

void setup() {
analogReference(INTERNAL);
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);

time = millis();
memooculto = EEPROM.read(0); delay(80);
if (memooculto == 0) { maxmodereal = maxoculto;}
else  {maxmodereal = maxmode;}

mode = EEPROM.read(1);
delay(80);
if (mode == 0) {mode = 1;}
if (mode > maxmodereal) {mode = maxmodereal;}
}

I confirmed there is a problem with wiring.h. You need to uncomment analogReference() and change #define INTERNAL to something other then zero.

But unless you have another library, EEPROM functions won't work.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 18, 2013, 07:49 pm
Thanks a lot hiduino...

Now i can compile the code.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 18, 2013, 08:10 pm

I confirmed there is a problem with wiring.h. You need to uncomment analogReference() and change #define INTERNAL to something other then zero.

But unless you have another library, EEPROM functions won't work.


Oh My God. I need both... EEPROM and analogReference()  :~
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 19, 2013, 02:34 am
is there any way to solve this issue?  =(

can I write the code that correspond to analogReference() directly in the Arduino sketch?

Thanks in advance
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 19, 2013, 04:50 am

is there any way to solve this issue?  =(

can I write the code that correspond to analogReference() directly in the Arduino sketch?

Thanks in advance

No need. After you make the minor corrections in the wiring.h it will work. Will be fixed in version 0.19
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 19, 2013, 11:14 am


is there any way to solve this issue?  =(

can I write the code that correspond to analogReference() directly in the Arduino sketch?

Thanks in advance

No need. After you make the minor corrections in the wiring.h it will work. Will be fixed in version 0.19


However, you said that EEPROM will not work. My need  is to use EEPROM library and analogReference() at the same time...

is it possible with 0.18 or I have to wait to 0.19?

Thanks in advance
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on May 19, 2013, 12:00 pm
I am not sure what I do.
I just tryed this sketch on an ATtiny13

Code: [Select]

#include <TinyDebugKnockBang.h>
#include <EEPROM.h>


void setup( void )
{
 EEPROM.write( 0, 127 );
 EEPROM.write( 1, 23 );
 Debug.begin( 250000 );
}

void loop( void )
{
 Debug.print("EEPROM (0)= ");
 Debug.println( EEPROM.read( 0 ), DEC );
 Debug.print("EEPROM (1)= ");
 Debug.println( EEPROM.read( 1 ), DEC );
 delay( 1000 );
}


And get this result:

Code: [Select]
EEPROM (0)= 127
EEPROM (1)= 23
EEPROM (0)= 127
EEPROM (1)= 23
EEPROM (0)= 127


So the EEPROM lib seems to work on a t13

I can see from the verbose output that the EEPROM library from the Arduino core is used:

Code: [Select]
D:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=attiny13 -DF_CPU=4800000 -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -ID:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\hardware\tiny\cores\core13 -ID:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\libraries\TinyDebugKnockBang -ID:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\libraries\EEPROM C:\Users\EC\AppData\Local\Temp\build8446476430265160657.tmp\tiny13_eeprom.cpp -o C:\Users\EC\AppData\Local\Temp\build8446476430265160657.tmp\tiny13_eeprom.cpp.o
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 19, 2013, 03:29 pm
the problems seems to use at the same time EEPROM and analogReference()...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 19, 2013, 07:13 pm
Replace wiring.h with:
Code: [Select]

/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices.
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty"
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.19
*/
#ifndef Wiring_h
#define Wiring_h
#include <avr/io.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C"{
#endif
#define HIGH 1
#define LOW 0
#define INPUT 0
#define OUTPUT 1
#define false 0
#define FALSE 0
#define TRUE 1
#define true 1
#define PI 3.1416
#define HALF_PI 1.57
#define TWO_PI 6.283
#define DEG_TO_RAD 0.0174533
#define RAD_TO_DEG 57.2958
#define SERIAL 0
#define DISPLAY 1 //WTF are these?
#define LSBFIRST 0
#define MSBFIRST 1
#define CHANGE 1
#define FALLING 2
#define RISING 3
#define INTERNAL 1
#define EXTERNAL 0
#define DEFAULT 0
#ifdef abs
#undef abs
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
typedef unsigned int word;
#define bit(b) (1UL << (b))
typedef uint8_t boolean;
typedef uint8_t byte;
void init(void);
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
uint8_t digitalRead(uint8_t);
int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, uint8_t);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned ms);
void delayMicroseconds(unsigned int us);
void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t);
uint8_t shiftIn(uint8_t, uint8_t, uint8_t);
unsigned long pulseIn(unsigned char pin, unsigned char stat, unsigned long timeout);
//void attachInterrupt(uint8_t, void (*)(void), int mode);
//void detachInterrupt(uint8_t);
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif


The EEPROM library is just a thin wrapper around avr-libc so it should work but could be large.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on May 20, 2013, 03:37 pm
That seems to do the trick.
Using the new wiring.h I get theese result, when using analogReference(INTERNAL);
and 0,53V on ADC(2)


Quote

EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 20, 2013, 04:45 pm

That seems to do the trick.
Using the new wiring.h I get theese result, when using analogReference(INTERNAL);
and 0,53V on ADC(2)


Quote

EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23





That's good news... thanks for sharing

I will check it up
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on May 24, 2013, 10:36 am
I have problems with analogRead, using analogRerefence(INTERNAL).

The reading does not seem to be a function of the applied voltage.

has anybody the same problem?

EDIT:  I solved this problem adding delay(50) before each reading. It seems that if the reads are taking very closely the value from analogRead is not accurate
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dwhacks on May 29, 2013, 02:48 am
First off, this is awesome. Check out what I've made using it at dwhacks.blogspot.ca

Second, I have a question about PWM. I know theres 2 dedicated PWM pins, 0 and 1, but I've also read that pin 4 (actual pin 3) can be used as PWM without "software PWM". Does this work with your core? I havent been able to figure it out, but I was trying to make a simple code to fade through colors with an RGB LED. Anyone done this that I've missed?

And finally, why not include a "boards.txt" and the proper folder structure in the download?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on May 29, 2013, 04:11 am
...but I've also read that pin 4 (actual pin 3) can be used as PWM without "software PWM".


Not correct.  One timer.  Two outputs per timer.  Two hardware driven PWM pins.

For three hardware driven PWM pins in an 8 pin package you will have to move to something from the ATtiny85 family.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dwhacks on May 29, 2013, 04:58 am
Thanks for the clarification.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jun 07, 2013, 02:14 am
Shame on me for not checking this for a long time.

Yeah I am not aware of any mechanism for generating PWM on pin 4 other then software.

I don't distribute boards.txt because it is a PITA to work with. I struggle with it for my own testing.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Jun 07, 2013, 04:24 am
Boards.txt is not as hard as it may seem.

I've always added the core13 to the sketches\hardware\ folder.  That way I can easily change out the IDE version without having to worry about adding core13 back.  You can keep all files separate from the IDE.  This makes it simpler to maintain.

It all starts with the boards.txt file.  Paths are relative to that location, unless you specify a platform qualifier.  So if you build your tree structure properly then it is easy to add it to the sketches\hardware folder.

Code: [Select]

\My Documents\Arduino\hardware\tiny13\boards.txt
\My Documents\Arduino\hardware\tiny13\cores\core13\ {core files}


boards.txt:
Code: [Select]

###########################################################################
attiny13.name=Attiny13 @ 16 KHz (internal 128 KHz watchdog oscillator/8)

attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.maximum_ram_size=64

attiny13.bootloader.low_fuses=0x2B
attiny13.bootloader.high_fuses=0xFF

attiny13.build.mcu=attiny13
attiny13.build.f_cpu=16000L
attiny13.build.core=core13



A more complete example that uses variants and bootloader:
Code: [Select]

\My Documents\Arduino\hardware\TCtiny\boards.txt
\My Documents\Arduino\hardware\TCtiny\cores\tiny\ {core files}
\My Documents\Arduino\hardware\TCtiny\variants\tinyX4optiboot\pins_arduino.h
\My Documents\Arduino\hardware\TCtiny\bootloaders\optiboot\optiboot_attiny84.hex


boards.txt:
Code: [Select]

###########################################################################
attiny84.name=Optiboot ATtiny84 @ 8 MHz  (internal osc)

attiny84.upload.protocol=arduino
attiny84.upload.speed=19200
#bootloader takes up last 9 pages, so there is a limit on the max size.
attiny84.upload.maximum_size=7616

attiny84.bootloader.low_fuses=0xE2
attiny84.bootloader.high_fuses=0xD7
attiny84.bootloader.extended_fuses=0xFE
attiny84.bootloader.path=optiboot
attiny84.bootloader.file=optiboot_attiny84.hex

attiny84.build.mcu=attiny84
attiny84.build.f_cpu=8000000L
attiny84.build.core=tiny
attiny84.build.variant=tinyX4optiboot



Then if you want to use the IDE Arduino core files instead, using variants:
Code: [Select]

\My Documents\Arduino\hardware\attiny\boards.txt
\My Documents\Arduino\hardware\attiny\variants\tiny14\pins_arduino.h
Arduino IDE install, \arduino-1.0.4\hardware\arduino\cores\arduino\ {core files}


boards.txt (notice the "core=arduino:" prefix):
Code: [Select]

###########################################################################
attiny84-20.name=ATtiny84 (external 20 MHz clock)

attiny84-20.bootloader.low_fuses=0xfe
attiny84-20.bootloader.high_fuses=0xdf
attiny84-20.bootloader.extended_fuses=0xff

attiny84-20.upload.maximum_size=8192

attiny84-20.build.mcu=attiny84
attiny84-20.build.f_cpu=20000000L
attiny84-20.build.core=arduino:arduino
attiny84-20.build.variant=tiny14


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jun 09, 2013, 09:16 am
Ok well I personally find it hard to work with.
Quote

Code: [Select]

###########################################################################
attiny13.name=Attiny13 @ 16 KHz (internal 128 KHz watchdog oscillator/8)

attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.maximum_ram_size=64

attiny13.bootloader.low_fuses=0x2B
attiny13.bootloader.high_fuses=0xFF

attiny13.build.mcu=attiny13
attiny13.build.f_cpu=16000L
attiny13.build.core=core13


DAMN that is slow (is this thing on?)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on Jun 25, 2013, 09:29 pm
I confirm there are some problems with analogRead.

in my case, the reading seem to depend on the output of an adjacent pin.

Any ideas?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jun 27, 2013, 08:41 am
Make sure you don't have any floating inputs first of all.
I haven't set up the test rig lately - I need to be less lazy and start working on this.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on Jun 27, 2013, 11:29 am

Make sure you don't have any floating inputs first of all.
I haven't set up the test rig lately - I need to be less lazy and start working on this.


what do you mean by floating inputs?

I store the reading in variable of type int.

Thanks for your work
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jun 27, 2013, 07:26 pm
Floating input means the pin is not held at a defined value. What is the external circuit?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: ProfePaco on Jun 29, 2013, 03:08 pm

Floating input means the pin is not held at a defined value. What is the external circuit?


the external circuit is just a voltage divider (two resistances ) to measure the voltage of a battery.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jun 29, 2013, 10:55 pm
It seems like you are either reading from the wrong pin or the pin is floating.

I will have to test it when I get a chance though.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Jun 30, 2013, 02:24 am
You need to have a 0.1uF ceramic decoupling capacitor between VCC and GND.  Otherwise the ADC will not have a stable reference source to make reliable conversions.  It really does makes a difference in ADC readings.  I have confirmed this with an ATtiny13A with and without a decoupling capacitor.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 02, 2013, 09:05 am
I did some limited testing and the ADC seems to be functioning normally.

Can you post your exact circuit and code?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hypermax on Jul 17, 2013, 05:16 pm
Hi,

I want to realize a simple Servo control (with an Attiny13), but the Servo Libary isn't working correctly. While compiling there are several fails:

Code: [Select]
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp: In function 'void TIMER1_COMPA_vect()':
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:105: error: 'TCNT1' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:105: error: 'OCR1A' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp: In function 'void initISR(timer16_Sequence_t)':
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:151: error: 'TCCR1A' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:152: error: 'TCCR1B' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:152: error: 'CS11' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:153: error: 'TCNT1' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:159: error: 'TIFR1' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:159: error: 'OCF1A' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:160: error: 'TIMSK1' was not declared in this scope
C:\Users\m.aust.SFT\Documents\Arduino\arduino-1.0.4\libraries\Servo\Servo.cpp:160: error: 'OCIE1A' was not declared in this scope


Is it a known Problem? And how can i solve it?
Thanks for help

Max

Sketch code:
Code: [Select]
#include <Servo.h>

//Definition der Lagen
int mitte = 90;
int unten = 0;
int oben = 180;

//Für eventuelle Wartezeiten
int del = 0;

//Hardware Konfiguration
Servo out;
int in1 = 2;
int in2 = 3;

void setup()
{
 pinMode(in1, INPUT);
 digitalWrite(in1, HIGH);
 pinMode(in2, INPUT);
 digitalWrite(in2, HIGH);
 out.attach(1);
}

void loop()
{
 //wenn kein signal kommt Mittelposition anfahren
 anfahren(mitte);
 delay(del);
 
 //wenn ein signal kommt, die entsprechende Position anfahren
 if(digitalRead(in1) == LOW)
 {
   anfahren(unten);
   delay(del);
 }
 
 if(digitalRead(in2) == LOW)
 {
   anfahren(oben);
   delay(del);
 }
}

void anfahren(int pos)
{
 int akt = out.read();
 
 while (akt != pos)
 {
   if(akt < pos)
   {
     out.write(akt++);
   }
   else if(akt > pos)
   {
     out.write(akt--);
   }
   
   delay(10);
   akt = out.read();
 }
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Jul 17, 2013, 06:35 pm
Attiny13 does not have a Timer1, and it only have 1.000 bytes of Flash for your sketch, so yes it is a known problem

If you have a Attiny85/Attiny45, there is a special servolibrary you can use
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 18, 2013, 02:34 am
The problem is the servo library uses hardware specific code and thus non-portable.
It would need to be rewritten for the Attiny13 specifically.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Jul 22, 2013, 04:44 pm
I just found this servo example on Avrfreaks.net.

ATTiny13 @ 9,6MHz

Drawbacks: only 100 steps, and only one servo


Code: [Select]

#include <avr/io.h>
#include <avr/delay.h>
#include <avr/interrupt.h>

//http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=74861&start=0
volatile unsigned int Tick;   // 100KHz pulse
volatile unsigned int sPulse;   // Servo pulse variable
volatile unsigned int Tick_20ms;   // Servo frame variable

void setup() {  

 OSCCAL=0x68;
 pinMode(4,OUTPUT);
 pinMode(3,INPUT);
 cli();
 TCNT0 = 0;
 TCCR0A=0;
 TCCR0B=0;

 TCCR0A |= (1<<WGM01); // Configure timer 1 for CTC mode
 TIMSK0 |= (1<<OCIE0A); // Enable CTC interrupt
 TCCR0B |= (1<<CS00); // No prescaler
 OCR0A = 95; // Set CTC compare value
 sei(); //  Enable global interrupts
 Tick = 0;
 sPulse = 100;
 Tick_20ms = 0;
}


void loop()
{
 //int val=analogRead(3); //use potmeter on PB3
 //sPulse=50+(val/10);

 for(int x=50;x<150;x++){

   sPulse=x;
   _delay_ms( 5 );
 }

 for(int x=149;x>=50;x--){

   sPulse=x;
   _delay_ms( 5 );
 }


}



ISR(TIM0_COMPA_vect)   // 100 KHz interrupt frequency
{
 if(Tick >= 2000)   // One servo frame (20ms) completed
 {
   Tick = 0;
   Tick_20ms = Tick_20ms + 1;
 }

 Tick = Tick + 1;
 if(Tick <= sPulse)   // Generate servo pulse
 {
   PORTB |= (1<<PB4);   // Servo pulse high
 }
 else
 {
   PORTB &= ~(1<<PB4);   // Servo pulse low
 }
}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hypermax on Jul 25, 2013, 09:11 am
Thank you very much, it helped a lot

Max
Title: 019 version
Post by: jeka_tm on Sep 06, 2013, 08:18 pm
when there will be 019 version? required internal voltage reference
also tested people with ARDUINO.RU. Analog input only works on RB3 pin attiny13. maybe we're doing something wrong?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sparkylabs on Sep 08, 2013, 02:58 pm
my IDE does not pick up on the new board configs, I down loaded from sourceforge.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 12, 2013, 05:56 am
Quote

when there will be 019 version? required internal voltage reference
also tested people with ARDUINO.RU. Analog input only works on RB3 pin attiny13. maybe we're doing something wrong?

Internal voltage reference should already work.
I will try to debug the analog input soon. It is one of the hardest part to work on.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 12, 2013, 05:56 am

my IDE does not pick up on the new board configs, I down loaded from sourceforge.
http://elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sparkylabs on Sep 14, 2013, 04:41 pm
uh how complicated. can't i just download the core and put it in the hardware folder like any other ? or does it need extra files.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 15, 2013, 01:11 am

uh how complicated. can't i just download the core and put it in the hardware folder like any other ? or does it need extra files.

I know. The arduino boards.txt are horrendous. But that's how it works.
I have alot of trouble with it myself
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: reginr on Nov 07, 2013, 12:59 pm
BUMP:

I am trying to upload using USBISP.

A little help please.  Many thanks

Code: [Select]

avrdude: Version 5.11, compiled on Sep  2 2011 at 18:52:52
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/regin_rodriguez/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
avrdude: seen device from vendor ->www.fischl.de<-
avrdude: seen product ->USBasp<-
         AVR Part                      : ATtiny13
         Chip Erase delay              : 4000 us
         PAGEL                         : P00
         BS2                           : P00
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no         64    4      0  4000  4000 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6    32    0 yes      1024   32     32  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          2    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: auto set sck period (because given equals null)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9007
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: auto set sck period (because given equals null)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "/var/folders/98/98SOfbC9HsmpXuuVf9fn0E+++TI/-Tmp-/build3124297909485718164.tmp/BlinkATtiny13.cpp.hex"
avrdude: writing flash (378 bytes):

Writing | ################################################## | 100% 0.19s

avrdude: 378 bytes of flash written
avrdude: verifying flash memory against /var/folders/98/98SOfbC9HsmpXuuVf9fn0E+++TI/-Tmp-/build3124297909485718164.tmp/BlinkATtiny13.cpp.hex:
avrdude: load data flash data from input file /var/folders/98/98SOfbC9HsmpXuuVf9fn0E+++TI/-Tmp-/build3124297909485718164.tmp/BlinkATtiny13.cpp.hex:
avrdude: input file /var/folders/98/98SOfbC9HsmpXuuVf9fn0E+++TI/-Tmp-/build3124297909485718164.tmp/BlinkATtiny13.cpp.hex contains 378 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.12s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x09 != 0x00
avrdude: verification error; content mismatch

avrdude done.  Thank you.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Nov 07, 2013, 03:46 pm
This usually comes down to a few problems:

* Wiring problem such as short circuit or target device not powered
* SPI clock too fast
* Wires are too long between the programmer and device
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: reginr on Nov 07, 2013, 04:27 pm
smeezekitty,

Thanks for the response, I really appreciate it.  I think I can verify the first and the third one you said. But I don't know how to slowdown the spi clock if that is the case.

I am using one of the cheap USBISP programmer from China.
http://www.ebay.com/itm/130682846209?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
It works OK with my arduino pro mini 3.3v

Again any additional advise about the spi clock is apprciated!



Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Nov 07, 2013, 06:39 pm
avrdude: warning: cannot set sck period. please check for usbasp firmware update.


That's not good. Looks like it does not support software SCK changes.

Does your programmer happen to have a jumper anywhere on it?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: reginr on Nov 08, 2013, 03:33 am
smeezekitty,

Thanks again from your support!
To answer you question. There is a place to solder a jumper but after comparing it with the opensource schematic and actual connection on the PCB I think it is not the Slow SCK settings.

I diverted to an old Arduino Diecimila with atmega328p Installed

and upload worked like a charm! Many thanks again for sharing your library!!!

Greetings from Japan!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Nov 08, 2013, 03:39 am

smeezekitty,

Thanks again from your support!
To answer you question. There is a place to solder a jumper but after comparing it with the opensource schematic and actual connection on the PCB I think it is not the Slow SCK settings.

I diverted to an old Arduino Diecimila with atmega328p Installed

and upload worked like a charm! Many thanks again for sharing your library!!!

Greetings from Japan!


You might try to see if there happens to be a firmware update.
I was considering buying one of those programmers but if it does not support software SCK that is kind of a let down.

Good luck from across the pacific
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Docedison on Nov 08, 2013, 04:45 am
There is an upgrade to the firmware in the programmer here is the thread that covers it, There are several others as well..
http://forum.arduino.cc/index.php?topic=149668.0 (http://forum.arduino.cc/index.php?topic=149668.0) and it should addresss your difficulties.

Doc
Title: Sleep and Interrupts
Post by: reginr on Nov 13, 2013, 05:36 am
Hello Smeezekitty,

I have a quick question. 
Do you also have powersaving fuctions by chance?
(e.g. sleep, interrupt)


Thanks for reading,
Title: Re: Sleep and Interrupts
Post by: smeezekitty on Nov 13, 2013, 05:58 am

Hello Smeezekitty,

I have a quick question. 
Do you also have powersaving fuctions by chance?
(e.g. sleep, interrupt)


Thanks for reading,


No, but the AVR-LIBC sleep system is not all that hard to work with: http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html
Title: ADC Test only works with PB3
Post by: reginr on Nov 13, 2013, 09:53 am
Smeezekitty,
Again, many thanks for your kind support.
Just to let you know regarding ADC I am only having good readings with PB3 I have readings below:
3.3v = 1023
0.0v= 0

But when I use PB0,PB1,PB2,PB4 as Analog inputs I get erattic values, it never gets stable

Code below is what I used to check the value.
I used a 1Kohm potentiometer with the ends connected to GND and 3.3V and the middle connected to ADC input (PB0-PB4) and Only PB3 Worked.


Code: [Select]

/* attiny13 ADC Test */
/* flashing results via ledPin */

#define inputPin PB3
#define ledPin PB4
#define ON_DELAY 700
#define OFF_DELAY 1200
#define PAUSE_DELAY 4000
#define CHANGE_TRESHOLD 20

int current_reading=0;
int new_reading=0;
int offset=0;

void setup(){
 delay(10000);
 pinMode(ledPin,OUTPUT);
 pinMode(inputPin,INPUT);
 ledBlink(3);
 delay(10000);
}//void setup()

void ledBlink(int count){

 if(count>0){
   for(int n=0,m=ON_DELAY;n<count;n++,m+=100){
     digitalWrite(ledPin,HIGH);
     delay(m);
     digitalWrite(ledPin,LOW);
     delay(OFF_DELAY);
   }//for
 }//if

 //flash a dim light for zero value
 else{
   for(int n=0;n<10;n++){
     digitalWrite(ledPin,HIGH);
     delay(3);
     digitalWrite(ledPin,LOW);
     delay(160);
   }//for
 }//
 delay(PAUSE_DELAY);
}//void blink(count)

void loop(){
 
  new_reading=analogRead(inputPin);  
  if(new_reading!=current_reading){    
     if(new_reading-current_reading<0)
       offset=current_reading-new_reading;
     else
       offset=new_reading-current_reading;
       
     if(offset>=CHANGE_TRESHOLD){      
      current_reading=new_reading;      
      //Flash-blink the values
         ledBlink(new_reading/1000);
         new_reading=new_reading%1000;
         ledBlink(new_reading/100);
         new_reading=new_reading%100;
       ledBlink(new_reading/10);
         new_reading=new_reading%10;
         ledBlink(new_reading);
         delay(10000);
     }//if
  }//if
}//void loop
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Nov 14, 2013, 10:29 am

When reading analog values you use the ADC number, so for example reading pin PB2 you should use analogRead(1);

pin PB2  analogRead(1);
pin PB4  analogRead(2);
pin PB3  analogRead(3);

To get stable readings connect a 100nF capacitor between Gnd and Vcc
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: reginr on Nov 15, 2013, 12:28 am
Hello Erni,

Thanks for the advise! What kind of capacitor do I need? Will any do? or Should it be a polarized one? (E.G. Electrolytic capacitor)

Thanks in advance!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Nov 15, 2013, 12:37 pm
Quote
What kind of capacitor do I need?


I am no electronic expert, but a qute from a forum member that is expert

http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Quote
The type of capacitor construction that produces the lowest inductance is the ceramic type and those are always used for the smaller capacitors.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Nov 16, 2013, 11:39 pm
Pretty much any type of electrostatic capacitor 0.05 - 0.22 uf would work
Title: I can blink LED with this core
Post by: attiny13a on Nov 21, 2013, 12:52 pm
Thank you so much!
Title: Report: analogWrite() not working.
Post by: attiny13a on Dec 11, 2013, 08:57 pm

map()
random()
randomSeed()
millis()
micros() *
delay()
delayMicroseconds()
analogRead()
analogWrite()
pinMode()
digitalRead()
digitalWrite()


Hello  :)

Just a quick comment about the "analogWrite().  I tried using it to set brightness/color on RGB LED;
I used:

ADC1, ADC2, ADC3 Pins

All it does is turn the LED on and off at a certain value (cant tell no Serial.println).
Also I got confused when I checked the datasheet of attiny13 and  saw the ADC articles (is it the same as DAC?)
Lastly, I saw somewhere along this thread about PWM. which made  more confuse.

To control an RGB LED using attiny13:


Please advise and thanks in advance!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Dec 11, 2013, 10:05 pm
There is only two pwm pins availeble on the ATtiny13:
PB0 and PB1
Title: attiny13 Only 2 PWMs?
Post by: attiny13a on Dec 11, 2013, 10:18 pm

There is only two pwm pins available on the ATtiny13:
PB0 and PB1


Thanks for the note!
Now I am puzzled.  I saw some youtube videos demonstrating RGB on the attiny13.
Does this suggest they did not used the 2 PWMs or they have made their own 3rd PWM?

Thanks in advance!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Dec 11, 2013, 10:37 pm
They most likely used software PWM
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Dec 12, 2013, 12:19 am
You could try this soft_pwn sketch.

It fades leds on pin 0,3 and 4
Note if you use a RGB Led with common anode you wil have to reverse the logic.

Code: [Select]

int led[]={0,3,4};
int count=0;

void setup(){
for (int z=1;z<6;z++){

pinMode(led[z],OUTPUT);

} //for z
}


void loop(){
 
for (int x=1;x<254;x++){
  spwm(x,led[count],15);
}
for (int x=254;x>0;x--){
  spwm(x,led[count],15);
}

count++;
  if (count>2){
count=0;
}

}


void spwm(int freq,int spin,int sp){

  //on
digitalWrite(spin,HIGH);
delayMicroseconds(sp*freq);

// off
digitalWrite(spin,LOW);
delayMicroseconds(sp*(255-freq));


} //spwm

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: attiny13a on Dec 13, 2013, 07:42 am

When reading analog values you use the ADC number, so for example reading pin PB2 you should use analogRead(1);
pin PB2  analogRead(1);
pin PB4  analogRead(2);
pin PB3  analogRead(3);


Thanks for this note I needed this!
May I know what is the inside code of analogRead()
I want to understand why it can not accept PORTBx instead.

Thanks in advance!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Dec 13, 2013, 09:23 am
Code: [Select]

int analogRead(uint8_t pin){
uint8_t l,h;
//ADMUX = (1<<REFS0) | pin & 3; //Setup ADC
ADMUX = ADMUX & _BV(REFS0) | pin & 3; //Setup ADC, preserve REFS0
ADCSRA |= _BV(ADSC);
while(ADCSRA & 1<<ADSC); //Wait for conversion
l = ADCL;  //Read and return 10 bit result
h = ADCH;
return (h << 8)|l;
}

In short, I omitted pin conversion code to save flash space.
Title: analogRead() Question
Post by: attiny13a on Dec 14, 2013, 12:58 am
Code: [Select]
//ADMUX = (1<<REFS0) | pin & 3;         //Setup ADC
  ADMUX = ADMUX & _BV(REFS0) | pin & 3; //Setup ADC, preserve REFS0

smeezekitty thank you for the post!

Just a quick question:

Thanks in advance!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Dec 14, 2013, 04:27 am
I commented it out because it was the older code that didn't allow selecting VREF.
I replaced it with the newer more flexible code. I had it commented incase I needed to revert

I will remove it in the 0.19 revision
Title: ERROR: Interrupt Service Routine Setup (ISR)
Post by: attiny13a on Dec 16, 2013, 07:21 am
Thank you so much for all the support an help.
Just a quick query about using ISR along with the library.
Thank you so much in advance!  :)

Error is encountered during compilation:
Code: [Select]

core.a(wiring.c.o): In function `__vector_3':
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/core13_018/wiring.c:13: multiple definition of `__vector_3'
attiny13CoreTest.cpp.o:/Applications/attiny13CoreTest.ino:7: first defined here


Code is below:
Code: [Select]

#include "avr/interrupt.h"
#include "avr/io.h"

void setup(){
   //blank
}// setup

void loop(){
   //blank
}//loop()

ISR (TIM0_OVF_vect){
   //blank
}//ISR
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Dec 16, 2013, 09:31 am
Because the core already hooks timer 0. You cannot use it like that.
You could modify the core hook to call a user function if you need to
Title: Question: Template for Timer_0 access
Post by: attiny13a on Dec 16, 2013, 10:59 am

Because the core already hooks timer 0. You cannot use it like that.


smeezekitty, thank you again for the insight! I am not familiar with "hooks" could you please show me a sample template to uitlize the timer 0 function.

thank you in advance!!!

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Dec 16, 2013, 09:11 pm
In wiring.c
Code: [Select]

ISR(TIM0_OVF_vect){
ovrf++; //Increment counter every 256 clock cycles
}

You can add a user function call to the ISR hook although it is kind of a hack
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Feb 17, 2014, 11:59 pm
Wow this got all the way to page 17

I will hook up the development board soon to see if I can make some improvements
for the first release of 2014
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Apr 13, 2014, 02:56 pm
Hello i just wanted to say a BIG thank you for the core13 really nice work, its amazing how much you can squeeze into a attiny13.
thanks to your core i managed to get my nrf24l01 remote control transmitter to work on attiny13(with 3 byte to spare..) so thank you again.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Apr 20, 2014, 08:49 pm

Hello i just wanted to say a BIG thank you for the core13 really nice work, its amazing how much you can squeeze into a attiny13.
thanks to your core i managed to get my nrf24l01 remote control transmitter to work on attiny13(with 3 byte to spare..) so thank you again.

Congratulations.
I found it surprising nobody else had a solid Attiny13 core so I decided I might as well make one
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: idris on Apr 27, 2014, 03:23 am
17  pages way too long for me to read. any shortcut link/tutorial/etc to upload code for attiny13 using arduino ide
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Docedison on Apr 27, 2014, 08:01 pm
Waah...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dwhacks on May 03, 2014, 11:14 pm
Im not sure If I have an older version of the core13 installed, but as I change the clock speed of the tiny (via burn bootloader) it changes the amount of "delay" time. Why is this?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 09, 2014, 08:39 pm

Im not sure If I have an older version of the core13 installed, but as I change the clock speed of the tiny (via burn bootloader) it changes the amount of "delay" time. Why is this?

Did you change F_CPU to match?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dwhacks on May 10, 2014, 05:06 am
In my boards.txt file? I believe so. It is like this:

Code: [Select]

###########################################################################
attiny13int.name=Attiny13a @ 128 KHz (internal watchdog oscillator)
attiny13int.upload.using=usbtinyisp
attiny13int.upload.maximum_size=1024
attiny13int.upload.speed=250 # important for not losing connection to a slow processor
attiny13int.bootloader.low_fuses=0x7B
attiny13int.bootloader.high_fuses=0xFF
attiny13int.bootloader.unlock_bits=0x3F
attiny13int.bootloader.lock_bits=0x3F
attiny13int.build.mcu=attiny13
attiny13int.build.f_cpu=128000
attiny13int.build.core=core13

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

attiny13at4.name=ATtiny13a @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.upload.using=usbtinyisp
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13
###############################################################

attiny13.name=ATtiny13a @ 9.6MHz (internal 9.6 MHz clock)
attiny13.upload.using=usbtinyisp
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff
attiny13.upload.maximum_size=1024
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=1200000
attiny13.build.core=core13

###############################################################
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 10, 2014, 06:54 am
Code: [Select]

###########################################################################
attiny13int.name=Attiny13a @ 128 KHz (internal watchdog oscillator)
attiny13int.upload.using=usbtinyisp
attiny13int.upload.maximum_size=1024
attiny13int.upload.speed=250 # important for not losing connection to a slow processor
attiny13int.bootloader.low_fuses=0x7B
attiny13int.bootloader.high_fuses=0xFF
attiny13int.bootloader.unlock_bits=0x3F
attiny13int.bootloader.lock_bits=0x3F
attiny13int.build.mcu=attiny13
attiny13int.build.f_cpu=128000
attiny13int.build.core=core13

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

Good
Code: [Select]

attiny13at4.name=ATtiny13a @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.upload.using=usbtinyisp
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13
###############################################################

Values are ok, but it is actually for 600Khz so the name is wrong
Code: [Select]

attiny13.name=ATtiny13a @ 9.6MHz (internal 9.6 MHz clock)
attiny13.upload.using=usbtinyisp
attiny13.bootloader.low_fuses=0x7a
attiny13.bootloader.high_fuses=0xff
attiny13.upload.maximum_size=1024
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=1200000
attiny13.build.core=core13

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

This is wrong. The fuses are set for 9.6MHz no divider but FCPU is set to 1.2MHz
Change FCPU to 9600000
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dwhacks on May 11, 2014, 01:50 am
Thanks,
So for 4.8 mhz I just to make the High fuse 0xFF? and my f_cpu 4800000?

Is there a way to have 8 mhz?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 11, 2014, 05:17 am

Thanks,
So for 4.8 mhz I just to make the High fuse 0xFF? and my f_cpu 4800000?

No. You need to change the low fuse to 0x79 instead of 0x69
Quote

Is there a way to have 8 mhz?

External oscillator
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dwhacks on May 25, 2014, 04:14 am
Is there analogReference on this chip with this core? And are there different internal ones like the other avr's? I need to read some pretty low values on the ADC so if the standard is 5v reference then that wont be very good!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on May 25, 2014, 08:46 am
i am using the internal 1.1v ref with no problem, just put  analogReference(INTERNAL); in setup and it should work, care to share what you are working on? i am always looking for new projects to try out on this core.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 25, 2014, 08:23 pm
Yes the 1.1V reference works. But make sure you use the latest version because it was not supported in old versions
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: neu-rah on Jun 06, 2014, 06:19 am
Tested this ok, I have a slight different folder structure (just addapted a bit there for my sketches/hardware folder), i'm running the attiny13a @ 5V 9.6MHz (lfuse: 7A hfuse: FF),  F_CPU = 12MHz, still the delay is not accurate, guess i could do a calibration here.
Programming it with an usbasp programmer (guess my raspi would program it too)
burned fuses with avrdude:
    avrdude -pt13 -cusbasp -Pusb -U lfuse:w:0x7A:m -U hfuse:w:0xFF:m
    or avrdude -pt13 -cusbasp -Pusb -U lfuse:w:0x7A:m -U hfuse:w:0xFF:m
    depending on how the board was called on the avrdude.conf file (avrdude -p? for a list of boards)
some might change -P and -c if using another programmer

I had to edit my avrdude.conf and changed the "t13" to "attiny13a" because thats how the IDE was refering it (use verbose mode for details) so after the change i had to refer to the board as attiny13a when using avrdude from command line

here is my 208 bytes blink program:

#define LED 2

void setup() {
  DDRB=DDRB&~(1<<LED)|(1<<LED);//set LED as output
}

void loop() {
  PORTB^=(1<<LED);//blink LED
  delay(500);
}

i have to add an Arduino.h file (using IDE 1.0.5)
also on my linux (ubuntu 14.04) system i had to create a link for

   /usr/lib/avr/lib/avr25/tiny-stack/crttn13a.o -> /usr/lib/avr/lib/avr25/crttn13a.o

thanks for the core :D
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: john1993 on Jun 07, 2014, 10:31 am

Is there a way to have 8 mhz?


8mhz is very easy by simply adjusting the osccal register. i do this on all my t13 projects to compensate for the oddball clock. now the same code works for nearly all my avr projects.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Jul 19, 2014, 09:01 am

Hello i am trying to fit a weather station transmitter code into a attiny13 and its working as it is but i need a bit more space to get the sleep code in, to make it usable with batteries. This is the code as of now any tip on where/how i can make the code smaller??





Code: [Select]
//WH2 transmitter weather station

#define rf_ut 0    //433 transmitter on pin 0


#define  onee 470      //Timings for transmitting
#define  zero 1430
#define  space 930

byte wh2_packet[5];      //Packets to send
//byte wh2_calculated_crc;






int main(void){
init();
{



 
 
  wh2_packet[0]=75;      //First 12 bits transmitter id and stuff (8 bits here and 4 in next packet)
  wh2_packet[1]=80;      // 4 bits id and rest temperature bit 3 set bit for -+ and 0-2 highest bits in 11 bit temp 260=26,0 C
//  wh2_packet[2]=138;   //last 8 bits in temp
  wh2_packet[3]=255;    //humidity set no senstor for it so set to 255
 
 
   analogReference(INTERNAL);      //internal ADC

/*
 
  wh2_packet[0]=B01001011 ;
  wh2_packet[1]=B01010000 ;
  wh2_packet[2]=B10001010 ;
  wh2_packet[3]=B11111111  ;
  //wh2_packet[4]=B01010111;
 
 
*/
 
  /*
  wh2_packet[0]=B01000011;
  wh2_packet[1]=B10010001;
  wh2_packet[2]=B11111111;
  wh2_packet[3]=B00000000;
  wh2_packet[4]=B00111000;
  */
 

  pinMode(rf_ut, OUTPUT);
 
   //setup
}



while(1) {
 
 
 

  unsigned int temp=analogRead(A1);    //read temp tmp 36 sensor
 
   if(temp<467)          //trying to map the temperature/voltage without long or float not perfect but -+1 or 2 deg ok for now
{                                    //1023 adc to 1100 mv, 500-1100 positive temp in c, 500-0 negative temp in c
  temp=(temp*107)/100;
  temp=500-temp;
//temp=temp*(-1);
bitSet(wh2_packet[1], 3);        //bit for negative temp 1=neg 0=+
}

else
{
bitClear(wh2_packet[1], 3);



temp=temp-467;                           //467 is the adc of 500 mv-+
temp=(temp*107)/100;
}
 
 
 
//moving temperature into the right bits
//3 lowest bits in  wh2_packet[1] and all bits in wh2_packet[2]
int counter=2;

while(counter>(-1))
{
 
  bitWrite(wh2_packet[1], counter, bitRead(temp, counter+8));
  counter--;
   
}
 
  counter=7;
   while(counter>(-1))
{
 
  bitWrite(wh2_packet[2], counter, bitRead(temp, counter));
  counter--;
   
}

//wh2_packet[3]=temp;


 

  //crc over the first 4 bits stolen from resciever end
 
  wh2_packet[4] = crc8(wh2_packet, 4);


//Sending first 8 bits B11111111 to initinate resciever

    sendd(255);
   sendd(wh2_packet[0]);
   sendd(wh2_packet[1]);
   sendd(wh2_packet[2]);
   sendd(wh2_packet[3]);
   sendd(wh2_packet[4]);
  delay(1000);
 
 
 
 
 
 
//code
                                 
}
}

uint8_t crc8( uint8_t *addr, uint8_t len)
{
  uint8_t crc = 0;

  // Indicated changes are from reference CRC-8 function in OneWire library
  while (len--) {
    uint8_t inbyte = *addr++;
    for (uint8_t i = 8; i; i--) {
      uint8_t mix = (crc ^ inbyte) & 0x80; // changed from & 0x01
      crc <<= 1; // changed from right shift
      if (mix) crc ^= 0x31;// changed from 0x8C;
      inbyte <<= 1; // changed from right shift
    }
  }
  return crc;
}


void sendd(byte number)

{
int counter1=7;



  //-----preamble---------------------------------
 
    while(counter1>-1)
    {
   
    if((bitRead(number, (counter1)))==1 )
    {
    digitalWrite(rf_ut,HIGH);
    delayMicroseconds(onee);
   
    }
      else
      {
          digitalWrite(rf_ut,HIGH);
          delayMicroseconds(zero);
      }
      digitalWrite(rf_ut,LOW);
      delayMicroseconds(space);
      counter1--;
    }


}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: john1993 on Jul 19, 2014, 06:22 pm
recompiling with winavr using "naked" directive will save about 30%. rewriting in asm about half. all tools to these are included in arduino.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 19, 2014, 08:47 pm
You can call _delay_ms() yourself instead of delay since you don't need a variable argument
which *might* save a few bites. A word of warning though:

The internal clock in the '13 is marginally accurate at best and is voltage and temperature dependent
Things that need tight timing like generating rf signal pulses might not work as you expect
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Jul 20, 2014, 02:48 pm
Thank you both for the tips, i have managed to get the sleeping function in now, so its sleeping at 3uA now.

Ye i know the clock are temperamental lol, but i am lucky the receiver side of things are very forgiving with the timing. I have the transmitter in the freezer now its -27 C in there and it is still sending out OK signals so i think it will do.

Thank you again for this Core as of now i have 4 projects running with it and more to come.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 02, 2014, 08:30 am
First release (minor update) of 2014
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Sep 06, 2014, 08:00 am
Thank you for the update, i will give it a test over the weekend.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 06, 2014, 09:44 am
This is brilliant !! Good work SmeezeKitty, I have been looking for a way to use 13's from my IDE and this is perfect

Ideally I want to run at 8mhz, I guess others have commented on this too, but I havent read all 16 pages of posts yet

Are the cores stable ? on page 1 you mentioned that alot is untested, is this still the case ?

Regards Bob
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 07, 2014, 12:42 am

This is brilliant !! Good work SmeezeKitty, I have been looking for a way to use 13's from my IDE and this is perfect

Ideally I want to run at 8mhz, I guess others have commented on this too, but I havent read all 16 pages of posts yet

Are the cores stable ? on page 1 you mentioned that alot is untested, is this still the case ?

Regards Bob

It runs fine on 8MHz but you need to use an external oscillator (which uses up an I/O pin)
The internal clock options are 128KHz, 600KHz, 1.2MHz, 4.8MHz, 9.6MHz
None of which are particularly accurate  :P
But they are R/C oscillators

It is pretty stable now. At first I had a lot of problems with hanging especially during I/O
but I think I have that problem more or less solved. There are still some functions I have not thoroughly tested.
Partly because it isn't that easy to test without UART. And partly because I haven't had much time lately.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 07, 2014, 10:37 am
thats ok, I can work with 9.6mhz..

for comms have you considered making a few timing adjustments to tinydebug ? or would that take up too much flash ?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Erni on Sep 07, 2014, 05:42 pm
Quote
for comms have you considered making a few timing adjustments to tinydebug ?


Regarding smeezekitty's core and TinyDebug see this

http://forum.arduino.cc/index.php?PHPSESSID=ugfk8b6of564ohs1btn2lpfb10&topic=123388.75
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: fusionstream on Sep 13, 2014, 01:18 pm
Will this work as is with a 10 pin attiny13?

I noticed that you commented out:
/*#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7*/

But I don't understand what it means.

I'm looking to create a very small single rgb led controller while being able to check the input of 2 pins and supporting i2c so I can communicate to other controllers.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 13, 2014, 01:44 pm

Will this work as is with a 10 pin attiny13?


Huh?  Do you mean the 10-pin QFN package?  This still has only 6 usable pins.  PB0 - PB5.

The attiny13 only has two PWM output pins so you wouldn't be able to properly control an RGB LED.

You will need to go with an attiny85 which does have 3 PWM output pins.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 02:28 pm
Quote
The attiny13 only has two PWM output pins so you wouldn't be able to properly control an RGB LED.


Unless you use a WS2812 rgb LED, I have just finished writing my code to convert DMX (250kbps) to WS2812 (800khz), it is currently only 950 bytes and runs on an ATTiny85 @ 8mhz perfectly, when my ATTiny13's arrive this will be my first project

Its written in C and assembler, but once I get confident enough I will convert it over to all assembly

I have just 90 bytes left to squeeze in an up/down button input to set the DMX receive channel :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 13, 2014, 03:35 pm
That is very interesting.  Adafruits NeoPixel code does not currently support the attiny13 due to internal clock rate differences and the minimum flash size need to be at least 2.5K.

 So you have custom code that can support the attiny13 clock rates and flash size?  Can you share your code?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 05:52 pm
Its a bit knife and fork, but it works, I intend to use it on the ATTiny13 (1k flash / 60 bytes ram)
just need a few defines, and set your port, and DDR... WS2812 routine is left for you to include/adjust how you like

code modified from here -> http://www.instructables.com/id/Bitbanging-step-by-step-Arduino-control-of-WS2811-/#step0 (http://www.instructables.com/id/Bitbanging-step-by-step-Arduino-control-of-WS2811-/#step0)

Code: [Select]

#define DIGITAL_PIN   (2)         // Digital port number
#define PORT          (PORTB)     // Digital pin's port
#define PORT_PIN      (PORTB2)    // Digital pin's bit position

unsigned long  latch50us;

void setup(void) {
// setups and DDR
}

void loop(void) {
WS2812();
delay(10);
}

void WS2812(void) {
    while((micros() - latch50us) < 50L);  // 50us data latch
    cli();
    volatile uint8_t green = 50; // choose your values for RGB
    volatile uint8_t red = 191;
    volatile uint8_t blue = 45;
    asm volatile(
      "rcall dobits\n\t"    // do green
      "mov %5, %6\n\t"
      "rcall dobits\n\t"    // do red
      "mov %5, %7\n\t"
      "rcall dobits\n\t"    // do bloo
      "rjmp out\n\t"
    "dobits:\n\t"           // label
      "ldi  %4, 8\n\t"      // reset number of bits
    "nextbit:\n\t"          // label                       
      "sbi  %0, %1\n\t"     // SET OUTPUT HIGH
      "sbrc %5, 7\n\t"      // Skip if HiBit in value is clear 
      "rjmp bitset\n\t"     // jump if HiBit is set
      "cbi %0, %1\n\t"      // SET OUTPUT LOW
      "rol  %5\n\t"         // shift value left to get to next bit
      "dec  %4\n\t"         // decrement nBits
      "brne nextbit\n\t"    // branch if bits not finished
      "ret\n\t"
    "bitset:\n\t"           // label
      "rol  %5\n\t"         // shift value left to get to next bit
      "cbi %0, %1\n\t"      // SET OUTPUT LOW
      "dec  %4\n\t"         // decrement nBits
      "brne nextbit\n\t"    // branch back if bits not finished
    "ret\n\t"               // return from sub
    "out:\n\t"              // exit
      ::
      // Input operands         Operand Id (w/ constraint)
      "I" (_SFR_IO_ADDR(PORT)), // %0
      "I" (PORT_PIN),           // %1
      "e" (&PORT),              // %a2
      "w" (NULL),              // %3
      "r" (8),                // %4
      "r" (green),              // %5
      "r" (red),                // %6
      "r" (blue)                // %7
    );
  sei();                       
  latch50us = micros();                 
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 05:53 pm
I forgot to mention, I am just writing to a single WS2812 at the moment, but i guess the code can be adjusted to write to more
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 13, 2014, 07:40 pm
Quote

I have just 90 bytes left to squeeze in an up/down button input to set the DMX receive channel

Well that isn't necessarily true. When you switch to a different core the compiled code size may go up or down
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 08:14 pm
dammit !! you could be right there, I havent installed the cores yet... I should do that and compile and see for myself !

Thanks :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 08:30 pm
Great news...

just downloaded, installed core13 etc...

my sketch compiles to 950 bytes with the ATTiny85, and only 774 bytes with the ATTiny13 cores

*cracks open bottle of wine* :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 13, 2014, 10:49 pm
@mcnobby tried your code on an attiny85 @8MHz and attiny13a @9.6MHz but couldn't get any pixel to light up.  To note I was able to run adafruit's NeoPixel code on the attiny85 without any issues.  Which attiny85 core were you using?

I'm guessing though for the tiny13 the timing would need to be adjusted for 9.6MHz.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 11:04 pm
I must admit this was an excerpt from something I am writing, so I did put the whole sketch
Well it works perfectly for me, perhaps I will make a standalone sketch with just the code the works and post that.. tomorrow maybe :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 13, 2014, 11:06 pm
I think I am using the attiny-master core, I found it ages ago on here, cant say exactly where I found it though, but everything works fine for me
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 13, 2014, 11:51 pm
Keep in mind  the timing of the RC oscillators is hit or miss.
Also core13 is designed to minimize the amount of timer interrupts and thus has less granularity
How close to 50uS do you need?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 14, 2014, 02:54 am
@mcnobby I had to setup the pin for output mode.  Then it worked with my t85.

Code: [Select]

void setup(void) {
// setups and DDR
  pinMode(DIGITAL_PIN, OUTPUT);
}


As-is it doesn't work with the attiny13 @9.6MHz.  It looks like the timing will need to be adjusted.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 14, 2014, 10:12 am
Thanks Hiduino, I shall bear that in mind when I get my t13's in the post !!
Perhaps a few "nop\n\t" should be added in strategic lines of the assembly, if you know how Ws work then it might be straight forward :)

Cheers SmeezeKitty, I dont think the 50us is the issue, I am trying to create a pulse-width data stream for the ws2812 which needs to be near 800khz, I dont think my code is near that, but the ws device has allowances and works on an t85, but as Hiduino says the timing needs adjustment for the t13, I cant imagine is very far out

:)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 14, 2014, 11:16 am
Okay, I used one of the original bitbang_whitish sketches from the Instructables.  Which is timed for a 16MHz clock.  I feed an external 16MHz clock to the tiny13A.   I had to remove the malloc routine because that was eating too much flash.  I also modified it to animate the pixel thru the rainbow colors.  It currently compiles to around 980 bytes, just barely fitting.

Edit: Using IDE 1.5.7 has better optimizations.  So I was able to get 8 pixels going thru the rainbow colors.  There are probably other code optimizations that can be done, but this was just a quick throw together to test the concept.

Note: I had to update to smeezekitty's latest core13_19 for this to work.  It was doing nothing on core13_18.

Code: [Select]

/*---------------------------------------------------------------------
 Acrobotic - 01/10/2013
 Author: x1sc0
 Platforms: Arduino Uno R3
 File: bitbang_whitish.ino

 Description:
 This code sample accompanies the "How To Control 'Smart' RGB LEDs:
 WS2811, WS2812, and WS2812B (Bitbanging Tutorial)" Instructable
 (http://www.instructables.com/id/Bitbanging-step-by-step-Arduino-control-of-WS2811-/)

 The code illustrates how to continuously set one WS2811 (driver)/
 WS2812/WS2812B RGB LEDs to a full intensity whitish.  The color and
 number of WS281X ICs can be easily modified to explore the full range of
 these wonderful family of LEDs.

 The communication is done by bitbanging a self-clocked 800KHz, NZR signal.
 The implementation was done using assembly so that the timing of the signal
 was extremely accurate.

 Usage:
 Connect power (5V), ground (GND), and the Arduino Uno pin defined
 by DIGITAL_PIN to the WS281X ports VCC, GND, and DIN ports, respectively.

 Upload the program to an Arduino Uno, and the Green LED of the first
 WS281X will light up to full brightness.

 ------------------------------------------------------------------------
 For a full-blown Arduino library, check out:
 https://github.com/acrobotic/Ai_Library_WS281X/
 ------------------------------------------------------------------------
 Please consider buying products from Acrobotic to help fund future
 Open-Source projects like this! We'll always put our best effort in every
 project, and release all our design files and code for you to use.
 http://acrobotic.com/
 ------------------------------------------------------------------------

 License:
 Beerware License; if you find the code useful, and we happen to cross
 paths, you're encouraged to buy us a beer. The code is distributed hoping
 that you in fact find it useful, but  without warranty of any kind.
------------------------------------------------------------------------*/

#define NUM_RGB       (8)         // Number of WS281X we have connected
#define NUM_BYTES     (NUM_RGB*3) // Number of LEDs (3 per each WS281X)
#define DIGITAL_PIN   (2)         // Digital port number
#define PORT          (PORTB)     // Digital pin's port
#define PORT_PIN      (PORTB2)    // Digital pin's bit position

#define NUM_BITS      (8)         // Constant value: bits per byte
#define WAIT 10

//uint8_t* rgb_arr = NULL;
uint8_t rgb_arr[NUM_BYTES];
uint32_t t_f;
uint8_t brightness = 40;

void setup()
{
 pinMode(DIGITAL_PIN, OUTPUT);

/*
if ((rgb_arr = (uint8_t *)malloc(NUM_BYTES)))
 {
   memset(rgb_arr, 0, NUM_BYTES);
 }
*/
 render();
}

void loop()
{
 for (int j = 0; j < 256*5; j++) {
   for (int i = 0; i < NUM_RGB; i++)
     setColorRGB(i, Wheel(( (i*256/NUM_RGB) +j) & 255) );   // R, G, B
   render();
   delay(WAIT);
 }
}

void setColorRGB(uint16_t idx, uint32_t c) // uint8_t r, uint8_t g, uint8_t b)
{
 if (idx < NUM_RGB)
 {
   uint8_t
     r = (uint8_t)(c >> 16),
     g = (uint8_t)(c >>  8),
     b = (uint8_t)c;
   if(brightness) { // See notes in setBrightness()
     r = (r * brightness) >> 8;
     g = (g * brightness) >> 8;
     b = (b * brightness) >> 8;
   }
   uint8_t *p = &rgb_arr[idx * 3];
   *p++ = g;
   *p++ = r;
   *p = b;
 }
}

// Convert separate R,G,B into packed 32-bit RGB color.
// Packed format is always RGB, regardless of LED strand color order.
uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
 return ((uint32_t)r << 16) | ((uint32_t)g <<  8) | b;
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
 if(WheelPos < 85) {
  return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
 } else if(WheelPos < 170) {
  WheelPos -= 85;
  return Color(255 - WheelPos * 3, 0, WheelPos * 3);
 } else {
  WheelPos -= 170;
  return Color(0, WheelPos * 3, 255 - WheelPos * 3);
 }
}

void render(void)
{
 if (!rgb_arr) return;

 while ((micros() - t_f) < 50L); // wait for 50us (data latch)

 cli(); // Disable interrupts so that timing is as precise as possible
 volatile uint8_t
 *p    = rgb_arr,   // Copy the start address of our data array
  val  = *p++,      // Get the current byte value & point to next byte
  high = PORT |  _BV(PORT_PIN), // Bitmask for sending HIGH to pin
  low  = PORT & ~_BV(PORT_PIN), // Bitmask for sending LOW to pin
  tmp  = low,       // Swap variable to adjust duty cycle
  nbits = NUM_BITS; // Bit counter for inner loop
 volatile uint16_t
 nbytes = NUM_BYTES; // Byte counter for outer loop
 asm volatile(
   // The volatile attribute is used to tell the compiler not to optimize
   // this section.  We want every instruction to be left as is.
   //
   // Generating an 800KHz signal (1.25us period) implies that we have
   // exactly 20 instructions clocked at 16MHz (0.0625us duration) to
   // generate either a 1 or a 0---we need to do it within a single
   // period.
   //
   // By choosing 1 clock cycle as our time unit we can keep track of
   // the signal's phase (T) after each instruction is executed.
   //
   // To generate a value of 1, we need to hold the signal HIGH (maximum)
   // for 0.8us, and then LOW (minimum) for 0.45us.  Since our timing has a
   // resolution of 0.0625us we can only approximate these values. Luckily,
   // the WS281X chips were designed to accept a +/- 300ns variance in the
   // duration of the signal.  Thus, if we hold the signal HIGH for 13
   // cycles (0.8125us), and LOW for 7 cycles (0.4375us), then the variance
   // is well within the tolerated range.
   //
   // To generate a value of 0, we need to hold the signal HIGH (maximum)
   // for 0.4us, and then LOW (minimum) for 0.85us.  Thus, holding the
   // signal HIGH for 6 cycles (0.375us), and LOW for 14 cycles (0.875us)
   // will maintain the variance within the tolerated range.
   //
   // For a full description of each assembly instruction consult the AVR
   // manual here: http://www.atmel.com/images/doc0856.pdf
   // Instruction        CLK     Description                 Phase
   "nextbit:\n\t"         // -    label                       (T =  0)
   "sbi  %0, %1\n\t"     // 2    signal HIGH                 (T =  2)
   "sbrc %4, 7\n\t"      // 1-2  if MSB set                  (T =  ?)
   "mov  %6, %3\n\t"    // 0-1   tmp'll set signal high     (T =  4)
   "dec  %5\n\t"         // 1    decrease bitcount           (T =  5)
   "nop\n\t"             // 1    nop (idle 1 clock cycle)    (T =  6)
   "st   %a2, %6\n\t"    // 2    set PORT to tmp             (T =  8)
   "mov  %6, %7\n\t"     // 1    reset tmp to low (default)  (T =  9)
   "breq nextbyte\n\t"   // 1-2  if bitcount ==0 -> nextbyte (T =  ?)
   "rol  %4\n\t"         // 1    shift MSB leftwards         (T = 11)
   "rjmp .+0\n\t"        // 2    nop nop                     (T = 13)
   "cbi   %0, %1\n\t"    // 2    signal LOW                  (T = 15)
   "rjmp .+0\n\t"        // 2    nop nop                     (T = 17)
   "nop\n\t"             // 1    nop                         (T = 18)
   "rjmp nextbit\n\t"    // 2    bitcount !=0 -> nextbit     (T = 20)
   "nextbyte:\n\t"        // -    label                       -
   "ldi  %5, 8\n\t"      // 1    reset bitcount              (T = 11)
   "ld   %4, %a8+\n\t"   // 2    val = *p++                  (T = 13)
   "cbi   %0, %1\n\t"    // 2    signal LOW                  (T = 15)
   "rjmp .+0\n\t"        // 2    nop nop                     (T = 17)
   "nop\n\t"             // 1    nop                         (T = 18)
   "dec %9\n\t"          // 1    decrease bytecount          (T = 19)
   "brne nextbit\n\t"    // 2    if bytecount !=0 -> nextbit (T = 20)
   ::
   // Input operands         Operand Id (w/ constraint)
   "I" (_SFR_IO_ADDR(PORT)), // %0
   "I" (PORT_PIN),           // %1
   "e" (&PORT),              // %a2
   "r" (high),               // %3
   "r" (val),                // %4
   "r" (nbits),              // %5
   "r" (tmp),                // %6
   "r" (low),                // %7
   "e" (p),                  // %a8
   "w" (nbytes)              // %9
 );
 sei();                          // Enable interrupts
 t_f = micros();                 // t_f will be used to measure the 50us
 // latching period in the next call of the
 // function.
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 14, 2014, 01:33 pm
Ok I see sir, I might give your code a go when my chips arrive too..

I am really up against flash limits with my code as I ALSO have a 250kbps (n,8,2) data receiver in there as well as 2 button up/down control and EEPROM read/write... all in less than 1k of code !!

so far need to save 90 bytes for it to fit on the t13
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 17, 2014, 08:17 pm
Hi, I got my t13's !! :)

HELP, I have a problem... I cant write the bootloader to 9.6mhz, I get the following error...

Code: [Select]
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x3f
avrdude: verification error; content mismatch


I am sure I have all my boards.txt entry correct

Code: [Select]
attiny13.name=Attiny 13A 9.6mhz
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x7A
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000L
attiny13.build.core=core13
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 17, 2014, 08:27 pm
Which programmer are you using?  Chances are the default clock on the tiny13 is too slow for your programmer.  Depending on which programmer you may be able to slow it down with avrdude options.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 17, 2014, 08:28 pm

Hi, I got my t13's !! :)

HELP, I have a problem... I cant write the bootloader to 9.6mhz, I get the following error...

Code: [Select]
avrdude: verification error, first mismatch at byte 0x0000
        0xff != 0x3f
avrdude: verification error; content mismatch


I am sure I have all my boards.txt entry correct

Code: [Select]
attiny13.name=Attiny 13A 9.6mhz
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.speed=19200
attiny13.bootloader.low_fuses=0x7A
attiny13.bootloader.high_fuses=0xFF
attiny13.bootloader.path=empty
attiny13.bootloader.file=empty
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.mcu=attiny13
attiny13.build.f_cpu=9600000L
attiny13.build.core=core13


That is a chip programming error.

What kind of programmer? An Arduino?
If so, did you add a reset prevention capacitor? You need atleast about 0.5uF from reset to ground (others say you need more
but I have used 0.56u with no problem)

If you are using a dedicated chip programmer, what kind is it?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 17, 2014, 09:29 pm
Ok, I found my error, but not sure why this works....

Code: [Select]
attiny13.build.f_cpu=1200000L

thats all I changed and it works... although, the timings are well out of the window

I am measuring micros() and the results are 10x what they should be (eg 1040 to measure 104us)

I can live with that for now, as soon as I sussed these two problems, everything started to work

I love my T13's, although they are way short on ram after the compiler gets hold of things, not sure where 20 bytes are going, any clues ?? lol

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 17, 2014, 09:54 pm

Ok, I found my error, but not sure why this works....

Code: [Select]
attiny13.build.f_cpu=1200000L

thats all I changed and it works... although, the timings are well out of the window

I am measuring micros() and the results are 10x what they should be (eg 1040 to measure 104us)

I can live with that for now, as soon as I sussed these two problems, everything started to work

I love my T13's, although they are way short on ram after the compiler gets hold of things, not sure where 20 bytes are going, any clues ?? lol



You need to match the F_CPU and the fuses. Chances are changing F_CPU "fixed" it by coincidence only
since it shouldn't effect programming at all.

As far as RAM goes.. What is your code?
The core will naturally require some RAM and avr-libc might use some too.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 17, 2014, 10:09 pm
As far as matching F_CPU and fuses are concerned you are right, it was just lucky I guess, perhaps that is the reason why the micros() are x10 ?? - I am not sure what to do to get 9.6mhz with fuses and F_CPU

I dont think I could post my code, no one would understand it !! lol

I will do some more tests on the ram

Oh, and I found that PROGMEM  prog_uint8_t... and ... pgm_read_byte_near(... seem to crash the program, that was my main way of saving ram, but ended up losing 8 bytes after I took the lines out :(

Thanks for all your help so far sir !! :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 17, 2014, 11:02 pm
Change it back to 9600000. If you burned the fuses listed above you are already running at ~9.6MHz
but the core thinks it is is running at 1.2MHz

I don't know about PROGMEM. I think it works. not sure why it would crash (out of RAM?)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 18, 2014, 08:11 am
0x7A, 0xFF and 9600000 threw up that error I mentioned and i'm not sure how to get round it
To be honest with the settings I have (1200000) it seems that the micro is running alot faster than 9.6 but Im not sure what speed it is...

Perhaps Progmem requires some RAM overhead just to run, so there may not be any advantages on trying to save 8 bytes with it

I have found another way around the memory problem - smarter programming !!! :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 18, 2014, 10:04 am

Oh, and I found that PROGMEM  prog_uint8_t... and ... pgm_read_byte_near(... seem to crash the program, that was my main way of saving ram, but ended up losing 8 bytes after I took the lines out :(


You must be using IDE 1.5.7?  Or updated your AVRToolChain.  The newer avr-gcc changed two things.
1) You need to add the 'const' keyword to your PROGMEM variables.
2) They dropped support for the prog_ typedefines.

You can edit all your code to use the newer method.  Or you could add a compatibility work-around by defining this.
Code: [Select]

#define __PROG_TYPES_COMPAT__
#include <avr/pgmspace.h>

const prog_uint8_t CIEL8[] PROGMEM = {  
0, 1, 2, 3, 4, 5, 7, 9,
12, 15, 18, 22, 27, 32, 38, 44,
51, 58, 67, 76, 86, 96, 108, 120,
134, 148, 163, 180, 197, 216, 235, 255
};


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 18, 2014, 09:38 pm
The mind boggles at how F_CPU could affect uploading at all.
Quote

To be honest with the settings I have (1200000) it seems that the micro is running alot faster than 9.6 but Im not sure what speed it is...

Its possible that it is running a little faster (10-15%) due to clock tolerances

Not likely to be "alot" faster.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 19, 2014, 08:33 am
Thanks for that Hiduino, decided not to use progmem for the time being and have a work around for now

Smeeze, well I guess it is a noticable difference from the t85 I 'upgraded' from !! - if you know of any exact settings I should use for 9.6 jiggawatts then please share, for now I have this tiny micro searching for a 88us sync pulse in a 250kbps continuous data stream - I am synching beautifully and grabbing the data with ease on the t13 @ 9.6mhz

What seemed like an impossible task a few weeks back is now a success !! thanks for your help
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 19, 2014, 06:14 pm
I am trying to suss out a bug I have with t13.. I am using EEPROM.h and im just wondering if when I upload the program it wipes the eeprom, how can I stop this with t13 ? (I think I had a similar problem with t85 before but got over that after someone on here helped) - Thanks in advance
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 19, 2014, 07:48 pm

I am trying to suss out a bug I have with t13.. I am using EEPROM.h and im just wondering if when I upload the program it wipes the eeprom, how can I stop this with t13 ? (I think I had a similar problem with t85 before but got over that after someone on here helped) - Thanks in advance

Not a bug. Its because the Arduino IDE is passing the erase chip option to avrdude.

The way around it (AFAIK) is to upload manually with avrdude which is a pain
-edit-
oops coding badly has a better option. I forgot about the fuse
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Coding Badly on Sep 19, 2014, 07:51 pm

Uh, actually, it is a fuse bit.  Ensure Preserve EEPROM memory through the Chip Erase cycle; [EESAVE=0] is "set".
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 19, 2014, 10:56 pm
Ah yes, thats it CodingBaldy, I had forgotten about that.. I shall check my fuse options - cheers
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 20, 2014, 09:43 am
I was using 0x7a for low fuse, but should be 0x3a to preserve my eeprom during pogramming

found this, VERY useful

http://www.elektronik-kompendium.de/public/arnerossius/programme/web/avrfuse/tn13fuse.html (http://www.elektronik-kompendium.de/public/arnerossius/programme/web/avrfuse/tn13fuse.html)

Cheers :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 20, 2014, 10:14 am
That's an interesting view of the fuse settings.  I like to use this fuse site, http://eleccelerator.com/fusecalc/fusecalc.php?chip=attiny13a (http://eleccelerator.com/fusecalc/fusecalc.php?chip=attiny13a).  It supports most of the Atmel AVR mcu.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Sep 21, 2014, 02:13 pm
I just committed to a PCB design for the ATTiny13, really pleased with my code and the minimal design in SMD

Big thanks to all who have helped me here :)

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Sep 22, 2014, 10:07 am
Hello!
Any one succeeded in getting this core to work on arduino 1.5.7 ?? i have been trying but no luck for me so far.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 22, 2014, 12:36 pm
Yes, I've been using the core13 with IDE 1.5.x for a while now.  The main thing is to have a proper boards.txt and platform.txt files. Also you need to have the proper directory path structure.  For IDE 1.5.x the boards.txt file structure has some slight changes.

For IDE 1.0.6:
/sketches/hardware/tiny13/boards.txt
/sketches/hardware/tiny13/core/core13/

For IDE 1.5.7:
/sketches/hardware/tiny13/avr/boards.txt
/sketches/hardware/tiny13/avr/platform.txt
/sketches/hardware/tiny13/avr/core/core13/

I have combined both in the attached file.  It includes the core13_19 files.  I have included various CPU clock options for the tiny13.  Just keep in mind when you go below 1 MHz clock rates you need to make sure your ISP programmer supports a slow clock option.  Otherwise you may not be able to program it unless you have a different ISP programmer option.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Sep 22, 2014, 05:49 pm
Thanks a lot it works like a dream,
i saw in your boards file that you are not using reset as IO, a tip try ScratchMonkey hsvp programmer it works really well for attiny13 too. cheapest way to get a hsvp programmer i have seen so far.

http://microtherion.github.io/ScratchMonkey/GettingStarted.html

Thanks again for the Help
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Sep 26, 2014, 06:36 pm
Hi all, I've been doing some work on that recurring delay/timing issue many have been experiencing. (Including myself!)

Long story short - I've written a new delay function that seems to be very close to spot on. I think it'll need a bit of explaining, but the base code is below. In a nutshell, millisecond delays are fine, but microsecond delays may need increasing by 20% depending on your clock speed.

There are two new functions, "delay_us" and "delay_ms", and both take an unsigned integer for the time period. You can put the functions in your sketch file, or add them to "wiring.c" in the core13 directory.

A few issues to consider:
1. "ms_delay" just reuses "us_delay", but note that the "ms_loops" variable can be 1200 rather than 1000. This is due to the ATTiny internal base frequency being at 1.2/4.8/9.6MHz. It's only 1000 if using 2/4/8/16MHz. This is done automatically for millisecond delays, so nothing to worry about.

However, such an adjustment is NOT done inside "us_delay". It would require a *1.2 multiplier, and maths functions eat up memory. As a result, if you're running at 1.2/4.8/9.6MHz then the value passed to "us_delay" MUST be increased by 20% to get the correct delay period. So if you want a 50us delay, you actually need to call "us_delay(60);" (This is a minor annoyance, but I'm working on it...)

2. The F_CPU parameters in "boards.txt" need to be the actual CPU frequency. The stock file has both 4.8MHz and 9.6MHz set to 1200000L, and this won't work. They need to be changed to 4800000L and 9600000L for these functions to work correctly. (Changing them may mess up the existing delay functions if you use those as well - but I haven't yet checked.)

3. There are some slight overheads which make the delays very slightly longer than expected. This is just a few microseconds, so isn't a problem for long delays, but it starts creeping in below 100us. (Actually called as "120us" - see point 1.)

4. The maximum delay in microseconds is 16383, the minimum is 4. Due to point 1, in practice this translates as 13650us if you're running at the awkward 1.2/4.8/9.6 clock speeds.


I've done a reasonable amount of testing with some ATTiny13As at 1.2MHz and 9.6MHz, and also with a standard Arduino (ATMega328) at 16MHz. At the higher clock speeds the timing is pretty accurate, but not quite so good at 1.2MHz. I think this is due to the overheads being longer in real-time at the slower clock speed.

I'll try and fix the annoying +20% issue when I get some free time, I suspect it may require changing the number of clock cycles used by the loop.

Comments and feedback appreciated. Someone may also wish to check the code as it's my first attempt at assembly!

________________

Code: [Select]
void delay_us(uint16_t us_delay) // Works OK between 10us and 16382us. NOTE: Send x1.2 for ATTiny @ 1.2/4.8/9.6MHz
{
  us_delay = us_delay >> 2;
  uint8_t us_low = us_delay & 255;
  uint8_t us_high = us_delay >> 8;

  uint8_t us_loops;  // define the number of outer loops based on CPU speed (defined in boards.txt)

  #if (F_CPU == 16000000L)
    us_loops=16;
  #elif (F_CPU == 8000000L || F_CPU == 9600000L)
    us_loops=8;
  #elif (F_CPU == 4000000L || F_CPU == 4800000L)
    us_loops=4;
  #elif (F_CPU == 2000000L)
    us_loops=2;
  #elif (F_CPU == 1000000L || F_CPU == 1200000L)
    us_loops=1;
  #else
  #error This CPU frequency is not defined   
  #endif

   
  // loop is (4) + (4x us) + (4x us_loops) clock cycles in total - this is where the overheads occur
  // each clock cycle is 62.5ns @ 16MHz
  // each clock cycle is 833.3ns @ 1.2MHz
  asm volatile(
   "CLI\n" // turn off interrupts : 1 clock
   "MOV r28,%0\n" // Store low byte into register Y : 1 clock
   "MOV r29,%1\n" // Store high byte into register Y : 1 clock
   "MOV r30,%2\n" // Set number of loops into register Z : 1 clock
 
     // note branch labels MUST be numerical (ie. local) with BRNE 1b (ie. backwards)
     "1:\n" // = 4 clock cycles for each outer loop
     "MOV r26,r28\n" // Copy low byte into register X : 1 clock
     "MOV r27,r29\n" // Copy high byte into register X : 1 clock
   
       "2:\n" // = 4 clock cycles for each inner loop
       "SBIW r26,1\n" // subtract one from word : 2 clocks
       "BRNE 2b\n" // Branch back unless zero flag was set : 1 clock to test or 2 clocks when branching
       "NOP\n" // add an extra cycle if not branching
     
     "SUBI r30,1\n" // subtract one from loop counter : 1 clocks
     "BRNE 1b\n" // Branch back unless zero flag was set : 1 clock to test or 2 clocks when branching

   "SEI\n" // turn on interrupts :  1 clock (adds extra clock cycle when not branching)
   :: "r" (us_low), "r" (us_high), "r" (us_loops) // tidy up registers
);
}


void delay_ms(uint16_t ms_delay) // reuse delay_us routine
{
  uint16_t ms_loops=1000;  // define number for us cycles
  #if (F_CPU == 1200000L || F_CPU == 4800000L || F_CPU == 9600000L)
    ms_loops=1200;  // Need to compensate for 1.2/4.8/9.6MHz
  #endif

  for (int ms_loop=0; ms_loop < ms_delay; ms_loop++) {
    delay_us(ms_loops);
  }
}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 26, 2014, 09:26 pm



A few issues to consider:
1. "ms_delay" just reuses "us_delay", but note that the "ms_loops" variable can be 1200 rather than 1000. This is due to the ATTiny internal base frequency being at 1.2/4.8/9.6MHz. It's only 1000 if using 2/4/8/16MHz. This is done automatically for millisecond delays, so nothing to worry about.

I will try it out when I get a chance. But I am very concerned with flash usage.
Quote


However, such an adjustment is NOT done inside "us_delay". It would require a *1.2 multiplier, and maths functions eat up memory. As a result, if you're running at 1.2/4.8/9.6MHz then the value passed to "us_delay" MUST be increased by 20% to get the correct delay period. So if you want a 50us delay, you actually need to call "us_delay(60);" (This is a minor annoyance, but I'm working on it...)

To avoid floating point math, you might be able to do something like this:
Code: [Select]

B = A + (A / 5);

or faster but less accurate (using 25% scaling)
Code: [Select]

B = A + (A >> 2);

Those wouldn't have the (flash) overhead of *1.2 but still might still be slow.
Quote

2. The F_CPU parameters in "boards.txt" need to be the actual CPU frequency. The stock file has both 4.8MHz and 9.6MHz set to 1200000L, and this won't work. They need to be changed to 4800000L and 9600000L for these functions to work correctly. (Changing them may mess up the existing delay functions if you use those as well - but I haven't yet checked.)

The boards.txt that are set up like that are wrong plain and simple. They keep kicking around for some reason.
F_CPU should always be set to the actual core speed. This includes accounting for whether /8 fuse is set or not.
Quote

3. There are some slight overheads which make the delays very slightly longer than expected. This is just a few microseconds, so isn't a problem for long delays, but it starts creeping in below 100us. (Actually called as "120us" - see point 1.)

This is always the case especially at low clock speeds. Not much can be done.


Quote

Comments and feedback appreciated. Someone may also wish to check the code as it's my first attempt at assembly!

It looks fairly okay. It does have more overhead though.
I will see if it is worth integrating later.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Sep 27, 2014, 05:22 pm
Hi smeezekitty, thanks for the quick feedback!

I've done a bit of tweaking and oscilloscope testing - here's the results:

// Original routines
delayMicroseconds(1000) : +34 bytes, actual delay 1140us (+14%)
delay(1000) : +26 bytes, actual delay 1380ms (+38%)

// New routines
delayMicroseconds(1000) : +58 bytes, actual delay 1060us (+6%)
delay(1000) : +44 bytes, actual delay 1040ms (+4%)


With a bit of pruning I might be able to reduce the size a little, but for an extra 20 bytes or so the accuracy is much improved, especially with longer delays. (My current project can live with that.)

Turns out the new routines have to replace the old ones in wiring.c. If they're left as separate functions they seem to get embedded every time they're called. Replacing the originals in wiring.c then results in the usual overhead of just 6 bytes for every additional use.

I also fixed the annoying *1.2 issue by using 9/8 instead, which is easy to bitshift. (Thanks for the suggestion!) That also helps compensate for the clock cycle overheads in the loop. As a result, the maximum delayMicrosecond() is reduced to 58250, but you can now just pass the raw us value as normal.


Code: [Select]

void delay(unsigned ms)
{
  while(ms--){
    delayMicroseconds(1000);
  }
}



void delayMicroseconds(unsigned us)
{
  uint8_t us_loops;  // define the number of outer loops based on CPU speed (defined in boards.txt)
  #if (F_CPU == 16000000L)
    us_loops=16;
  #elif (F_CPU == 9600000L)
    us=us + (us >> 3); // this should be *1.2 but *1.125 adjusts for overheads
    us_loops=8;
  #elif (F_CPU == 8000000L)
    us_loops=8;
  #elif (F_CPU == 4800000L)
    us = us + (us >> 3);
    us_loops=4;
  #elif (F_CPU == 4000000L)
     us_loops=4;
  #elif (F_CPU == 2000000L)
    us_loops=2;
  #elif (F_CPU == 1200000L)
    us = us + (us >> 3);
    us_loops=1;
  #elif (F_CPU == 1000000L)
    us_loops=1;
  #else
  #error This CPU frequency is not defined   
  #endif

  us = us >> 2;
  uint8_t us_low = us & 255;
  uint8_t us_high = us >> 8;
   
  // loop is (4 clock cycles) + (4x us) + (4x us_loops)
  // each clock cycle is 62.5ns @ 16MHz
  // each clock cycle is 833.3ns @ 1.2MHz
  asm volatile(
   "CLI\n" // turn off interrupts : 1 clock
   "MOV r28,%0\n" // Store low byte into register Y : 1 clock
   "MOV r29,%1\n" // Store high byte into register Y : 1 clock
   "MOV r30,%2\n" // Set number of loops into register Z : 1 clock
 
     // note branch labels MUST be numerical (ie. local) with BRNE 1b (ie. backwards)
     "1:\n" // : 4 clock cycles for each outer loop
     "MOV r26,r28\n" // Copy low byte into register X : 1 clock
     "MOV r27,r29\n" // Copy high byte into register X : 1 clock
   
       "2:\n" // : 4 clock cycles for each inner loop
       "SBIW r26,1\n" // subtract one from word : 2 clocks
       "BRNE 2b\n" // Branch back unless zero flag was set : 1 clock to test or 2 clocks when branching
       "NOP\n" // add an extra clock cycle if not branching
     
     "SUBI r30,1\n" // subtract one from loop counter : 1 clocks
     "BRNE 1b\n" // Branch back unless zero flag was set : 1 clock to test or 2 clocks when branching

   "SEI\n" // turn on interrupts : 1 clock (adds extra clock cycle when not branching)
   :: "r" (us_low), "r" (us_high), "r" (us_loops) // tidy up registers
);
}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 27, 2014, 07:09 pm
Ok so for comparison do you think you can test a millis() loop for size and accuracy
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Sep 27, 2014, 10:00 pm
This topic has been hashed many times for optimized math division.  Check these out.

http://forum.arduino.cc/index.php?topic=185662.0 (http://forum.arduino.cc/index.php?topic=185662.0)

http://forum.arduino.cc/index.php?topic=164644.0 (http://forum.arduino.cc/index.php?topic=164644.0)

http://forum.arduino.cc/index.php?topic=167414.0 (http://forum.arduino.cc/index.php?topic=167414.0)

http://forum.arduino.cc/index.php?topic=172635.0 (http://forum.arduino.cc/index.php?topic=172635.0)

http://forum.arduino.cc/index.php?topic=165860.0 (http://forum.arduino.cc/index.php?topic=165860.0)

http://forum.arduino.cc//index.php?topic=192209.msg1448435#msg1448435 (http://forum.arduino.cc//index.php?topic=192209.msg1448435#msg1448435)

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Sep 28, 2014, 02:51 pm
A quick comparison using millis() and micros() shows them to be pretty bad when using a simple while loop:

Code: [Select]

void loop() {
PORTB=1;
period=micros()+1000;
while(micros()<period){
}
PORTB=0;
period=micros()+1000;
while(micros()<period){
}
}


Using micros() the sketch compiles to 398 bytes and times at 1400-1800us (with very inconsistent timing)
Using millis() the sketch compiles to 414 bytes, and times at 1120ms consistently.


In constrast, the new delay() and delayMicroseconds routines give:

delayMicroseconds(1000) compiles to 266 bytes, times at 1064us
delay(1000) compiles to 252 bytes, times at 1070ms


An obvious problem with using millis() or micros() is that the timer overflow counter is only incremented every 256 clock cycles, ie. every 213us at 1.2MHz. With millis() this is then scaled by 5/19/37 for 1.2/4.8/9.6MHz. These don't quite give exact ms values. At 1.2MHz for example,  256*5=1280 clock cycles and 1280*0.833=1066us.

micros() fares even worse, since the time has increased by 213us for each ovrf++ (at 1.2MHz). And because there's no way of controlling exactly when these functions are executed, ovrf may have increased beyond the required timing value, being some multiple of 213us larger than desired. (Unless 213 happens to be an aliquot part of your required duration.) This also means that micros() can't deal with periods less than 213us.

I think that with higher clock speeds and with longer delays millis() and micros() are probably adequate. But micros() is not too good for actually counting microseconds.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Sep 28, 2014, 06:05 pm

A quick comparison using millis() and micros() shows them to be pretty bad when using a simple while loop:

Code: [Select]

void loop() {
PORTB=1;
period=micros()+1000;
while(micros()<period){
}
PORTB=0;
period=micros()+1000;
while(micros()<period){
}
}


Using micros() the sketch compiles to 398 bytes and times at 1400-1800us (with very inconsistent timing)
Using millis() the sketch compiles to 414 bytes, and times at 1120ms consistently.

This is quite expected from the current micros() routine at clock clock rates
I am very surprised they are so large though

In constrast, the new delay() and delayMicroseconds routines give:

delayMicroseconds(1000) compiles to 266 bytes, times at 1064us
delay(1000) compiles to 252 bytes, times at 1070ms

Quote

An obvious problem with using millis() or micros() is that the timer overflow counter is only incremented every 256 clock cycles, ie. every 213us at 1.2MHz. With millis() this is then scaled by 5/19/37 for 1.2/4.8/9.6MHz. These don't quite give exact ms values. At 1.2MHz for example,  256*5=1280 clock cycles and 1280*0.833=1066us.

Well I am seriously thinking that I am going to increase the timer interrupt rate in a future version
Quote

I think that with higher clock speeds and with longer delays millis() and micros() are probably adequate. But micros() is not too good for actually counting microseconds.

I am fully aware of the limitations on the uS routines. However I will work on improvements.

The problem with your routines is they fail completely on clock speeds below 1 MHz. Not a huge deal with uS since "microsecond"
timing and overhead would be pretty awful at 128 or 600 khz. BUT working millisecond timing is important.

I may set it up so it switches routines based on clock speed
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Sep 29, 2014, 05:08 pm
Yeah, I need to have a look at the slower clock speeds. 600kHz might not be too terrible, but I can see 128kHz being awkward. I'll give it some thought. (Perhaps 1MHz << 8 is close enough?)

A reasonable millis() can be done, but a robust micros() eludes me at present. With some modified functions I can get these results:

@ 9.6MHz (chip 1):
micros()+100   : 124 to 154us
micros()+500   : 520us

millis()+5        : 4.1 to 4.7ms
millis()+50   : 49.6ms
millis()+500   : 492ms
millis()+5000   : 4920ms


@ 1.2MHz (chip 2):
micros()+100   : 400 to 600us
micros()+500   : 640 to 860us

millis()+5     : 4.84 to 5.20ms
millis()+50   : 50.8ms
millis()+500   : 508ms
millis()+5000   : 5040ms

The figures are slightly different between chips, so this is probably as good as I can get.

Code: [Select]

unsigned long micros(){
// asm("CLI\n");
unsigned long us_actual = ovrf << 9; // Put number of overflows into higher bits (equivalent to total clocks*2)
us_actual = us_actual + TCNT0; // Put current timer-counter into lower 8 bits


#if F_CPU == 1000000 // 1.0us per clock = 1 clock per us
us_actual = us_actual >> 1; // Equivalent to clocks

#elif F_CPU == 2000000 // 0.5us per clock = 2 clocks per us
us_actual = us_actual >> 2; // Equivalent to clocks/2

#elif F_CPU == 4000000 // 0.25us per clock = 4 clocks per us
us_actual = us_actual >> 3; // Equivalent to clocks/4

#elif F_CPU == 8000000 // 0.125us per clock = 8 clocks per us
us_actual = us_actual >> 4; // Equivalent to clocks/8

#elif F_CPU == 16000000 // 0.0625us per clock = 16 clocks per us
us_actual = us_actual >> 5; // Equivalent to clocks/16


#elif F_CPU == 600000 // 1.66us per clock = 0.833 clock per us
us_actual = (us_actual >> 1) + (us_actual >> 2) + (us_actual >> 3) + (us_actual >> 6); // Equivalent to clocks*0.8906

#elif F_CPU == 1200000 // 0.83333us per clock = 1.2 clocks per us
us_actual = (us_actual >> 2) + (us_actual >> 3) + (us_actual >> 4) + (us_actual >> 7); // Equivalent to clocks*0.4453

#elif F_CPU == 4800000 // 0.20833us per clock = 4.8 clocks per us
us_actual = (us_actual >> 4) + (us_actual >> 5) + (us_actual >> 6) + (us_actual >> 9); // Equivalent to clocks*0.1113

#elif F_CPU == 9600000 // 0.10416us per clock = 9.6 clocks per us
us_actual = (us_actual >> 5) + (us_actual >> 6) + (us_actual >> 7) + (us_actual >> 10); // Equivalent to clocks*0.0557

#else
#error This CPU frequency is not defined
#endif
// asm("SEI\n");

return us_actual;
}


unsigned long millis(){
return (micros() >> 10); // This is 2.4% too low is but compensated for above at 0.6/1.2/4.8/9.6MHz
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Oct 23, 2014, 01:41 pm
Been a bit busy last few weeks, but tried a couple of alternative ways to improve the timing functions. None were much better sadly.

Did discover a couple of other things while playing about:

1. Removing the init() function from wiring.c and pasting the code into main() (main.cpp) seems to save 92 bytes if you don't need the timing functions. A "bare minimum" sketch normally compiles to about 194 bytes, but moving the init() code reduces it to 102 bytes. The overhead comes back if you call any timing function, but it doesn't if you're not using those.


2. The following code appears in analogWrite:
Code: [Select]

if(pin == 1){
TCCR0A |= (1 << COM0B1);
OCR0B = (val / 4) * 4;
}
if(pin == 0){
TCCR0A |= (1 << COM0A1);
OCR0A = val;
}


Is there a reason for "(val / 4) * 4"? Replacing it with "OCR0B = val" should work and avoids the overheads


On the subject of analogWrite, I needed full control over the PWM output so wrote this:

Code: [Select]

void configPWM(uint8_t pwmmode, uint16_t prescaler) // set PWM mode and prescaler frequency
{
if (pwmmode){
TCCR0A = _BV(WGM00);} // set to phase correct PWM mode.

if (!pwmmode){
TCCR0A = _BV(WGM00)|_BV(WGM01);} // set to fast PWM



if (prescaler == 8){
TCCR0B = _BV(CS01);} // clk/8 prescaler

else if (prescaler == 64){
TCCR0B = _BV(CS01) | _BV(CS00);} // clk/64 prescaler

else if (prescaler == 256){
TCCR0B = _BV(CS02);} // clk/256 prescaler

else if (prescaler == 1024){
TCCR0B = _BV(CS02) | _BV(CS00);} // clk/1024 prescaler

else{
TCCR0B = _BV(CS00);} // no prescaler (Default setting.)
}



I've tested it at 1.2MHz and the measured outputs are pretty close to the theoretical - slightly lower, but possibly just due to chip tolerances. The nominal FAST output (pwmmode=1) with prescaler=1 should be 4687Hz, I measure it at about 4460Hz. The nominal PHASE CORRECT output (pwmmode=0) with prescaler=1024 should be 2.3Hz, I measure it at about 2.1Hz.

The function compiles to 68 bytes, with an additional 8 bytes for every reuse.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Oct 29, 2014, 03:57 am
I just like this tiny13 MCU , even more than ATtiny85, some litle effort and you can do great things with little resource.
Many thanks to smeezekitty  - you did great job with this core.
I find some fine two channel volt meter here - http://razniepodelki.blogspot.com/2014/05/attiny13-74ch595-lcd-on-hd44780-2.html (http://razniepodelki.blogspot.com/2014/05/attiny13-74ch595-lcd-on-hd44780-2.html)

and with this small serial library - http://nerdralph.blogspot.dk/2014/01/avr-half-duplex-software-uart.html
( only 64 bytes more on flash work also great with ATtiny85) i manage to do some modifications and to create this small ATtiny13 two chanel Console terminal volt meter.
I use LP2950ACZ-5.0 (5V - 0.5%) LDO for power supply and for reference also ( 100mA max. current), 10KOhm input resistors , and result is pretty accurate ( 4.096 V , 0.728 V with my cheap volt meter ). And a little unnecessary graphics purely to try to see what can do with so little memory.

(http://i58.tinypic.com/f4ln6h.gif)

Quote
#include <BasicSerial.h> // Samo TX ( SALJE Serial)
//#include <BasicSerial3.h> // TX i RX( SALJE I PRIMA Serial)
#include <util/delay.h>

//////////////////////////////////////////////////////////////////////////////////////////////////////
// #define UART_Tx 3 - U BasicSerial.S tj. Po defaultu Pin 3 ( PB3 ) - 115.2kbps ako je 9.6 MHz-a
void serOut(const char* str){
  while (*str) TxByte (*str++);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////

#include <avr/pgmspace.h>
// Ispis na istoj poziciji u externoj konzoli - pre svake komande mora Escape - \033 ( Umesto \033 moze \x1B ):
// \033 - Escape
// [2J - Clear screen
// [H - Go to home position (0,0)
// [0;36m - color tirkiz
// [0;34m - plava , [1;34m - svetlo plava
// [?25l - hide_cursor
// [4m - underscore
// [0;m - Normal color za sve
// [0;5m"; - blink
// [1;5m"; - blink bold
// \033[m  - stop za blink
prog_char Message0[] PROGMEM  = {
  "\033[H\n\033[1;34m#\033[0;31m-------- \033[0;36mQ"};
prog_char Message1[] PROGMEM  = {
  "\033[H\n\n\033[1;34m#\033[0;31m-------- \033[0;32mQ"};
prog_char Message2[] PROGMEM  = {
  "\033[1;34m### \033[0;m\033[1;5mATTINY13 VOLT METER\033[m \033[1;34m###\033[?25lQ"};
prog_char Message3[] PROGMEM  = {
  " \033[0;31m--------\033[1;34m#Q"};
prog_char Message4[] PROGMEM  = {
  "\033[1;34m###########################Q"};

#define ADC_Pin_1 A1      // PB2
#define ADC_Pin_2 A2      // PB4

/////////////////////////////////////////////////////////////////////////////
int main() {
#if defined (__AVR_ATtiny13__)
  char buf[2];
  byte b = 0;
  while(1){
    buf[0] = pgm_read_byte_near(&(Message2));
    buf[1] = '\0';
    if(buf[0] == 'Q')break;
    serOut(buf);
    b++;
  }
  b = 0;
  serOut("\n\n\n");
  while(1){
    buf[0] = pgm_read_byte_near(&(Message4));
    buf[1] = '\0';
    if(buf[0] == 'Q')break;
    serOut(buf);
    b++;
  }
#elif defined(__AVR_ATtiny85__)
  serOut("\x1B[0;31mATtiny85\033[?25l");
#else
  serOut("");
#endif

  DDRB &= ~(1 << ADC_Pin_1); //  pinMode(ADC_Pin, INPUT);
  DDRB &= ~(1 << ADC_Pin_2); //  pinMode(ADC_Pin, INPUT);
#if defined (__AVR_ATtiny13__)
  turn_on_adc(); // Samo ako odaberemo drugu verziju
#endif

  while(1)  {
    unsigned int adc_read_1,adc_read_2;

#if defined (__AVR_ATtiny13__)  
    adc_read_1 = (/*analogRead*/readADC(ADC_Pin_1));
    adc_read_2 = (/*analogRead*/readADC(ADC_Pin_2));
#elif defined(__AVR_ATtiny85__)
    adc_read_1 = (((unsigned int)analogRead(ADC_Pin_1)*49/10));
    adc_read_2 = (((unsigned int)analogRead(ADC_Pin_2)*49/10));
#endif
    print_tree_UINT_dec( adc_read_1, 1 );
    print_tree_UINT_dec( adc_read_2, 2 );
    _delay_ms(500);
  }
  return 0;
}


/////////////////////////////////////////////////////////////////////////////////////////

void turn_on_adc(){ADCSRA |= (1 << ADEN) |(1 << ADPS2)|(1 << ADPS1);
  ACSR |= (1 << ACD);
  DIDR0 |= (1 << ADC3D)|(1 << ADC2D);
}

unsigned int readADC(unsigned char ch) {
  ADMUX = ch;
  ADCSRA |= (1 << ADSC);
  while((ADCSRA & (1 << ADSC)));
  //  return(ADC); // 0-1023
////// LP2950ACZ-5.0 ~~ 5V , 0.5% ///////////////
  return(ADC*49/10); // 1023 * 49 / 10 = (int)5012.4 = 5012( 49/10 kada je 5.0 V = Vcc = refV)
  // Posto koriscenje float prom. trosi mem. mora se koristiti racional aprox. kao ovde a za ref. voltazu birati Vcc sa sto tacnijom regulacijom.
}


////////////////////////////////////////////////////////////////////////////////////////////////
// unsigned int max do 65 536
void print_tree_UINT_dec( unsigned int aprox_a , int voltCh ){

  unsigned int decimals = 1000; // 3 decimale

  unsigned int b = aprox_a / decimals; // ceo broj 3
  unsigned int c = (aprox_a % decimals) / (decimals/10);  // 1. decimala - ostatak 1
  unsigned int d = (aprox_a % (decimals/10) ) / (decimals/100);  // 2. decimala - ostatak 4
  unsigned int e = aprox_a % (decimals/100);  // 3. decimala - ostatak 4

  char buf[2];
  byte bb = 0;
  if(voltCh == 1){
    while(1){
      buf[0] = pgm_read_byte_near(&(Message0[bb]));
      buf[1] = '\0';
      if(buf[0] == 'Q')break;
      serOut(buf);
      bb++;
    }
  }
  if(voltCh == 2){
    bb = 0;
    while(1){
      buf[0] = pgm_read_byte_near(&(Message1[bb]));
      buf[1] = '\0';
      if(buf[0] == 'Q')break;
      serOut(buf);
      bb++;
    }
  }

  char buffer [2];
  itoa (b,buffer,10);
  serOut( buffer );
  serOut( "." );
  itoa (c,buffer,10);
  serOut( buffer );
  itoa (d,buffer,10);
  serOut( buffer );
  itoa (e,buffer,10);
  serOut( buffer );
  serOut( " V" );

  // Crvene crtice desno  
  bb = 0;
  while(1){
    buf[0] = pgm_read_byte_near(&(Message3[bb]));
    buf[1] = '\0';
    if(buf[0] == 'Q')break;
    serOut(buf);
    bb++;
  }
}


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Oct 29, 2014, 05:14 am
Thanks for sharing. Although it begs the question on why you are overriding the ADC functions.

To kosine:
I have noticed your feedback but I haven't had time to implement anything.
That /4 line was for testing and somehow it slipped through. It will be fixed in the next release
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Oct 29, 2014, 10:52 am
Thanks for sharing. Although it begs the question on why you are overriding the ADC functions.
No reason at all, build in analogRead work fine in 0.19 core , i just trying something and forget to roll back before post.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Nov 11, 2014, 09:04 am
Hi there all,

Ive been out of the t13 for a few weeks now, but thought I would get round to publishing a working project on here

ATTiny13 - DMX512 to WS2812 RGB LED interface (http://forum.arduino.cc/index.php?topic=278252)

Thanks to all that have helped and contributed

Bob
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Nov 13, 2014, 03:31 am
Thanks for sharing.
I am long overdue for an update
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 10, 2015, 11:04 pm
Core13 0.20 released!

Features improved PWM output and rewritten delayMicroseconds() code
which should be more accurate at all clock speeds and delay length.

(first release of 2015!)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: evildave_666 on Jan 11, 2015, 12:48 pm
Core13 0.20 released!

Features improved PWM output and rewritten delayMicroseconds() code
which should be more accurate at all clock speeds and delay length.

(first release of 2015!)
Great, will give it a go to make sure my arduino-based 13a stuff still works. Any impact of these changes on generated code size?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 11, 2015, 08:57 pm
Great, will give it a go to make sure my arduino-based 13a stuff still works. Any impact of these changes on generated code size?

Certain functions may be a little larger. Sorry about that :(
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Jan 12, 2015, 09:55 pm
I have been playing with ATTINY13A again

This time I got to drive a projector in 8 colours DIRECTLY from the ATTINY13 !!

http://forum.arduino.cc/index.php?topic=288766.0 (http://forum.arduino.cc/index.php?topic=288766.0)

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: furri on Jan 14, 2015, 09:44 pm
hi all.

I just unzip core13_20.zip on ...\Arduino\hardware\tiny\cores\core13

Where is the attiny def for boards.txt?

Am i in the right way?

It works with Attiny13A?

thanks.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 15, 2015, 12:01 am
Where is the attiny def for boards.txt?

There is a lot of boards.txt that are kicking around.
Some are more correct than others. I hacked this together:
Code: [Select]

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

attiny13a.name=Attiny 13A standalone 128khz
attiny13a.upload.using=arduino:arduinoisp
attiny13a.upload.maximum_size=1024
attiny13a.upload.speed=19200
attiny13a.bootloader.low_fuses=0x7b
attiny13a.bootloader.high_fuses=0xFF
attiny13a.bootloader.path=empty
attiny13a.bootloader.file=empty
attiny13a.bootloader.unlock_bits=0xFF
attiny13a.bootloader.lock_bits=0xFF
attiny13a.build.mcu=attiny13
attiny13a.build.f_cpu=128000L
attiny13a.build.core=core13
#######################

attiny13f.name=Attiny 13A standalone 600khz
attiny13f.upload.using=arduino:arduinoisp
attiny13f.upload.maximum_size=1024
attiny13f.upload.speed=19200
attiny13f.bootloader.low_fuses=0x69
attiny13f.bootloader.high_fuses=0xFF
attiny13f.bootloader.path=empty
attiny13f.bootloader.file=empty
attiny13f.bootloader.unlock_bits=0xFF
attiny13f.bootloader.lock_bits=0xFF
attiny13f.build.mcu=attiny13
attiny13f.build.f_cpu=600000L
attiny13f.build.core=core13
#######################

attiny13c.name=Attiny 13A standalone 1.2mhz
attiny13c.upload.using=arduino:arduinoisp
attiny13c.upload.maximum_size=1024
attiny13c.upload.speed=19200
attiny13c.bootloader.low_fuses=0x6a
attiny13c.bootloader.high_fuses=0xFF
attiny13c.bootloader.path=empty
attiny13c.bootloader.file=empty
attiny13c.bootloader.unlock_bits=0xFF
attiny13c.bootloader.lock_bits=0xFF
attiny13c.build.mcu=attiny13
attiny13c.build.f_cpu=1200000L
attiny13c.build.core=core13

#######################
attiny13d.name=Attiny 13A standalone 4.8Mhz
attiny13d.upload.using=arduino:arduinoisp
attiny13d.upload.maximum_size=1024
attiny13d.upload.speed=19200
attiny13d.bootloader.low_fuses=0x79
attiny13d.bootloader.high_fuses=0xFF
attiny13d.bootloader.path=empty
attiny13d.bootloader.file=empty
attiny13d.bootloader.unlock_bits=0xFF
attiny13d.bootloader.lock_bits=0xFF
attiny13d.build.mcu=attiny13
attiny13d.build.f_cpu=4800000L
attiny13d.build.core=core13
#######################
attiny13e.name=Attiny 13A standalone 9.6Mhz
attiny13e.upload.using=arduino:arduinoisp
attiny13e.upload.maximum_size=1024
attiny13e.upload.speed=19200
attiny13e.bootloader.low_fuses=0x7A
attiny13e.bootloader.high_fuses=0xFF
attiny13e.bootloader.path=empty
attiny13e.bootloader.file=empty
attiny13e.bootloader.unlock_bits=0xFF
attiny13e.bootloader.lock_bits=0xFF
attiny13e.build.mcu=attiny13
attiny13e.build.f_cpu=9600000L
attiny13e.build.core=core13

Quote
It works with Attiny13A?


It works on all Attiny13 series
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: karlboll on Jan 17, 2015, 02:04 am
Yay! My AtTiny13A's just arrived. 10 days from Shenzhen to Scandinavia must be some kind of record :-)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on Jan 17, 2015, 07:27 pm
Just received two attiny13a PU.
Plan 1: use it to drive a 4-pin RGB led. User shud be able to control intensity of each color using a push-button.

Plan 2: use it to drive a single(may be multiple, but don't really need it now) WS2812 based neoPixcel. Here also user should be able to control the individual color using push buttons.

In both of above case, either 3 push switch can be used to change individual color intensity with a step value of say 32 or 64. OR 2 push switch can be used; one for select the color to change and other to change the color intensity by a step value.

Should I burn a bootloader to the tiny? Please suggest how can I keep the code below 1K.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Jan 17, 2015, 08:46 pm
Plan 2: use it to drive a single(may be multiple, but don't really need it now) WS2812 based neoPixcel. Here also user should be able to control the individual color using push buttons.
I did THIS (http://forum.arduino.cc/index.php?topic=278252.0) on attiny13a, most is not relevant here, but I wrote a fast ws2812 driving routine in assembler which works a treat !!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on Jan 18, 2015, 04:03 am
Thanks mcnobby. I hv gone through your post on dmx/attiny. I am planning to leverage from the same. This is the t13 i bought:http://m.ebay.com/itm/201190520005?nav=SEARCH
Could you please suggest me what should i put in boards.txt file.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: evildave_666 on Jan 18, 2015, 04:11 am
I've found this WorldSemi library useful: https://github.com/cpldcpu/light_ws2812

I've used it on attiny13 with the raw avr libraries.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Jan 18, 2015, 09:50 am
I use this boards.txt entry for 9.6mhz attiny13a

Code: [Select]
attiny13at9.name=ATtiny13 @ 9.6MHz (internal 9.6 MHz clock)
attiny13at9.bootloader.low_fuses=0x3a
attiny13at9.bootloader.high_fuses=0xff
attiny13at9.upload.maximum_size=1024
attiny13at9.build.mcu=attiny13
attiny13at9.build.f_cpu=1200000
attiny13at9.build.core=core13


and this entry for driving at 32mhz from an external clock

Code: [Select]

attiny13-32.name=ATtiny13A (32mhz MHz clock gen)
attiny13-32.bootloader.low_fuses=0x70
attiny13-32.bootloader.high_fuses=0xff
attiny13-32.upload.maximum_size=1024
attiny13-32.build.mcu=attiny13
attiny13-32.build.f_cpu=9600000L
attiny13-32.build.core=core13
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 18, 2015, 08:05 pm
Just received two attiny13a PU.
Plan 1: use it to drive a 4-pin RGB led. User shud be able to control intensity of each color using a push-button.

Plan 2: use it to drive a single(may be multiple, but don't really need it now) WS2812 based neoPixcel. Here also user should be able to control the individual color using push buttons.

In both of above case, either 3 push switch can be used to change individual color intensity with a step value of say 32 or 64. OR 2 push switch can be used; one for select the color to change and other to change the color intensity by a step value.

Should I burn a bootloader to the tiny? Please suggest how can I keep the code below 1K.
The Attiny13 has 5 usable I/O pins so it should be okay to drive a 4 pin RGB LED
and two push buttons. You may be able to use multiplexing to use less I/O pins.

Keeping the code under 1k ... well you should follow common sense to optimize code
and then just try it out and see where it lands.

No bootloader needed when programming with SPi

Quote
I use this boards.txt entry for 9.6mhz attiny13a
This is wrong.

Code: [Select]

attiny13at9.build.f_cpu=1200000


should be

Code: [Select]

attiny13at9.build.f_cpu=9600000
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Jan 19, 2015, 08:31 am
This is wrong.
Code: [Select]

attiny13at9.build.f_cpu=1200000

should be
Code: [Select]

attiny13at9.build.f_cpu=9600000

I think I went through this before trying to set frequency to 9.6mhz, bot sure why I ended up with the first entry but it seems to work fine.

As far as I know low fuse bits 0 & 1 also select internal oscillator and divider.

Is F_CPU only in there as a contant for the compiler ?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 20, 2015, 01:04 am
I think I went through this before trying to set frequency to 9.6mhz, bot sure why I ended up with the first entry but it seems to work fine.

As far as I know low fuse bits 0 & 1 also select internal oscillator and divider.

Is F_CPU only in there as a contant for the compiler ?
F_CPU is a constant used by avr-libc and any Arduino core.
If it is incorrect, all timing and delay functions will be wrong.
And the ADC may be set up incorrectly.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Jan 20, 2015, 08:42 pm
ah ok, so thats probably why I didnt notice any problem, if I wasnt using any timing related functions it wouldnt matter

Thanks for the heads up :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Winnie_The_Pooh on Jan 23, 2015, 09:18 pm
hi!

analogWrite makes 4 KHz output frequency.

Is it possible to make it approx 10 times smaller? e.g. 400-800 Hz

Thanks!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 23, 2015, 09:48 pm
hi!

analogWrite makes 4 KHz output frequency.

Is it possible to make it approx 10 times smaller? e.g. 400-800 Hz

Thanks!
I'm curious why? To be honest, I have never actually measured
the frequency.

You could lower the microcontroller clock which would no doubt
slow down the PWM rate
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Winnie_The_Pooh on Jan 23, 2015, 10:08 pm
I'm using PWM to dim LED driver. Manual says that pwm frequency should be lower than 1000 Hz.


Lowering the clock is a little bit brute :)


May be I can play with divider here:


void analogWrite(uint8_t pin, uint8_t val){


24
       if(pin == 0){
25
           TCCR0A |= (1 << COM0A1);
26
           OCR0A = (val / 16) * 16;


Changing COM0A1 to COM0A2 will encrease the divider to 8. I think so :)

Any side effects?


Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 24, 2015, 12:46 am
I'm using PWM to dim LED driver. Manual says that pwm frequency should be lower than 1000 Hz.


Lowering the clock is a little bit brute :)


May be I can play with divider here:


void analogWrite(uint8_t pin, uint8_t val){


24
       if(pin == 0){
25
           TCCR0A |= (1 << COM0A1);
26
           OCR0A = (val / 16) * 16;


Changing COM0A1 to COM0A2 will encrease the divider to 8. I think so :)

Any side effects?



It should be okay. Just toss this
Code: [Select]

(val / 16) * 16


and make it just "val"

That was part of testing code that has since been removed. Newer versions fixed it
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Winnie_The_Pooh on Jan 24, 2015, 04:13 pm
Hi!

Check the attiny13 manual and find out that PWM freq can be set by the last 3 bits of TCCR0B register.

Use that code in setup section:

Code: [Select]

/*
Setting Divisor Frequency PWM on 9.6, 4.8, 1.2 MHz CPU
  0x01 divisor is 1      37500, 18750, 4687 Hz
  0x02 divisor is 8      4687, 2344, 586 Hz
  0x03 divisor is 64     586, 293, 73 Hz
  0x04 divisor is 256    146, 73, 18 Hz
  0x05 divisor is 1024   36, 17, 5 Hz
  */

 TCCR0B = TCCR0B & 0b11111000 | 0x02; // 0x02 divisor is 8   586 Hz


Measured real frequency is 555 Hz.

The question is - does this influence delay() function? Will test this in a near future :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Jan 24, 2015, 05:43 pm
I believe the timer-counter is derived from the main CPU clock via the prescaler, so changing the timer-counter prescaler should not affect the main clock.

Since the delay functions are based on counting clock cycles, they should remain tied to F_CPU. (So long as F_CPU is defined correctly in your boards.txt file and you've burned the fuses accordingly.)

However, the millis and micros functions are based on counting timer-counter overflows, and this will be affected by changing the prescaler.

Also note that there are two PWM modes, fast and phase correct. The core files set fast mode by default. If you switch to phase-correct [TCCR0A = _BV(WGM00);] the frequency is halved. (Actually 256/510.)

Actual output frequencies will not be exactly as listed in the ATtiny13a manual. 10% slower is not uncommon. If you need an exact frequency output, you'll need an external clock.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 25, 2015, 01:48 am
However, the millis and micros functions are based on counting timer-counter overflows, and this will be affected by changing the prescaler.

Also note that there are two PWM modes, fast and phase correct. The core files set fast mode by default. If you switch to phase-correct [TCCR0A = _BV(WGM00);] the frequency is halved. (Actually 256/510.)

Actual output frequencies will not be exactly as listed in the ATtiny13a manual. 10% slower is not uncommon. If you need an exact frequency output, you'll need an external clock.
Check out what I did to improve delayMicroseconds()
It is a hybrid of your code and my original code (your code bombed at low clock speeds)

Its a little bigger but it is the most accurate I could make it over a wide range of clock speeds
and delay lengths.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: kosine on Jan 25, 2015, 03:36 pm
I noticed the update to wiring.c in your latest v20, but haven't had chance to play around with it yet. Will try and find some time soon.

I've also been meaning to have a look at using CLKPR as a runtime reference instead of F_CPU during compilation. Would be nice to switch speeds on-the-fly and still retain some timing functionality, at least in ms.

With a 256 prescaler (37.5kHz) each clock cycle is 26.66us, so an ASM loop using 38 clocks would return after 1013.33us, which is close enough given the chip tolerances. Repeating the loop 256/CLKPR times would give the same 1ms regardless of operating frequency. (9 to choose from and no fuses to worry about!)

Seems fairly simple if using the internal 9.6MHz oscillator, and not much more complex with an external clock. (Adjust for that with F_CPU at compile time.)

Downside is that it's not going to work with us delays, but millis() and micros() might be possible with some work. The upside is that it would offer a lot of different PWM frequencies (20 I think) from 37.5kHz right down to 0.07Hz.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 25, 2015, 10:16 pm
Quote
I've also been meaning to have a look at using CLKPR as a runtime reference instead of F_CPU during compilation. Would be nice to switch speeds on-the-fly and still retain some timing functionality, at least in ms.

With a 256 prescaler (37.5kHz) each clock cycle is 26.66us, so an ASM loop using 38 clocks would return after 1013.33us, which is close enough given the chip tolerances. Repeating the loop 256/CLKPR times would give the same 1ms regardless of operating frequency. (9 to choose from and no fuses to worry about!)

Seems fairly simple if using the internal 9.6MHz oscillator, and not much more complex with an external clock. (Adjust for that with F_CPU at compile time.)

Downside is that it's not going to work with us delays, but millis() and micros() might be possible with some work. The upside is that it would offer a lot of different PWM frequencies (20 I think) from 37.5kHz right down to 0.07Hz
To be honest, I don't think I would implement that in the main
core distribution. Arduino doesn't implement it and
I am trying to avoid bloat.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on Jan 28, 2015, 08:06 am
Thanks every one for the help. I was able to use the attiny13a as a RGB fader. I used the raw avr libraries from

https://github.com/cpldcpu/light_ws2812 as suggested by this forum. Next i'll use some pot to control each color value individually. Once complete will share the details here.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Feb 17, 2015, 07:00 pm
I was creating ATtiny13 library install for Arduino IDE 1.6.0 ( from smeezekitty library ), just extract in sketchbook/hardware folder.
It has some new feature like change GCC Optimisation flags from IDE directly. I added -O1 flag because with new compiler in some cases can produce smaller .hex file ( must do some experimenting )

(http://i57.tinypic.com/30bh737.jpg)

This is the boards i include ( you can change it from board.txt  )

(http://i57.tinypic.com/sy607o.png)

and burn Bootloader ( only use to change fuse settings, no real bootloader ) works fine from IDE.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: pierrotm777 on Mar 02, 2015, 10:37 am
Tanks for this share  :smiley-grin:  :smiley-grin:  :smiley-grin:
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: grigorym on Mar 26, 2015, 07:59 pm
Thank you very much for IDE 1.6.0 version, works out of the box, which is helpful for beginners like myself. However, a strange recurring feature for all my atmega chips - if I try to burn the bootloader first (only fuses, I know, I know), it fails with some out-of-sync or something. Uploading the blink sketch works (though the sketch produces longer blick delays). Burning the bootloader-fuses after that - works, and the uploading the blick sketch again works perfectly as expected.
I encountered that while programing the atmega328 chip and thought i made a mistake somewhere. But now it repeated again with your compilation for attiny13! Am I missing something?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Mar 26, 2015, 11:39 pm
However, a strange recurring feature for all my atmega chips
I'm not sure i understand you completely. This installation is only for ATtiny13 and has nothing to do with atmega mcu (they use a settings that is in a different location).
Can you explain it more clearly.
What programmer you use?
If you use USBTinyISP then maybe flash timing is problem and here you have a solution for this: ATTiny flash timing problem (http://forum.arduino.cc/index.php?topic=273184.msg1927324#msg1927324)

I use Arduino as ISP  and USBTinyISP and it works well with both.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: grigorym on Mar 27, 2015, 05:57 am
I'm not sure i understand you completely. This installation is only for ATtiny13 and has nothing to do with atmega mcu (they use a settings that is in a different location).
Can you explain it more clearly.
What programmer you use?
1. I am using Arduino as ISP (using Nano board). Only the wierd behaviour (having to upload sketch first, and only then setting the fuses worked) on ATtiny13 matched the one I noticed on 328, so I mentioned it here.

2. Are you sure your configuration option "attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)" works as expected? In my case IDE says it is missing "upload.tool=arduino:avrdude" and ".bootloader.tool=arduino:avrdude". However, having added those I must have locked my ATtiny13, it does not respond anymore.

P.S. May I take some more time to read the whole thread? :) I definitely must not be the only one to try this 128KHz option :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Mar 27, 2015, 11:02 am
2. Are you sure your configuration option "attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)" works as expected? In my case IDE says it is missing "upload.tool=arduino:avrdude" and ".bootloader.tool=arduino:avrdude". However, having added those I must have locked my ATtiny13, it does not respond anymore.
128 KHz option was just copied from a previous settings and I did not adjust it for 1.6.x, and it can not be used with a standard Arduino as ISP , as a rookie you should avoid using internal watchdog oscillator , I'm sorry i have not been thinking, this option had to be deleted, and who knows how to use it, can easily be set manually.
If you tried, it means your ATtiny13 is locked and here you have a good procedure how to unlock :reset-clock-fuse-bits on ATTiny13 (http://www.logikdev.com/2011/02/15/reset-clock-fuse-bits-on-avr/), i tried this procedure, works well and it's easy to use, only instead
Quote
avrdude -p attiny13 -P usb -c usbtiny -tuF
you should put
Quote
avrdude -p attiny13 -P usb -c arduino -tuF
But others fuse settings should work with Arduino as ISP without problems , i just tried them all again.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hiduino on Mar 27, 2015, 12:12 pm
2. Are you sure your configuration option "attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)" works as expected? In my case IDE says it is missing "upload.tool=arduino:avrdude" and ".bootloader.tool=arduino:avrdude". However, having added those I must have locked my ATtiny13, it does not respond anymore.

P.S. May I take some more time to read the whole thread? :) I definitely must not be the only one to try this 128KHz option :)
I've used the 128KHz many times.   The issue here is the tiny13 cpu clock is too slow for some ISP programmers SCK clock speeds.

In order to program at these very low speeds is you need an ISP programmer that will support the Bitclock rate adjustment from avrdude -B option.  There are several programmers that will support this option, AVRispMKII, USBtinyISP(some versions may not work correctly), and USBASP(new firmware versions).  I've even add my own 16KHz clock rate option that works with this bitclock rate adjustment.

ArduinoasISP will not work at these very slow speeds.

For avrdude -B option, you should specify at least -B50.

To program via the IDE, then you will need to change the Global defaults in the avrdude.conf file.
Some where around line 335:
Code: [Select]

#
# Overall avrdude defaults; suitable for ~/.avrduderc
#
default_parallel   = "lpt1";
default_serial     = "com1";
# default_bitclock = 2.5;
default_bitclock = 50;
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: grigorym on Mar 27, 2015, 04:31 pm
ArduinoasISP will not work at these very slow speeds.
As I have no other programmer, but Arduino Nano as ArduinoISP, does that mean I technically can *not* repair that 128KHz issue?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Mar 27, 2015, 04:49 pm
As I have no other programmer, but Arduino Nano as ArduinoISP, does that mean I technically can *not* repair that 128KHz issue?
Try Arduino ISP with boot-time selectable slow SPI (http://pastebin.com/Mngw3UH9)

It may help, but I have not tested it.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: grigorym on Mar 27, 2015, 05:28 pm
Try Arduino ISP with boot-time selectable slow SPI (http://pastebin.com/Mngw3UH9)
Tried already, no luck. Both burning bootloader and trying to upload says: "avrdude: Device signature = 0x000000 avrdude: Yikes!  Invalid device signature."
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Mar 27, 2015, 07:25 pm
OK, i find solution for Arduino as ISP and ATTINY13 on 128 KHz :

open in some text editor:
Quote
sketchbook\hardware\tiny13\avr\boards.txt
Close IDE and change Attiny13 @ 128 KHz section with this :

Code: [Select]
attiny13.name=Attiny13 @ 128 KHz (internal watchdog oscillator)
attiny13.upload.tool=arduino:avrdude
attiny13.upload.using=arduino:arduinoisp
attiny13.upload.maximum_size=1024
attiny13.upload.maximum_data_size=64
attiny13.upload.speed=250

attiny13.bootloader.tool=arduino:avrdude
attiny13.bootloader.low_fuses=0x7B
attiny13.bootloader.high_fuses=0xFF

attiny13.build.mcu=attiny13
attiny13.build.f_cpu=128000
attiny13.build.core=core13


download zipped Arduino_slow_ISP sketch, then start IDE ( i tried on 1.6.1 only ) and install sketch on your arduino programmer ( i tried on breadboard atmega328 on 8MHz ) connect attiny13 as you usual do
and this version of - Arduino_slow_ISP sketch - is sufficiently slow to burn 128KHz fuse and upload sketch, and also change to other fuses as well, I just tried all options.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: grigorym on Mar 27, 2015, 08:38 pm
OK, i find solution for Arduino as ISP and ATTINY13 on 128 KHz :
No change. I think it's time to try something new. Tomorrow I'll take another attiny13 to replace the current one and see if it is going to programmed, just in case I screwed something with schematic or managed to shortcut my poor attiny :). I will also try to find an AVR-fan-neighbor to borrow an external programmer.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Mar 27, 2015, 08:47 pm
No change. I think it's time to try something new. Tomorrow I'll take another attiny13 to replace the current one and see if it is going to programmed, just in case I screwed something with schematic or managed to shortcut my poor attiny :). I will also try to find an AVR-fan-neighbor to borrow an external programmer.
Only if you damage attiny13.Try with new one.

I just lock one ATTiny13 with standard ArduinoISP and unlock with Arduino_slow_ISP , work 100%. That makes using Arduino as excellent ISP programmer of choice.
I'll make one to be permanent, no need to buy anything else.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 28, 2015, 06:08 am
I program them at 128K all the time. I modified the Ardunio ISP program to run at a very low SPI rate
and it works with no problems. Make sure your wire connections are good.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: grigorym on Mar 28, 2015, 09:43 am
I program them at 128K all the time. I modified the Ardunio ISP program to run at a very low SPI rate
and it works with no problems. Make sure your wire connections are good.
I was planning to disappear silently, but bad conscience brought me back to report my stupidity. Common_ground, I was trying to recover with your slow ISP not the attiny13, but the 555 timer chip :)). Surprisingly, it refused to be programmed :). @@@@!

So, reporting. Slow version of Arduino ISP successfully sets the fuses back and programs the chip. After that I was able to switch back to ordinary Arduino ISP. I went the whole process once again: programming with ordinary Arduino ISP the fuses for 128KHz, loosing control of the chip, uploading slow version of Arduino ISP and reprogramming the fuses and the sketch back.

Thank you very much for your assistance and patience. I'll mention the solution on a couple of places, where beginners like me stumbled upon 128KHz option.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on Mar 30, 2015, 02:08 am
As for USBTinyISP programmers, we do not have to change default_bitclock only in avrdude.conf, but we can change the parameters directly from the IDE environment (at least from 1.6.1), without changing avrdude.conf.

Open arduino-1.6.1\hardware\arduino\avr\programmers.txt in some text editor and change usbtiny section with this :

Code: [Select]

usbtinyisp.name=USBtinyISP -B10 (Default)
usbtinyisp.protocol=usbtiny
usbtinyisp.program.tool=avrdude
usbtinyisp.program.extra_params=

############ > 4.8 MHz ##################

usbtinyisp_2.name=USBtinyISP -B2 (> 4.8 MHz)
usbtinyisp_2.protocol=usbtiny
usbtinyisp_2.program.tool=avrdude
usbtinyisp_2.program.speed=2
usbtinyisp_2.program.extra_params=-B{program.speed}

############ < 4.8 MHz ##################

usbtinyisp_4.name=USBtinyISP -B4 (> 0.6 <= 4.8 MHz)
usbtinyisp_4.protocol=usbtiny
usbtinyisp_4.program.tool=avrdude
usbtinyisp_4.program.speed=4
usbtinyisp_4.program.extra_params=-B{program.speed}

############ 128 KHz ##################

usbtinyisp_50.name=USBtinyISP -B50 (= 128 KHz)
usbtinyisp_50.protocol=usbtiny
usbtinyisp_50.program.tool=avrdude
usbtinyisp_50.program.speed=50
usbtinyisp_50.program.extra_params=-B{program.speed}

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


restart IDE and we have USBTinyISP options for diferrent bitclocks :

(http://i57.tinypic.com/x0pq4h.png)

I just try some values and this is empirical result ( no upload error ) i get.

2us for > 4.8 MHz
4us for > 0.6 <= 4.8 MHz
10us - default settings for => 0.6 MHz
50us - for 128 KHz

Because i use often usbtiny for ATTINY85 too, upload speed improving the lot, for example :

Code: [Select]

avrdude: Using SCK period of 10 usec
avrdude: writing flash (8070 bytes):
Writing | ######################################### | 100% 21.05s
Reading | ########################################  | 100% 24.73s

avrdude: Setting SCK period to 2 usec
avrdude: writing flash (8070 bytes):
Writing | ######################################### | 100% 7.33s
Reading | ########################################  | 100% 8.19s


instead of 46 seconds I get the upload for 16 seconds for 8 Kb .hex file on 8 MHz attiny85.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Mar 30, 2015, 03:49 am
With only 1K of memory, upload time isn't a big deal.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Ed1960 on Apr 24, 2015, 12:03 am
1.2K is a lot of bytes for a blink! The code must be not well optimized or sometin'  . You can do plenty of useful things with 1K of command space. For example, here is a code for a 10-LED light chaser (can convert it into Cylon eyes  or some other such blinking toy) and it compiles into only 562 bytes. In fact, there might even be some saving there still, I just didn't have too much time to optimize it.
Code: [Select]


I agree, 1.2k is a lot, i put an entire irrigation system in  some 700 bytes in an attiny13  AND it has a blinking LED :-)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: gneil90 on May 01, 2015, 04:01 pm
Can anyone share with their boards.txt file?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Marzogh on May 02, 2015, 07:01 pm
Can anyone share with their boards.txt file?
There are quite a few floating around the internet. Here's one I've made up (https://github.com/Marzogh/ATtiny). It works as of today on Arduino 1.6.3.

Code: [Select]

menu.cpu=Processor
menu.clock=Clock

attiny.name=ATtiny
attiny.bootloader.tool=arduino:avrdude
attiny.bootloader.unlock_bits=0xFF
attiny.bootloader.lock_bits=0xFF
attiny.build.core=arduino:arduino
attiny.build.board=attiny
attiny.upload.tool=arduino:avrdude
 
attiny.menu.cpu.attiny45=ATtiny45
attiny.menu.cpu.attiny45.upload.maximum_size=4096
attiny.menu.cpu.attiny45.build.mcu=attiny45
attiny.menu.cpu.attiny45.build.variant=tiny8

###############################################################
 
attiny.menu.cpu.attiny85=ATtiny85
attiny.menu.cpu.attiny85.upload.maximum_size=8192
attiny.menu.cpu.attiny85.build.mcu=attiny85
attiny.menu.cpu.attiny85.build.variant=tiny8

###############################################################
 
attiny.menu.cpu.attiny44=ATtiny44
attiny.menu.cpu.attiny44.upload.maximum_size=4096
attiny.menu.cpu.attiny44.build.mcu=attiny44
attiny.menu.cpu.attiny44.build.variant=tiny14

###############################################################
 
attiny.menu.cpu.attiny84=ATtiny84
attiny.menu.cpu.attiny84.upload.maximum_size=8192
attiny.menu.cpu.attiny84.build.mcu=attiny84
attiny.menu.cpu.attiny84.build.variant=tiny14

###############################################################
 
attiny.menu.clock.internal1=1 MHz (internal)
attiny.menu.clock.internal1.bootloader.low_fuses=0x62
attiny.menu.clock.internal1.bootloader.high_fuses=0xDF
attiny.menu.clock.internal1.bootloader.extended_fuses=0xFF
attiny.menu.clock.internal1.build.f_cpu=1000000L

###############################################################
 
attiny.menu.clock.internal8=8 MHz (internal)
attiny.menu.clock.internal8.bootloader.low_fuses=0xE2
attiny.menu.clock.internal8.bootloader.high_fuses=0xDF
attiny.menu.clock.internal8.bootloader.extended_fuses=0xFF
attiny.menu.clock.internal8.build.f_cpu=8000000L

###############################################################
 
attiny.menu.clock.external8=8 MHz (external)
attiny.menu.clock.external8.bootloader.low_fuses=0xFE
attiny.menu.clock.external8.bootloader.high_fuses=0xDF
attiny.menu.clock.external8.bootloader.extended_fuses=0xFF
attiny.menu.clock.external8.build.f_cpu=8000000L

###############################################################
 
attiny.menu.clock.external16=16 MHz (external)
attiny.menu.clock.external16.bootloader.low_fuses=0xFE
attiny.menu.clock.external16.bootloader.high_fuses=0xDF
attiny.menu.clock.external16.bootloader.extended_fuses=0xFF
attiny.menu.clock.external16.build.f_cpu=16000000L

###############################################################
 
attiny.menu.clock.external20=20 MHz (external)
attiny.menu.clock.external20.bootloader.low_fuses=0xFE
attiny.menu.clock.external20.bootloader.high_fuses=0xDF
attiny.menu.clock.external20.bootloader.extended_fuses=0xFF
attiny.menu.clock.external20.build.f_cpu=20000000L

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

attiny13.name=ATtiny13
attiny13.bootloader.tool=arduino:avrdude
attiny13.bootloader.unlock_bits=0xFF
attiny13.bootloader.lock_bits=0xFF
attiny13.build.core=arduino:arduino
attiny13.build.board=attiny
attiny13.upload.tool=arduino:avrdude
attiny13.upload.using=arduino:arduinoisp
attiny13.build.mcu=attiny13

attiny13.menu.cpu.attiny13=ATtiny13
attiny13.menu.cpu.attiny13.upload.maximum_size=1024
attiny13.menu.cpu.attiny13.build.mcu=attiny13
attiny13.menu.cpu.attiny13.build.variant=core13

#################################################
attiny13.menu.clock.internal128=128KHz (internal)
attiny13.menu.clock.internal128.bootloader.low_fuses=0x7B
attiny13.menu.clock.internal128.bootloader.high_fuses=0xFF
attiny13.menu.clock.internal128.bootloader.extended_fuses=0xFF
attiny13.menu.clock.internal128.build.f_cpu=128000L

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

attiny13.menu.clock.internal600=600KHz (internal)
attiny13.menu.clock.internal600.bootloader.low_fuses=0x69
attiny13.menu.clock.internal600.bootloader.high_fuses=0xFF
attiny13.menu.clock.internal600.bootloader.extended_fuses=0xFF
attiny13.menu.clock.internal600.build.f_cpu=600000L

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

attiny13.menu.clock.internal12=1.2MHz (internal)
attiny13.menu.clock.internal12.bootloader.low_fuses=0x6A
attiny13.menu.clock.internal12.bootloader.high_fuses=0xFF
attiny13.menu.clock.internal12.bootloader.extended_fuses=0xFF
attiny13.menu.clock.internal12.build.f_cpu=1200000L

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


attiny13.menu.clock.internal48=4.8MHz (internal)
attiny13.menu.clock.internal48.bootloader.low_fuses=0x79
attiny13.menu.clock.internal48.bootloader.high_fuses=0xFF
attiny13.menu.clock.internal48.bootloader.extended_fuses=0xFF
attiny13.menu.clock.internal48.build.f_cpu=4800000L

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

attiny13.menu.clock.internal96=9.6MHz (internal)
attiny13.menu.clock.internal96.bootloader.low_fuses=0x7A
attiny13.menu.clock.internal96.bootloader.high_fuses=0xFF
attiny13.menu.clock.internal96.bootloader.extended_fuses=0xFF
attiny13.menu.clock.internal96.build.f_cpu=9600000L

################################################
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on May 10, 2015, 11:41 am
Hi all, I am about to start some t13 work again, is everything stable for me to use the cores with 1.6.3 ?
have there been any t13 core updates in the last 6 months or so ?

Its a big ole thread now isnt it !!

:)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 11, 2015, 03:06 am
Hi all, I am about to start some t13 work again, is everything stable for me to use the cores with 1.6.3 ?
have there been any t13 core updates in the last 6 months or so ?

Its a big ole thread now isnt it !!

:)
The last update was in January. I have no idea about 1.6.x. I am  always slow to upgrade Arduino
versions since they always seem to bork something lately.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on May 11, 2015, 08:36 am
Cheers Smeezekitty, I shall tentatively give it a go :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on May 16, 2015, 02:10 pm
Since there is a difference between version 1.6.3 and 1.6.4 in relation to the earlier 1.6.x versions, i decided to make the installation file for 1.6.4 (1.6.3) version only.
Just unpack file in ...\sketchbook\hardware folder.

Boards included :

(http://i58.tinypic.com/250i2x5.png)

I added some GCC Flags ( can be used from IDE menu - choose default if you do not like to use extra optimisation flags ) :

(http://i59.tinypic.com/mtrne9.png)

And i added millis() , micros(),  delayMicroseconds() and set ADC clock for 16 KHz ( it is not set for 16 kHz originally )

If you use 128 KHz - default_bitclock must be slow down to -B50 and for 16 KHz to -B250 ( USBTinyISP)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on May 16, 2015, 09:41 pm
I add attiny13 install file for 1.6.4 IDE :
ATTiny13 for 1.6.4 (http://forum.arduino.cc/index.php?topic=89781.msg2234412#msg2234412)
Since the pins_arduino.h is blank, does someone know the exact pin configuration for the Attiny13? I added a dummy below :)

Code: [Select]

// ATMEL ATTINY13 - ARDUINO
//
//                  +-\/-+
// AinX (D X) PB5  1|    |8  Vcc
// AinX (D X) PB3  2|    |7  PB2 (D X)  AinX
// AinX (D X) PB4  3|    |6  PB1 (D X) PWM
//            GND  4|    |5  PB0 (D X) PWM
//                  +----+

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: nicnac on May 17, 2015, 04:13 pm
Since there is a difference between version 1.6.3 and 1.6.4 in relation to the earlier 1.6.x versions, i decided to make the installation file for 1.6.4 (1.6.3) version only.
Just unpack file in ...\sketchbook\hardware folder.

Boards included :

(http://i58.tinypic.com/250i2x5.png)

I added some GCC Flags ( can be used from IDE menu - choose default if you do not like to use extra optimisation flags ) :

(http://i59.tinypic.com/mtrne9.png)

And i added millis() , micros(),  delayMicroseconds() and set ADC clock for 16 KHz ( it is not set for 16 kHz originally )

If you use 128 KHz - default_bitclock must be slow down to -B50 and for 16 KHz to -B250 ( USBTinyISP)

Thanks for that brilliant setup!
One thing that is not really streamlined is the categories. I changed that. So now it is ATtiny13 with all the clock speed and all compiler options (only listed once for all speeds of course). Only 9.6MHz tested.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: common_ground on May 17, 2015, 07:05 pm
Yes, excellent solution, Thanks nicnac.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 18, 2015, 07:02 am
Since the pins_arduino.h is blank, does someone know the exact pin configuration for the Attiny13? I added a dummy below :)

Code: [Select]

// ATMEL ATTINY13 - ARDUINO
//
//                  +-\/-+
// AinX (D X) PB5  1|    |8  Vcc
// AinX (D X) PB3  2|    |7  PB2 (D X)  AinX
// AinX (D X) PB4  3|    |6  PB1 (D X) PWM
//            GND  4|    |5  PB0 (D X) PWM
//                  +----+



The pins are internally converted hence no need for pins_arduino. If you don't mind, I can add this to the next release for reference purposes. After I check it for accuracy at least
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on May 18, 2015, 07:29 pm
The pins are internally converted hence no need for pins_arduino. If you don't mind, I can add this to the next release for reference purposes. After I check it for accuracy at least
Yes, please add the pinout to the next core13 version :)
Buy why have you just uploaded the core files, and not a complete set of folders, including boards.txt?
The setup would be much simpler if you wouldn't need to dig through the whole forum post to find the correct files :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on May 19, 2015, 06:34 am
Buy why have you just uploaded the core files, and not a complete set of folders, including boards.txt?
The setup would be much simpler if you wouldn't need to dig through the whole forum post to find the correct files :)
Because it is a royal pain in the BUTT to work with the *.txt that Arduino uses. When I wrote it, I couldn't figure it out myself. I kind of have it figured now but there are already working boards.txt out there.

Quote
Please help me out. I was expecting neoPixel lib to be able to handle 9.6MHz but looks like its not.
The neopixel code is unportable (it calls internal core functions rather than just the external ones)
It would need to be rewritten.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on May 19, 2015, 07:45 am
Thanks for the reply. WS2812 based need 800Khz to work. ATtiny13A has internal source for 4.8 & 9.6Mhz. Is it possible to get 800Khz out of tiny13a without external clock source? is it possible to do sort of bit-banging to get the neopixel working? Any suggestion how?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: evildave_666 on May 19, 2015, 08:56 am
There is a non-arduino avr-gcc library for ws2812b out there. It works fine on t13.

https://github.com/cpldcpu/light_ws2812

I doubt you'd be able to shoehorn any arduino worldsemi library onto a t13.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on May 19, 2015, 10:46 am
Thanks, I am using the same library as you pointed. But the pixel are just shining once when they get the power and than go blank. That is why I was trying to use neoPixel library. I'l do some tests and check it once again.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: evildave_666 on May 19, 2015, 01:45 pm
I've run a strip of 10 off of a t13 without any problem with the light_ws2812 library.  Are you sure you aren't having power problems?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on May 24, 2015, 07:43 pm
Thanks, Power was not an issue. But the sample blinky program from ws2812 library is working now, I don't really know the cause why it was not working. What I did is, I just replaced the light_2812 library with the one you suggested and uploaded the program to tiny13A. Thanks.

Here is the program with a push button connected to PB3, WS2812 to PB4. A fixed set of 8 color matrix will cycle with each push of the button.
https://youtu.be/y-Fuz-sQf5w
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: sudhirkhamari on Jun 12, 2015, 08:51 am
Hi All,
   Has anyone tried using an IR receiver with attiny13?? I am planning to hook up an IR sensor to attiny13 so that I can choose/control the color of the ws2812 RGB LED through a remote. if you have any code/diagram then it will really help.

  The code need to be really small to fit in 1KB.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Ed1960 on Jun 23, 2015, 10:14 am
Have been using the attiny13 core for some time with much pleasure.
However, the core already uses the TIM0_OVF_vect, therefore making it impossible to use it for own applications
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: jlx78520 on Jul 01, 2015, 07:12 pm
I added 8, 16 and 20 MHz for arduino ide 1.6.5 they are not very well tested (tested on attiny13a-pu 8MHz, by chip number it should be 20 MHz but delay(1000) says it is ~8 MHz), so be aware that it could not work on your attiny13a or worse... And 20 MHz micros will not work as expected, you can fix it by editing wiring.c line 102 for 20000000 Hz. Instalation is thesame, put folder "tiny13" from zip to Documents\Arduino\hardware folder.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 01, 2015, 09:10 pm
Have been using the attiny13 core for some time with much pleasure.
However, the core already uses the TIM0_OVF_vect, therefore making it impossible to use it for own applications
There is only one timer in the t13. I don't know what else can be done.
Quote
I added 8, 16 and 20 MHz for arduino ide 1.6.5 they are not very well tested (tested on attiny13a-pu 8MHz, by chip number it should be 20 MHz but delay(1000) says it is ~8 MHz), so be aware that it could not work on your attiny13a or worse... And 20 MHz micros will not work as expected, you can fix it by editing wiring.c line 102 for 20000000 Hz. Instalation is thesame, put folder "tiny13" from zip to Documents\Arduino\hardware folder.
Sorry. I don't understand. Are you using an external clock gen?
The Attiny13 do not support 8 or 20MHz on the internal clock.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 13, 2015, 05:51 am
Version 0.21 released

-Edit-
It still isn't 1.6 compliant. I'll try fix that next release.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Jul 13, 2015, 08:15 am
Hello i just tried this in arduino 1.0.6 and i get this when i try to compile:
Code: [Select]

C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp: In function 'long unsigned int pulseIn(unsigned char, unsigned char, long unsigned int)':
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:22: error: expected primary-expression before ']' token
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:22: error: expected `;' before ']' token
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:27: error: expected `}' at end of input
C:\Users\stefan\Documents\Arduino\hardware\tiny13\cores\core13_021\events.cpp:27: error: expected `}' at end of input


it compiles OK in version 0.20 and 0.19
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Jul 13, 2015, 08:24 am
just found the problem...
this line
Code: [Select]
while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}]
change to
Code: [Select]
while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}

And its all good.

Any new functions or big changes from last version?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 13, 2015, 10:06 am
just found the problem...
this line
Code: [Select]
while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}]
change to
Code: [Select]
while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}

And its all good.

Any new functions or big changes from last version?
Somehow I uploaded a broken copy of that file. It's weird because
the current version compiled fine here. Anyway, it's fixed now.

Nothing too big. One of the fixes was actually that function (pulseIn)
Besides bug fixes, I worked on some on the ADC code a bit. The next release
should include boards.txt and platform.txt (or whatever it's called) and
hopefully some of the functions will be a few bytes smaller.

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: Reuti on Jul 25, 2015, 01:29 pm
Hi,

while having a look at the just mentioned events.cpp, I wonder whether all these comparisons are a typo.

Code: [Select]
    to = micros();
    while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}
    while(digitalRead(pin) != stat){if((micros() - st) > timeout){return 0;}}
    st = micros();
    while(digitalRead(pin) == stat){if((micros() - st) > timeout){return 0;}}
    return micros()-st;


to is initialized but never used, and st used before being initialized. I assume, to stands for "start timeout" and all three comparisons with "timeout" should read:

Code: [Select]
{if((micros() - to) > timeout){return 0;}}

instead to cover an overall timeout.

-- Reuti
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 31, 2015, 07:00 am
Guys I need help porting over to Arduino 1.6. It's extremely convoluted and I can't even figure out what is required an what is not
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 01, 2015, 10:05 am
It was rough but I finally got it done.

Core13 0.22 released!

Features:

Native compatibility with Arduino 1.6.x
Size optimization
pulseIn fixed (again)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: cb88 on Aug 10, 2015, 07:49 pm
It would be very nice to be able to use attachinterrupt.... as I want to implement a quadrature encoder to pulse and direction sketch. Basically A and B in on change interrupt pins... and direction and increment pulses out on another pin. Alternatively reading out position counters via i2c on the USI port.

766 bytes for my current sketch (although attachinterrupt is missing and I'm just calling the pin read functions from the main loop so it doesn't optimize them out).


Looks like a cool port... I'm glad to see it working in 1.6.5 also (I found 1.6.4 to be rather buggy)!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: aleksey_ua on Aug 19, 2015, 11:41 pm
Arduino IDE 1.6.4
USBasp programmer

On the native "Core 13 0.22" boards.txt I got:
Quote
Error while burning bootloader: missing 'bootloader.tool' configuration parameter
so, I trying to solve this and make own boards.txt 
Please could someone check it.
Code: [Select]
# boards.txt for Arduino 1.6.4

menu.flag=GCC Flags
menu.cpu=Processor
menu.clock=Clock

attiny13.name=Attiny13
attiny13.bootloader.tool=arduino:avrdude
attiny13.upload.tool=arduino:avrdude
attiny13.upload.tool=arduino:arduinoisp
attiny13.upload.using=arduino:usbasp
attiny13.bootloader.unlock_bits=0xff
attiny13.bootloader.lock_bits=0xff
attiny13.build.core=arduino:core13
attiny13.build.board=attiny

attiny13.menu.cpu.attiny13=ATtiny13
attiny13.menu.cpu.attiny13.upload.maximum_size=1024
attiny13.menu.cpu.attiny13.upload.maximum_data_size=64
attiny13.menu.cpu.attiny13.build.mcu=attiny13
attiny13.menu.cpu.attiny13.build.core=core13
# attiny13.menu.cpu.attiny13.build.variant=core13

#################################################
############## clock speeds #####################
#################################################

#### 9.6 MHz
############
attiny13.menu.clock.t13_9M6=9.6MHz (internal clock, Preserve EEPROM, BOD disable)
attiny13.menu.clock.t13_9M6.bootloader.low_fuses=0x3A
attiny13.menu.clock.t13_9M6.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_9M6.upload.speed=57600L
attiny13.menu.clock.t13_9M6.build.f_cpu=9600000L

#### 9.6 MHz - 2.7V
attiny13.menu.clock.t13_9M6_bod=9.6MHz (internal clock, Preserve EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_9M6_bod.bootloader.low_fuses=0x32
attiny13.menu.clock.t13_9M6_bod.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_9M6_bod.upload.speed=57600L
attiny13.menu.clock.t13_9M6_bod.build.f_cpu=9600000L

#### 4.8 MHz - 2.7V
attiny13.menu.clock.t13_4M8_bod=4.8 MHz (int 4.8 MHz clock, Preserve_EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_4M8_bod.bootloader.low_fuses=0x31
attiny13.menu.clock.t13_4M8_bod.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_4M8_bod.upload.speed=57600L
attiny13.menu.clock.t13_4M8_bod.build.f_cpu=4800000L

#### 1.2 MHz
attiny13.menu.clock.t13_1M2=1.2 MHz (int 9.6 MHz divided by 8,Preserve_EEPROM, BOD - 2.7V)
attiny13.menu.clock.t13_1M2.bootloader.low_fuses=0x2A
attiny13.menu.clock.t13_1M2.bootloader.high_fuses=0xFB
attiny13.menu.clock.t13_1M2.upload.speed=9600L
attiny13.menu.clock.t13_1M2.build.f_cpu=1200000L

#### 600 kHz
attiny13.menu.clock.t13_0M6=600 kHz (int 4.8 MHz divided by 8, Preserve_EEPROM, BOD disable)
attiny13.menu.clock.t13_0M6.bootloader.low_fuses=0x29
attiny13.menu.clock.t13_0M6.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_0M6.upload.speed=9600L
attiny13.menu.clock.t13_0M6.build.f_cpu=600000L

## 128 kHz
attiny13.menu.clock.t13_128k=128 KHz (internal watchdog oscillator)
attiny13.menu.clock.t13_128k.bootloader.low_fuses=0x7B
attiny13.menu.clock.t13_128k.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_128k.upload.speed=250
attiny13.menu.clock.t13_128k.build.f_cpu=128000L

## 16 kHz
attiny13.menu.clock.t13_16k=16 KHz (internal watchdog oscillator, Preserve_EEPROM, BOD disable)
attiny13.menu.clock.t13_16k.bootloader.low_fuses=0x2B
attiny13.menu.clock.t13_16k.bootloader.high_fuses=0xFF
attiny13.menu.clock.t13_16k.upload.speed=250
attiny13.menu.clock.t13_16k.build.f_cpu=16000L



##-----------------------------------
##--------- compiler flags ----------
##-----------------------------------

attiny13.menu.flag.Os=Default
attiny13.menu.flag.Os.compiler.c.extra_flags=
attiny13.menu.flag.Os.compiler.c.elf.extra_flags=
attiny13.menu.flag.Os.compiler.cpp.extra_flags=

attiny13.menu.flag.Os_flto=Default -flto
attiny13.menu.flag.Os_flto.compiler.c.extra_flags=-Wextra -flto
attiny13.menu.flag.Os_flto.compiler.c.elf.extra_flags=-w -flto
attiny13.menu.flag.Os_flto.compiler.cpp.extra_flags=-Wextra -flto

attiny13.menu.flag.O1=-O1
attiny13.menu.flag.O1.compiler.c.extra_flags=-O1
attiny13.menu.flag.O1.compiler.c.elf.extra_flags=-O1
attiny13.menu.flag.O1.compiler.cpp.extra_flags=-O1

attiny13.menu.flag.O1_flto=-O1 -flto
attiny13.menu.flag.O1_flto.compiler.c.extra_flags=-O1 -Wextra -flto
attiny13.menu.flag.O1_flto.compiler.c.elf.extra_flags=-O1 -w -flto
attiny13.menu.flag.O1_flto.compiler.cpp.extra_flags=-O1 -Wextra -flto

attiny13.menu.flag.O3=-O3
attiny13.menu.flag.O3.compiler.c.extra_flags=-O3
attiny13.menu.flag.O3.compiler.c.elf.extra_flags=-O3
attiny13.menu.flag.O3.compiler.cpp.extra_flags=-O3

attiny13.menu.flag.O3_flto=-O3 -flto
attiny13.menu.flag.O3_flto.compiler.c.extra_flags=-O3 -Wextra -flto
attiny13.menu.flag.O3_flto.compiler.c.elf.extra_flags=-O3 -w -flto
attiny13.menu.flag.O3_flto.compiler.cpp.extra_flags=-O3 -Wextra -flto


I have tested this with "Arduino as ISP" and "USBasp programmer" (I would like to use my USBasp programmer in many cases.)

I got an error on the "burn bootloader" stage:
Quote
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0x3f != 0xff
avrdude: verification error; content mismatch
but tiny13 was burned and blinking is working now.

P.S. I use a low speed USBasp in the D:\Program Files\Arduino\hardware\arduino\avr\programmers.txt
Code: [Select]

############ USBasp (16 kHz) ##############

usbasp_2.name=USBasp (-B 32: 16 kHz)
usbasp_2.communication=usb
usbasp_2.protocol=usbasp
usbasp_2.program.protocol=usbasp
usbasp_2.program.tool=avrdude
usbasp_2.program.speed=32
usbasp_2.program.extra_params=-B{program.speed}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: aleksey_ua on Aug 20, 2015, 12:51 am
analogRead(); working only on PB3
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Aug 20, 2015, 10:40 pm
analogRead(); working only on PB3
I just tested it. analogRead() works on all the ADC pins (except I didn't test the reset pin).
Make sure you use the ADC numbers and not the pin numbers for analogRead

PB2 = ADC1
PB3 = ADC3
PB4 = ADC2
PB5 = ADC0
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: cb88 on Aug 27, 2015, 04:00 pm
I requested ATTiny13A pin change library support here https://github.com/NicoHood/PinChangeInterrupt/issues/4

The code there might be compact enough to make sense on the ATtiny13.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: cb88 on Aug 27, 2015, 07:25 pm
So for some reason the delay function is not doing what I expect.

So I programmed an ATTiny13A with the blink demo. Changed it to blink on pin 0. The delay I see is acutally 10 seconds + some change.

If I do delay(100) I see 1 second and some change so its off by a factor of 10.

Edit:

I've investigated a bit further. Apparently my fuses were set to 0x6A 0xFF ... which enables dividing the clock by 8. With the fuse bits set to 0x7A 0xFF I now get delay(1000) = 1.31 seconds. delay(770) = 1 second.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: orlv on Jan 17, 2016, 11:32 am
Hi! I fixed all of the firmware uploading warnings, and changed menu.

https://github.com/orlv/at13 (https://github.com/orlv/at13)

Changes in boards.txt and platforms.txt
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jan 17, 2016, 02:53 pm
Isn't it possible to minimize the footprint of this core even more? a "blank" sketch (empty setup() and loop() ) takes up 172 bytes. Thats 17% of the memory without doing anything!

Wouldn't it be possible to instead have to start things like millis and micros manually, using #define? This would make this core a little more "manual", but the footprint would be much smaller.

(This core should also be hosted on Github rather than SourceForge, for obvious reasons)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 19, 2016, 02:55 am
Isn't it possible to minimize the footprint of this core even more? a "blank" sketch (empty setup() and loop() ) takes up 172 bytes. Thats 17% of the memory without doing anything!
172 bytes isn't a lot. The memory on the Tiny13 is just very small.
It might be possible with an optimized rewrite in assembly. But in C while remaining Arduino compatible, I doubt it.

Quote
Wouldn't it be possible to instead have to start things like millis and micros manually, using #define? This would make this core a little more "manual", but the footprint would be much smaller.
For fixed delays. For variable delays, probably not.
Quote
(This core should also be hosted on Github rather than SourceForge, for obvious reasons)
To be quite honest, they are both bad
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: bartgee on Feb 01, 2016, 12:44 am
Arduino IDE 1.6.4
USBasp programmer
Got my ATtiny13A working with your changes, aleksey_ua. Great job! Before I could even burn the bootloder, I had to set proper fuse bits with:

avrdude -p attiny13 -P usb -c usbasp -b 9600 -q -U lfuse:w:0x7a:m -U hfuse:w:0xff:m

If you don't mind - I've just put your changes to my github repo:
https://github.com/bartgee/at13 (https://github.com/bartgee/at13)
with a note, that these changes were made by you.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: glassgiant on Feb 22, 2016, 12:09 am
I'm having some trouble with core13, using in internal pullup resistor.  I have a led/resistor on pin 6 (PB1) which fades in and out.  I want to ground pin 5 (PB0) to toggle fast/slow fading, but it doesn't seem to be working with an attiny13a.  In the following code, the LED flashes fast when pin 5 is open.  When pin 5 is grounded, the LED does not light at all.  I see your INPUT_PULLUP workaround, and think I'm accounting for it in the code below.  For the life of me, I can't see the problem.  Any ideas?

int led = 1;           // the pin that the LED is attached to
int tswitch = 0;       // user selectable switch
int brightness = 0;    // how bright the LED is
int fadeAmount = 1;    // how many points to fade the LED by
int dtime = 100;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(tswitch, INPUT);
  digitalWrite(tswitch, 1);
}

void loop() {
  if (digitalRead(tswitch)) {
    dtime = 10;
  } else {
    dtime = 100;
  }
  // set the brightness
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }
  // wait to see the dimming effect
  delay(dtime);
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: uxomm on Feb 22, 2016, 02:45 am
This sketch works on my setup with ATtiny13a.
You should check your hardware.

By the way: the changes are  v e r y  slow when the button is pressed, so i have changed the dtimes to
Code: [Select]

if (digitalRead(tswitch)) {
    dtime = 1;     // original: 10
  } else {
    dtime = 10;   // original: 100
  }

so you can see the changes (button not pressed / button pressed) much better.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on May 22, 2016, 11:26 am
Hi SmeezeKitty,
I'm just about to test my ATTiny13a hardware for some software I have written, I am using 1.6.3 and the code is written in assembler within a main() loop. Hopefully all will go well and I can report back soonish
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jul 06, 2016, 08:27 pm
Hi SmeezeKitty,
I'm just about to test my ATTiny13a hardware for some software I have written, I am using 1.6.3 and the code is written in assembler within a main() loop. Hopefully all will go well and I can report back soonish
Any news?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: mcnobby on Jul 07, 2016, 09:50 am
Hi SK, no news as yet, I was having a bit of trouble with a few things in 1.6.3/t13 combination, so I ended up using an older stable IDE

I WILL be getting back to this as I have projects that need attention

Thanks, as always :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 07, 2016, 05:20 pm
What seems to be the problem with IDE 1.6? Per1234 helped me out porting my Arduino cores over to 1.6, so I (or him) might be able to help you out ;)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 17, 2016, 03:31 pm
I had some spare time, and created a fork of this core, called MicroCore (https://github.com/MCUdude/MicroCore). I've added some additional core settings (https://github.com/MCUdude/MicroCore/blob/master/avr/cores/microcore/core_settings.h) where changes can be done to reduce the flash usage.

The code compiles just fine, and I'm able to set fuses and upload the sketch to the microcontroller. Stil I'm having some weird issues. I've tried other forks that works out of the box as well, and they got the same issues as well. I'm running Arduino IDE 1.6.9, but I've also tried with the older 1.6.5 as well.

Have a look at the AVR code:

Code: [Select]

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  DDRB |= _BV(PB2);
 
  while(1)
  {
    PORTB ^= _BV(PB2);
  }
}


PB2 is set as an output, and will toggle every time the while loop runs. Easy right? I'm running this at 9.6MHz, even though I can reproduce this problem on all clock frequencies.

After uploading the code this is what the screen on my scope says:
(open in new window for higher resolution)
(http://i.imgur.com/50KpAEN.jpg)

(http://i.imgur.com/MSNiFjt.jpg)



The _really fast_ square wave runs for about 16.4 ms, with a period of about 82.8 ms. Here's a picture of the square wave itself (ignore the long  yellow line, the signal is hard to trigger):
(http://i.imgur.com/EywoKY3.jpg)


.. And this is a picture of my setup:
(http://i.imgur.com/WstS9HB.jpg)


How is this even possible? The low level code should work just fine, shouldn't it?  :(  Have you experienced this before smeezekitty?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Jul 17, 2016, 05:44 pm
I have used this core a lot with low level stuff with no problem so i tried your code with your MicroCore and with this core. No problem with either no pauses at all.(9.6mhz no bod)

I ran it on breadboard with only power and salea clone connected.

On the picture you have the programmer plugged in can that cause this??

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 17, 2016, 06:06 pm
Oh this is embarrassing! :smiley-confuse: I unplugged the programmer, and everything works just fine! I was using an avrispmkII when I took the pictures. The USBtinyISP does not interfere like that :)

I've not been able to get the other ones put there running without having to do some modifications, so I decided to create my own fork :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Jul 17, 2016, 06:20 pm
hehe soo easy to mess up like that i have done something similar that is why i thought of it....

Good luck with the core, Make a post when its time for testing and i will give it a test spin.
Title: What is the current final version of the aTTiny13 core today?
Post by: caiopoit on Jul 21, 2016, 09:07 pm
What is the current final version of the aTTiny13 core today? Can I use on ide 1.0.5 r2 ? Where can I download it? I have tried so many cores by now... None of them worked properly (usually clock and timer problems). I'd be very glad if anyone could help. Thanks.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 22, 2016, 12:01 am
I just did a large rewrite, but it works only with Arduino 1.6+, thus without having to do any modifications to make it work :) ---> MicroCore - Github (https://github.com/MCUdude/MicroCore)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: caiopoit on Jul 22, 2016, 05:40 am
I did all as this tutorial says (https://github.com/MCUdude/MicroCore#supported-clock-frequencies) even burned the bootloader but it doesn't blink at the defined time...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 22, 2016, 08:10 am
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?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: caiopoit on Jul 22, 2016, 04:40 pm
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...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: DrAzzy on Jul 22, 2016, 05:01 pm
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.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: caiopoit on Jul 22, 2016, 06:11 pm
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!!!
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 22, 2016, 06:18 pm
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? :)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: DrAzzy on Jul 22, 2016, 06:44 pm
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  (https://github.com/SpenceKonde/ATTinyCore/blob/master/avr/cores/tiny/wiring.c#L218)
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 22, 2016, 07:10 pm
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
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: caiopoit on Jul 22, 2016, 08:58 pm
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...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: DrAzzy on Jul 22, 2016, 09:19 pm
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.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: caiopoit on Jul 22, 2016, 09:54 pm
I understand. Thanks for the help guys. At least I can now do something with my aTTiny13.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jul 23, 2016, 10:22 am
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);
}
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: 1413 on Nov 06, 2016, 12:27 am
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,
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Nov 06, 2016, 11:17 am
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 (https://github.com/MCUdude/MicroCore), which solves a lot of the problems you introduced in core13. Forum post here (http://forum.arduino.cc/index.php?topic=426153.0).
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: dw23q on Nov 09, 2016, 03:06 am
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?
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: swe-dude on Nov 09, 2016, 09:40 am
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...
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: bipsen on Jan 07, 2018, 01:18 pm
Any chance of a release, that will fit the Arduino 1.8.x toolchain?

As far as I can see, the location of the files need to be adjusted...

Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: hansibull on Jan 07, 2018, 07:46 pm
There exist various forks of core13 on Github that works with IDE 1.8.x.
MicroCore (https://github.com/MCUdude/MicroCore) is probably the best one out there with lots of improvements (both efficiency and features) compared to core13.
Title: Re: core13: An Arduino core for the Attiny13 *testers wanted*
Post by: smeezekitty on Jan 21, 2018, 09:06 pm
I am not currently set up to work with Tiny13 so the development is on hold. At this point, it is best just to use one of the forks. There are a number of differences -- some are clearly improvements and others have upsides and downsides. Either way, you could always transplant bits of code if it doesn't work exactly how you want. The important thing is that they are maintained to be compatible with the newest version of the Arduino IDE. Something I always had trouble with because it changes so often