Attiny13 memory size limit - Page 1
Forum section: electronics / projects

author: Daniel_Reyes
author_rank: Regular Contributor
timestamp: September 22, 2015, 12:02:34 am
content: Good evening everyone,I'm currently away from my lab out of town on training and I bought a few things on ebay for when I return.I plan on building a small motion sensor to guard my front door and front window to my home so that would be two separate sensors facing 180 degrees away from each other.I would like to have a green and red led to show whether the alarm is activated or not.I would also like to have an ir receiver so that i can remotely turn it on and off.Due to budget concerns i bought the attiny13 and am now wondering if it can hold all the required code to perform these functions. If anyone has some experience, i humbly ask your advice.-DanSent from my SM-G900P using Tapatalk

author: ralphd
author_rank: Frequent Contributor
timestamp: September 22, 2015, 12:27:07 am
content: The question really belongs in the microcontroller forum.Nevertheless, the IR decoding in software may be a problem in 1KB.

author: georges80
author_rank: Frequent Contributor
timestamp: September 22, 2015, 12:56:24 am
content: attiny85 would have been a better choice for not much more money from a capacity perspective.Better yet a chip with more pins since you want 2 sensors, 2 leds, irda etc.Seems an 8 pin chip (5 i/o's since 2 are for power and 1 for reset#) is quite restrictive as well. Your budget can't stretch to $2 or $3??cheers,george.

author: Daniel_Reyes
author_rank: Regular Contributor
timestamp: September 22, 2015, 01:04:23 am
content: Quote from: georges80 on September 22, 2015, 12:56:24 amI've put about $4000 into this hobby in the last year before the wife caught on. Now i have to pinch pennies. I can buy it but i should wait till next month.Other question, is there a lot of overhead with arduino ide sketches? Should i try doing everything myself in eclipse to save space?Sent from my SM-G900P using Tapatalk

author: rs20
author_rank: Super Contributor
timestamp: September 22, 2015, 01:09:16 am
content: What does IR decoding actually entail? It's just measuring pulse lengths, isn't it? If you write some really purpose-specific code that can only recognise the "on" and "off" commands, 1KB should be fine I would have thought.In any case, you don't need to guess. Write your code up in Atmel Studio (or whatever), and see how big it is. You can always change the target chip mid-way through your project. If you find it's too big, post your source and assembler here andthenwe have a fun, interesting exercise to see if it can be shortened.Having said all that, I concur with others that just using a larger chip would save you worrying about it. It's nicer to think about code shrinking as a bonus exercise, rather than making it a blocker for testing your idea.Quote from: Daniel_Reyes on September 22, 2015, 01:04:23 amIf you use the setup() and loop() functions, arduino inserts its own main() function which calls init(), which is a rather heavy function. IIRC, the solution is simply to use main() instead. This will prevent some of the arduino functions, like delay(), from working, because init() needs to set up the timers in order for delay() to work. But, if you just avoid those Arduino functions and use the registers yourself (DDRB, PORTB for I/O, TCCR1A etc for timers) you'll get much smaller code size. You don't need to abandon the Arduino IDE to get all this.EDIT: To attach some numbers to this claim, here's the default empty Arduino sketch, which occupies464bytes:Code:void setup() {// put your setup code here, to run once:}void loop() {// put your main code here, to run repeatedly:}And here's the same sketch, compiles in the same IDE, but "translated" to not use the Arduino init function(). Occupies134bytes, which is most likely the interrupt table and other misc stuff.Code:int main() {// put your setup code here, to run once:for (;;) {// put your main code here, to run repeatedly:}}

author: Daniel_Reyes
author_rank: Regular Contributor
timestamp: September 22, 2015, 01:12:00 am
content: Quote from: rs20 on September 22, 2015, 01:09:16 amGreat! ! Thank you!Sent from my SM-G900P using Tapatalk

author: ralphd
author_rank: Frequent Contributor
timestamp: September 22, 2015, 01:34:58 am
content: Quote from: georges80 on September 22, 2015, 12:56:24 am4 IO pins is sufficient: 1 for each PIR, 1 for the 2 LEDs (active high and active low), and 1 for IR in.

author: sleemanj
author_rank: Super Contributor
timestamp: September 22, 2015, 01:43:05 am
content: If you want to try with the Arduino IDE, you will want to use "Core13" which is a minimal Arduino core for the Tiny13, for some reason the person who made Core13 didn't make a boards.txt to actually use it, so I have put it all including my boards.txt into a single zip file you can download here, there's a readme telling you what to do with it:http://www.thingiverse.com/download:1620380Note that because the Arduino IDE doesn't have a way to tell avrdude to slow down, you may need to use an ISP which is capable of being slowed down by a jumper, or automatically slow itself down.

author: Macbeth
author_rank: Super Contributor
timestamp: September 22, 2015, 01:52:01 am
content: Quote from: georges80 on September 22, 2015, 12:56:24 amTotally agree on the tiny85... as for /RESET you can disable it with a fuse to enable the extra i/o - like I recently didwhen testing some TIL311's here

author: Daniel_Reyes
author_rank: Regular Contributor
timestamp: September 22, 2015, 02:22:44 am
content: Quote from: Macbeth on September 22, 2015, 01:52:01 amAfter you disable reset pin, does that prevent it from being reprogrammed?Sent from my SM-G900P using Tapatalk

author: georges80
author_rank: Frequent Contributor
timestamp: September 22, 2015, 02:35:34 am
content: Yes, you re-assign reset# and you can't ISP the part anymore. Similarly with only 5 gpio and you use 2 for PIR and 2 for the LED, you have to battle with ISP pin sharing.Seriously, a tiny84 is like 10c more than a tiny85 (one piece pricing) and gives you more i/o pins. It's $1.73 for 1 piece at digikey...For a hobby, it's not like you have to REALLY penny pinch (especially if you blew $4000 already, just skip one coffee at your favourite coffee shop).... Get a chip with enough I/O that you don't have to deal with the ISP pins doing double duty with other i/o pins, gives you plenty of flash and ram and can easily be programmed via studio and a c compiler (all free).I've never tried any of the arduino koolaid since it's just another layer of stuff between my code and my hardware. Fine I guess if you are starting out without any hardware/software experience, but beyond that...cheers,george.

author: Daniel_Reyes
author_rank: Regular Contributor
timestamp: September 22, 2015, 02:39:36 am
content: Quote from: georges80 on September 22, 2015, 02:35:34 amThanks! I'll consider getting an tiny84. I knew the tiny13s were going to bite me in the end. I wonder what i can do with them now. It's all fun for me, my wife just wants to see some completed projects before i continue spending. I may have a intervention in my future.Sent from my SM-G900P using Tapatalk

author: matseng
author_rank: Frequent Contributor
timestamp: September 22, 2015, 03:48:02 am
content: The Tiny13 got 1K of flash, and that is just as much ram I had in my first computer back in the seventies - a KIM-1.... 1K was enough to fit a chess playing program so good that it most of the times beat the 12 year old me. :-)I don't want to live in a world where engineering/programming type people doubt that it's easy to to fit code for reading a motion detector and flash some LEDs in 1K of code space...

author: Daniel_Reyes
author_rank: Regular Contributor
timestamp: September 22, 2015, 03:49:50 am
content: Quote from: matseng on September 22, 2015, 03:48:02 amHaha. Love it! Ill give it a good try.Sent from my SM-G900P using Tapatalk

author: georges80
author_rank: Frequent Contributor
timestamp: September 22, 2015, 04:13:49 am
content: Quote from: matseng on September 22, 2015, 03:48:02 amOk, I made my own 8080 based computer and hand wired 1k static ram to it back in the 70's too. The whole computer was hand made and point to point soldered, not a kit, I designed it from scratch using the datasheets, before you could buy an altair or imsai. All hand coded (no cross assembler etc back then). Manually entered the entire written from scratch monitor (and hand assembled) and programmed it into a 2708 (home made programmer), yes I've done things the hard way too. It was fun and instructive back THEN.We're now in the 21st century and an 8k attiny84 at digikey costs $1.73 (versus more than $50 for JUST the 8080 back then). I now code in C (I do know how to code in asm for the AVR 8 bit family, having started with the attiny15 quite a few years ago).Do I now try and squeeze things into a 1k part when I can purchase an 8k part for a few pennies more that has room for adding features later... I don't think so... Do I use modern parts that can be easily support C development and source level debugging? Yep. I've moved on from the 70'scheers,george.

author: matseng
author_rank: Frequent Contributor
timestamp: September 22, 2015, 04:34:57 am
content: George, nice to find another oldtimer that have actually done stuff the hard way once upon a time.Your points are very valid in general, just use a bigger device for ease of coding. I'd probably just reach down in my box of assorted teensies and mini/micro arduinos priced at $2-3 each and use one of those of a one-off project like this.But! And that is a big but in this discussion - the question from the OP was ifhe could fit the code required for his application in a Tiny13 or not. Not if it was the most cost/time effective way of doing it.

author: georges80
author_rank: Frequent Contributor
timestamp: September 22, 2015, 05:19:07 am
content: Yeah, he did ask if it would fit - but then mentioned arduino sketches... So, unless the OP has some asm skill he's looking at some kind of C environment + all the arduino bloatware/overhead and the tiny13 is quite limited when you add that framework overhead...cheers,george.

author: rs20
author_rank: Super Contributor
timestamp: September 22, 2015, 07:04:12 am
content: Quote from: georges80 on September 22, 2015, 05:19:07 amExcept, as I've already pointed out in detail, you just have an Arduino sketch with "main()" instead of "setup()" and lo, the bloatware is gone. Arduino IDE doesnotimply Arduino bloat. Also, Arduino IDE supports the __asm__ block.

author: Psi
author_rank: Super Contributor
timestamp: September 22, 2015, 07:23:28 am
content: Quote from: Daniel_Reyes on September 22, 2015, 01:04:23 amYou can buy an atmega with like 64KB of flash for less than a coffee. I don't see the issue. Unless money really is that tight

author: android
author_rank: Regular Contributor
timestamp: September 22, 2015, 08:14:32 am
content: If you want to save a pin, you could try this trick to drive two LEDs (alternately) with a single output. Works best with red/blue, red/white, but red/green should be ok...