/script>
[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

1kB challange - /1kc/

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 47
Thread images: 7

File: 1kb.jpg (238KB, 800x533px) Image search: [Google]
1kb.jpg
238KB, 800x533px
What whare you working on /g/? Have you already started?

https://hackaday.io/contest/18215-the-1kb-challenge
>>
>>57631621
>1kB

Seems pretty boring when you get so much resource to work with.
>>
>>57631658
...What?
>>
1KB? Isn't that a lot? Aren't there 64B demos and shit?
>>
OP here,
I want to do something embedded. Any ideas?
Got stuff liek this:
>buttons
>switches
>7400 NAND-Gates
>MOSFETS (not in picture)
>LEDs
>L298N motor driver
>sound sensor (not in picture)
>attiny85 (will be replaced by attiny13, but doesnt matter I guess)
>433MHz modules

What do? Thought about maybe some sort of self driving car maybe with IR sensors, but not sure if this would fit into 1kB.
And I am not sure, but if I want to use those rf modules either chip only has to have 512bytes...
>>
>>57631658
t. """""""""professional""""""""""""""""""""" meme.js developer
>>
File: IMG_2381.jpg (2MB, 3000x2000px) Image search: [Google]
IMG_2381.jpg
2MB, 3000x2000px
>>57631676
forgot picture

>>57631670
It is a lot, but question is: How much can you do with it?
>>
File: output.webm (258KB, 1280x720px) Image search: [Google]
output.webm
258KB, 1280x720px
OP here,
did simple blink sketch just to have an impression how much 1kB is.
#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 1000000

int main() {

DDRB = 0xFF;
while(1) {
PORTB |= (1 << PB0);
_delay_ms(500);
PORTB &= ~(1 << PB0);
_delay_ms(500);
}
return 1;
}
>>
File: memory.png (15KB, 394x177px) Image search: [Google]
memory.png
15KB, 394x177px
>>57631812
>>57631670

pic related.
So 1kB is really not very much, m9.
>>
>>57631812
That's nice
>>
>>57631658
On the contrary, things get fun when you're limited in resources.
That forces you to be creative, and in the process you get good ideas.

t. A wannabe SNES programmer
>>
a clap code activated coffee-maschine

should be all the parts to create a "add-on" to a regular one only except putting in water+coffee
>>
>>57632276
Wew, this sounds nice.
My thought maybe a water kettle which boils my water only to 80°C for my green tea (or different temperatures on button press), since my old one doesn't have a temperature sensor - maybe I'll add one and add that clap idea.
>>
>>57632276
But that would be more of an analog electronic than a programming exercise.
>>
>>57632333
nice trips.

That doesn't actually matter imo. It just have to be somewhat creative. Guess I won't get under first four places anyways...
>>
>>57631812
>>57631823
I compiled it for atmega328p.
$ avr-gcc avr.c -o test.elf -Os -mmcu=atmega328p -DF_CPU=1000000UL
$ avr-size -C --mcu=atmega328p test.elf AVR Memory Usage
----------------
Device: atmega328p

Program: 178 bytes (0.5% Full)
(.text + .data + .bootloader)

Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)


but let's make a change. we can toggle pin state by writing to pin register, like that
#include <avr/io.h>
#include <util/delay.h>

int main() {

DDRB = 0xFF;
while(1) {
PINB |= (1 << PB0);
_delay_ms(500);
}
}


and what do we get? we save space
$ avr-size -C --mcu=atmega328p test.elf AVR Memory Usage
----------------
Device: atmega328p

Program: 158 bytes (0.5% Full)
(.text + .data + .bootloader)

Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)


If attiny85 supports pin toggling by writing 1 to pin register, then your compiled sketch will take 78 bytes instead of 98 bytes. That's an improvement.
>>
File: asdasd.png (12KB, 337x148px) Image search: [Google]
asdasd.png
12KB, 337x148px
>>57632539
wew, didn't knew that.
Apperently your solution doesn't work on attiny85, but this works and saves space, too:
#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 1000000

int main() {

DDRB = 0xFF;
while(1) {
PORTB ^= (1 << PB0);
_delay_ms(500);
}
return 1;
}


Will look more into this, when I have time. Thanks though!
>>
>>57632597
I highly believe your code will get 50-ish byte size written in ASM.
>>
>>57632650
I have never ever written ASM though.
>>
>>57632333
>>57632385

well you can as i said use the inputs and be creative with them as i said "clap code" also you can use leds as outputs

if you really want to use up the 1kb as a whole you would need a lot more data to handle since logic isnt that big
>>
>>57632597
It should work.
http://www.atmel.com/images/atmel-2586-avr-8-bit-microcontroller-attiny25-attiny45-attiny85_datasheet.pdf
>10.2.2 Toggling the Pin
>Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn. Note that the SBI instruction can be used to toggle one single bit in a port.
And when you compile it with -Os,
PINB |= (1 << PB0);

