Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #45 on: March 14, 2012, 01:54:15 pm » |
hello,
I found a bookstore that uses a library ATTINY13 for ATtiny 8.
I've never heard of an Attiny8. /* 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
Full Member
Karma: 1
Posts: 220
Arduino BBB
|
 |
« Reply #46 on: March 30, 2012, 09:56:54 pm » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Pennsylvania, USA
Offline
Newbie
Karma: 0
Posts: 31
Trying to make sense of it all
|
 |
« Reply #47 on: March 30, 2012, 10:38:09 pm » |
Thanks for your work, now I can play with $1.13 MCUs instead of those big expensive $2.26 attiny85 chips  It's the effort needed to squeeze everything you need into a smaller box, so to speak, that makes it all the more fun.  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
|
|
|
|
|
Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #48 on: March 30, 2012, 10:52:22 pm » |
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  The boards.txt was just a clobbered together example. I will be honest, I do not understand the boards.txt very well. 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
Full Member
Karma: 1
Posts: 220
Arduino BBB
|
 |
« Reply #49 on: April 01, 2012, 12:46:03 am » |
It looks (from the fuses) like the default clock speed is 1.2MHz (9.6MHz internal RC clock divided by  , 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  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
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #50 on: April 01, 2012, 02:55:16 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. 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
Edison Member
Karma: 25
Posts: 2063
|
 |
« Reply #51 on: July 05, 2012, 07:45:30 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
|
|
|
|
|
Logged
|
|
|
|
|
Pennsylvania, USA
Offline
Newbie
Karma: 0
Posts: 31
Trying to make sense of it all
|
 |
« Reply #52 on: July 05, 2012, 08:09:01 am » |
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
|
|
|
|
|
Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #53 on: July 06, 2012, 12:35:14 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.
|
|
|
|
|
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
Newbie
Karma: 0
Posts: 4
Arduino newbie - mechanical engineer / electronics hacker
|
 |
« Reply #54 on: July 10, 2012, 02:18:36 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
|
|
|
|
|
Logged
|
All electronics run on smoke - when the smoke escapes they always quit working!
|
|
|
|
Washington
Offline
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #55 on: July 10, 2012, 02:44:01 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) 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
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #56 on: July 10, 2012, 12:09:23 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...
|
|
|
|
|
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
Newbie
Karma: 0
Posts: 4
Arduino newbie - mechanical engineer / electronics hacker
|
 |
« Reply #57 on: July 11, 2012, 11:41:30 pm » |
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
God Member
Karma: 20
Posts: 717
Firefox & Arduino rocks
|
 |
« Reply #58 on: July 12, 2012, 01:47:09 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).
|
|
|
|
|
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
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #59 on: July 17, 2012, 01:10:59 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: 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
|
|
|
|
|
|