#avr Logs

May 25 2017

#avr Calendar

12:20 AM day__ is now known as daey
01:39 AM Emil: to divide by ten you can multiply by 20 and shift down once
01:39 AM Emil: äh
01:39 AM Emil: I cant think
01:41 AM Emil: lol
01:44 AM Emil: well division by 5 is faster iirc
01:44 AM Emil: so do that and shift down once
02:01 AM rue_bed: what happened to the good ole 'bcd adjust register'
02:01 AM rue_bed: instruction...
02:02 AM rue_bed: I'm surprised C dosn't have a bcd type
02:03 AM rue_bed: 50 cycles? to divide by 10?
02:03 AM rue_bed: how many bits?
02:03 AM rue_bed: 8?
02:04 AM rue_bed: o = 0;
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#1
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#2
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#3
02:04 AM rue_bed: o += i; // Add dividend to accumulator (dividend /8.000000)
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#4
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#5
02:04 AM rue_bed: o -= i; // Subtract dividend from accumulator (dividend /32.000000)
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#6
02:04 AM rue_bed: i >>= 1; // Shift dividend right. Shift#7
02:04 AM rue_bed: o += i; // Add dividend to accumulator (dividend /128.000000)
02:04 AM rue_bed: Final error: 0.001562 would require 1/640.000000 th of dividend to be added to accumulator
02:04 AM rue_bed: I think that works
02:04 AM rue_bed: i is input, o is output
02:15 AM timemage: hopefully i didn't break this when i reformulated it, but unsigned char div_0_to_127_by_10(unsigned char n) {return ((n >> 1) * 0x34u) >> 8;} i made that as a limited divide by 10 just playing around after the conversation.
02:17 AM timemage: https://pastebin.com/3iMadGrz in case you're wondering what it works out to in assembly.
02:21 AM timemage: it doesn't seem to be a hell of a lot different or better than what gcc is generating for something like: volatile unsigned char x, y; y = x / 10; though.
02:25 AM rue_bed: but...
02:25 AM rue_bed: ^^
02:26 AM rue_bed: 7 shifts and 3 adds
02:29 AM timemage: rue_bed, do it and see what happen i guess.
02:39 AM timemage: rue_bed, if i put 100 in i get 9 out. it's more approximate than i'd've guessed.
03:21 AM xentrac: rue_bed: I think it's about 50 cycles to divide a 16-bit int by a 16-bit non-constant int
03:21 AM xentrac: but gcc is pretty good about optimizing division by constants in general
03:38 AM xentrac: hmm, not in this case apparently
03:38 AM xentrac: my inner_itoa function is static int inner_itoa(int n, char *d, char rv) {*d++ = '0' + n % 10; n /= 10; return n ? inner_itoa(n, d, rv + 1) : rv + 1;}
03:39 AM xentrac: The code I get as a result with avr-gcc -g -c -mmcu=atmega328p -O5 -Wa,-adlhns=div10.lst div10.c is
03:39 AM xentrac: 82 000a FB01 movw r30,r22
03:39 AM xentrac: 83 000c 3196 adiw r30,1
03:39 AM xentrac: 84 000e 6AE0 ldi r22,lo8(10)
03:39 AM xentrac: 85 0010 70E0 ldi r23,0
03:39 AM xentrac: 86 0012 0E94 0000 call __divmodhi4
03:40 AM xentrac: (I should probably have called it utoa)
03:43 AM xentrac: by contrast, what I get on amd64 is
03:43 AM xentrac: 21 0002 41BB6766 movl $1717986919, %r11d
03:43 AM xentrac: 21 6666
03:43 AM xentrac: 23 0008 4189D1 movl %edx, %r9d
03:43 AM xentrac: 25 000b 41F7EB imull %r11d
03:43 AM xentrac: oh, I guess before that there is 20 0000 89F8 movl %edi, %eax
03:44 AM xentrac: this multiplying by the multiplicative inverse of 10 is a win on amd64 but I think it would probably be a much bigger win on avr
03:46 AM xentrac: oh, and I guess this part is kind of important:
03:46 AM xentrac: 28 0011 41C1FA1F sarl $31, %r10d
03:46 AM xentrac: 29 0015 C1FA02 sarl $2, %edx
03:50 AM xentrac: you can easily verify that x * 0x66666667 >> 34 is x floor-divided by 10 for at least for positive numbers up to a few million
03:52 AM xentrac: x * 0x6667 >> 18 fails when x == 43699, where it gives 4370 as a result instead
04:18 AM BongoShaftsbury: can someone tell me about this .lss file type?
04:26 AM crazy_pete: http://filext.com/file-extension/LSS
04:27 AM BongoShaftsbury: it's a spreadsheet?
04:35 AM BongoShaftsbury: what about .obj?
04:55 AM crazy_pete: obj files are assembled files BongoShaftsbury. They are assembler or high level language code that has gone through the compiler and the assembler (usually one step on modern systems) to generate binary code
04:55 AM crazy_pete: then at linking stage on or more obj files are linked together to produce an executable
04:58 AM BongoShaftsbury: thanks
09:38 AM CORDIC: Emil: XMEGA has a SFRs for `|=', `&=' and `^='.
09:40 AM Emil: CORDIC: hm?
09:40 AM Emil: CORDIC: oh you mean it can single cycle or and and xor?
09:40 AM Emil: that's pretty nice
09:42 AM CORDIC: Yes. You talked about it at 2017-05-12T04:00.
09:42 AM Emil: if only it also had >>= and <<=
09:42 AM Emil: CORDIC: heh, you are catching up on backlog ;)
09:43 AM polprog: backloggint to 12th may?
09:43 AM Emil: not even surprising
09:51 AM CORDIC: s/05-12/05-21/
09:51 AM CORDIC: ``PINn = mask'' is equivalent to ``PORTn ^= mask'' for mega and tiny family. Errata section of datasheet should have the date when it was introduced (few years ago).
09:52 AM Emil: ah
09:52 AM Emil: CORDIC: not all!
09:52 AM Emil: CORDIC: only some have the PINn=mask function
09:52 AM Emil: CORDIC: also it is more than "a few years ago"
09:52 AM CORDIC: I don't think You can easily find such an old part.
02:49 PM Emil: Damn
02:49 PM Emil: m328u4 had exactly the pins required for driving an eink display :D
02:49 PM Emil: wat
02:49 PM Emil: m328pb*
02:49 PM Emil: No pin left over
02:50 PM Emil: Hmm, I wonder how could I add an spi memory
02:50 PM bss36504: Does the display have an enable pin of some sort?
02:51 PM Emil: Moving the data bus to a spi serial to parallel ic slows shit down considerably
02:51 PM Emil: bss36504: yap
02:52 PM Emil: https://emil.fi/jako/kuvat/2017-05-25_22-21-45_zyaIP5Kj.png
02:52 PM Emil: It'll be fucking splendid drawing to an 800x600 eink display with an m328pb :"D"
02:56 PM polprog: you could use a buffer of some sort...
02:56 PM polprog: just thinking loud
02:57 PM bss36504: Well if there's an enable, seems like you could just connect a SPI memory to the bus and it shouldnt interfere with the display, no?
02:57 PM polprog: how much was that eink BTW?
03:00 PM kre10s: There's bound to be pins on an eink you don't need to use as often. you could place those on an expander.
03:01 PM Emil: bss36504: can't if there's no pins :D
03:01 PM Emil: kre10s: but maaaaam, I don't want tooo
03:02 PM Emil: Eh, it's fine
03:03 PM kre10s: an i2c exander requires only two pins. so if you have 3+ ios you can place on an expander you already gain some.
03:03 PM Emil: I don't :D
03:03 PM kre10s: what model eink?
03:03 PM Emil: Well, I could actually not have the isp header which would release 3 pins
03:04 PM Emil: and use the serial bootloader only
03:04 PM Emil: though I would still need to get the bootloader there first
03:04 PM Emil: kre10s: ED060SC4
03:04 PM kre10s: you can multipurpose the isp pins... the display might flicker when you program though...
03:06 PM kre10s: some avrs can even disable the reset pin and use it as an i/o with pullup.
03:06 PM Emil: I know, but I do not want to remove reset .D
03:07 PM Emil: Hmm, I could multiplex the digital pins, though
03:07 PM Emil: D0-D7
03:07 PM Emil: and use them as chip select
03:07 PM Emil: yeah that'll work
03:08 PM Emil: since if I don't clock anything out while doing that nothing happens at the chip
03:08 PM Emil: Yeah that would allow me to have a spi memory chip
03:08 PM kre10s: the ED060SC apears to have LE what does that do?
03:08 PM Emil: Latch enable iirc
03:09 PM kre10s: so if LE is HIGH then no data is shifted into the display?
03:09 PM Emil: I have to look at the code to find out
03:11 PM kre10s: if so... use a not gate to select another chip. when LE is high=> using memory chip. when LE is low=> using display.
03:12 PM Emil: hmm
03:12 PM Emil: not a bad idea
03:15 PM Emil: Hmm, I could hold a single full 800x600 image in a 1Mb flash chip
03:17 PM kre10s: apparently LE is active high. so really. you can do anything you want with D0-D7 and even CL as long as you make sure to clock out all the pixles before you LE^
03:18 PM Emil: What if I just changed to a bigger part :D
03:20 PM kre10s: :)
03:21 PM kre10s: what are you doing with the display anyway? maybe you want a bigger chip just for processing the img you want to display.
03:23 PM Emil: I have an eink display
03:23 PM Emil: just want to make use of it
03:23 PM Emil: also for a sikrit projekt
03:24 PM Emil: I need a low power display for it
03:25 PM kre10s: o_O secret you say...
03:27 PM kre10s: just to hold one image in mem you will need 60K bytes of ram. The only way you can get an image like that throgh a small chip would be in chunks.
03:29 PM Emil: I know
03:29 PM Emil: That's why I'll probably not have that
03:29 PM Emil: even if I might be able to stream the image
03:30 PM Emil: Well, actually streaming a image is a possibility
03:31 PM kre10s: as long as you don't touch CL while you repurpose D0-7
03:32 PM Emil: No I mean
03:32 PM Emil: I could stream the image through serial directly
03:32 PM Emil: Though it takes a minimum of 0.6 seconds to send a single one and that doesn't take into account anything but streaming
03:33 PM Emil: realistically Updating it like that could be achieved in ~5 seconds perhaps
03:34 PM kre10s: if your image is on a memory chip that has parallel out you could shovel it across directly in 8 bit chunks.
03:34 PM Emil: Heh
03:34 PM Emil: Imma fucking do it with the m328pb
03:34 PM Emil: I have no extra pins
03:34 PM Emil: It'll be a purely serial display
03:36 PM kre10s: oh. so your data comes from elsewhere...
03:53 PM JanC_ is now known as JanC
03:56 PM Emil: kre10s: yeah
04:45 PM xentrac: Emil: you could stream it in from, say, an SD card
05:26 PM kre10s: 450nA/channel opanp... jut awesome
05:33 PM Emil: hm?
05:38 PM kre10s: opamp that has an Iq of <450nA really low power!
05:40 PM Emil: ah
05:40 PM kre10s: or the TLV3691. a 75nA comparator!