gets compiled into
sbi 0x16,0


and don't use that #define, because it does not work for delay.h,
>>
>>57631621
What will I win? A bunch of facebook likes?
>>
>>57632719
>What will I win? A bunch of facebook likes?
http://hackaday.com/2016/11/21/step-up-to-the-1-kb-challenge/
Grand prize is a Digi-Comp II kit from EMSL
First prize is a Maker Select 3D printer V2
Second Prize is a Bulbdial Clock kit from EMSL
Third Prize is a Blinkytile kit from Blinkinlabs
>>
>>57632820
>Grand prize is worse than first prize
>>
>>57632699
oh yes, it does work. Thanks m8!
I have not seen that you used "PINB" instead of "PORTB".
>>
>>57632691
Try that, it's not hard.
Also I think
Loop:
...
goto Loop;

must take less space than while (1) { ... }
>>
>>57631670
64kb, not 64b
>>
>>57632850
And setting only one bit in DDRB instead of whole register also saves space.
#include <avr/io.h>
#include <util/delay.h>

int main()
{
DDRB |= (1 << PB0);
while(1)
{
PINB |= (1 << PB0);
_delay_ms(500);
}
}


AVR Memory Usage
----------------
Device: attiny85

Program: 76 bytes (0.9% Full)
(.text + .data + .bootloader)

Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)

>>57632880
but while(1) is compiled to something like that. it doesn't check if 1 is equal to 1, it jumps unconditionally
>>
>>57632914
>but while(1) is compiled to something like that
Amazing.
>>
>>57632914
>DDRB |= (1 << PB0);
How does this get translated into ASM?
>>
>>57632832
3d printers are garbage unless you have a heavy duty industrial one
>>
>>57633055
sbi 0x17,0

0x17 is the address of DDRB register. It sets bit0 in DDRB to 1. And bit0 is PB0. It takes two bytes.
>>
literally 8000 bits of program memory
>>
>>57632914
And if we check _delay_ms documentation, we can see that The maximal possible delay is 262.14 ms / F_CPU in MHz. We run our attiny at 1MHz, so chagning delay value from 500 to 262 produces smaller program. 70 bytes instead of 76.
http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

Can we make it even smaller? Perhaps by using timer interrupt instead of delay loop?
>>
>>57633137
What is this soccery, am I really on /g/?
Never thought that I would learn so much on /g/, wtf.
>we are only discussing about a simple blink sketch here
wew

PS: for me it's 72 bytes then
>>
>>57633167
#include <avr/io.h>
#include <util/delay.h>

int main()
{
DDRB |= (1 << PB0);
while(1)
{
PINB |= (1 << PB0);
_delay_ms(262);
}
}

$ avr-gcc avr.c -o test.elf -Os -mmcu=attiny85 -DF_CPU=1000000UL
$ avr-size -C --mcu=attiny85 test.elf
AVR Memory Usage
----------------
Device: attiny85

Program: 70 bytes (0.9% Full)
(.text + .data + .bootloader)

Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
>>
>>57633189
why does
>DDRB = 0x01;
need 2 bytes more than
>DDRB |= (1 << PB0);
??
>>
>>57633255
See
>>57633074
Almost every command in 2 bytes wide, so in the DDRB = 0x01 statement you get at first 0x01 value loaded into some temporary register, and later this value is pushed from temporary register into DDRB.
>>
>>57633286
Oh okay, thanks!
So fuckin sick how much you can learn with that stuff if you really focus on getting the best out of it. I am impressed
>>
>>57633255
because it first hast to load 0x01 to a register and then save it in memory under address of DDRB register.
two bytes for loading 0x01 to a register
two bytes for saving it to memory

but there is a two byte instruction that allows you to set a specific bit in a register to one, so it's more efficient to use that when you need to change only one pin
>>
You guys really inspire me to learn, thanks for being
>>
>>57631658
Shitty developers like you are the reason why everything is so bloated these days
>>
Any resources for learning low level C? Specifically microcontrollers.
>>
>>57633410
tips from atmel http://www.atmel.com/images/doc1497.pdf
>>
File: 1449344258887.png (81KB, 500x606px) Image search: [Google]
1449344258887.png
81KB, 500x606px
>>57633428

Thanks anon.
>>
File: 1401438112071.png (398KB, 699x523px) Image search: [Google]
1401438112071.png
398KB, 699x523px
Why do peeps on gee don't make more of this stuff? ;_;

All that anime shit makes me a sad pepe
>>
>>57631621
That VGA blinking project looks nice.
Thread posts: 47
Thread images: 7


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.