Pages: 1 2 3 [4] 5 6 ... 16   Go Down
Author Topic: core13: An Arduino core for the Attiny13 *testers wanted*  (Read 40605 times)
0 Members and 1 Guest are viewing this topic.
Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-grin
Logged

Pennsylvania, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Trying to make sense of it all
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for your work, now I can play with $1.13 MCUs instead of those big expensive $2.26 attiny85 chips smiley-grin
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.
Logged


 /\_/\      ARDUINO
((@v@))     CNC
()~|~()

Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-grin
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.
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 223
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 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 smiley-grin

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.
Logged

Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: April 01, 2012, 02:58:10 am by smeezekitty » Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Marche
Offline Offline
Edison Member
*
Karma: 33
Posts: 2265
azioni semplici per risultati complessi
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pennsylvania, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 31
Trying to make sense of it all
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


 /\_/\      ARDUINO
((@v@))     CNC
()~|~()

Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

San Diego
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino newbie - mechanical engineer / electronics hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

All electronics run on smoke - when the smoke escapes they always quit working!

Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

San Diego
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino newbie - mechanical engineer / electronics hacker
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

All electronics run on smoke - when the smoke escapes they always quit working!

Washington
Offline Offline
God Member
*****
Karma: 38
Posts: 790
Firefox & Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
void setup()
{
     pinMode(0, OUTPUT);
     pinMode(A2, INPUT);
}

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

Pages: 1 2 3 [4] 5 6 ... 16   Go Up
Jump to: