#avr Logs

Dec 13 2017

#avr Calendar

01:04 AM rue_mohr: anyone ever written fn's or macros to prevent addition and subtraction operations from rolling over?
01:07 AM Casper: probably not the most efficient way, but yes
01:07 AM rue_mohr: ? can you show?
01:07 AM rue_mohr: satAdd(this, that, llim, ulim) ...
01:07 AM Casper: it's somewhere in one of my code, forgot which one
01:12 AM Casper: for overflow there is the cary flag
01:12 AM Casper: not sure for under
01:12 AM rue_mohr: yea, a borrow for underflow
01:12 AM Casper: I'm still trying to remember what code I did it...
01:12 AM Casper: I did a few of those small values ones, so it was quite easy... but I remember having done one with a full 8/8 bits unsigned
01:12 AM Casper: I know it worked, can't remember which one it was...
01:12 AM Casper: it's one of the so many incomplete projects...
01:14 AM rue_mohr: http://paste.debian.net/1000492/
01:14 AM rue_mohr: ...
01:14 AM rue_mohr: when you cant actaully do the math because of the problem created by doing the math
01:15 AM rue_mohr: if I know i"m doing this in 8 bits, I should prolly make a fn that just does it in 16 and bla
01:16 AM rue_mohr: its gonna take less if's
01:18 AM rue_mohr: limited16BitAdd( int this, int that, int ulim, int llim) {
01:18 AM rue_mohr: long a, b, c;
01:18 AM rue_mohr:
01:18 AM rue_mohr: a = this; b = that;
01:18 AM rue_mohr: c = a+b;
01:18 AM rue_mohr: return limit(c, llim, ulim);
01:19 AM rue_mohr: }
01:19 AM rue_mohr: ugh
01:19 AM rue_mohr: ugly
01:19 AM rue_mohr: dont trust (long)
01:22 AM rue_mohr: ok wait, if I use 16 bits, and the adc is only 10, I have the overflow room I need
01:22 AM rue_mohr: so...
01:35 AM Casper: so use signed
01:35 AM Thrashbarg: *grumble*
01:36 AM Casper: and how to solder banana jack to a wire the easy way: use a turbo mapp torch, the kind used for brazing :D
01:36 AM Thrashbarg: >_>
01:36 AM Casper: let's talk about overkill, but hey, it did it quickly and easilly
01:36 AM rue_mohr: yea, this is that
01:39 AM rue_mohr: I think a 2ms response is the best I'm going to get from a 1kR + 1uF cap
01:44 AM rue_mohr: 500R and 0.5uF is faster
02:54 AM nuxil: mornings.
02:55 AM nuxil: what ya doing rue_mohr ? messing with the adc ?
03:05 AM nuxil: why change R? 500 and 0.5 is none standar values. just change C to 0.22 :p
03:05 AM nuxil: 220nf
03:11 AM nuxil: my fault. 2ms/ not 200ish Us :p.. a 2uf needed then :p
03:12 AM nuxil: if (this == wrong) use(that)
03:19 AM nuxil: i need more coffee
03:20 AM nuxil: im not awake yet i see
04:44 AM nuxil: so my 5buck logic analyzer arrivied today from china :p
04:45 AM nuxil: now my question is. what software do i use to get it working.
05:08 AM daey: nuxil: the saleae clones? simply use the saleae software
05:08 AM daey: those things get quite warm btw.
05:10 AM LeoNerd: You -could- run the saleae software but it's kinda terrible
05:10 AM LeoNerd: I use sigrok
05:13 AM nuxil: alright.thanks
05:13 AM nuxil: daey, yea its a saleae clone
05:14 AM nuxil: by the looks of it.. 8ch 24MHz
05:14 AM LeoNerd: Hah.. "24MHz"
05:14 AM LeoNerd: Good luck with that
05:14 AM LeoNerd: I can sustain 8Ms/sec on mine and do little bursts of 12
05:18 AM nuxil: LeoNerd, are you on linux or using the windows build?
05:18 AM LeoNerd: Linux
06:11 AM daey: LeoNerd: "the rate was too fast, device could not keep up" :P
06:12 AM daey: isnt sigrok 10x worse than saleae? at least that seems to be the public opinion when i last checked it
06:13 AM LeoNerd: By what metric?
06:13 AM LeoNerd: The Saleae software can do things like decoding SPI pulses into hex numbers
06:13 AM LeoNerd: Sigrok can tell me what named bit flags of which named registers in my chip that means I am writing to
06:14 AM LeoNerd: I don't know *anything* else that comes close to knowing this
06:18 AM nuxil: o.O nice.
06:22 AM nuxil: but doesnt sigrok supports plugin so makeing someting that shows the address/hex number of i2c /spi or whatever rather simple ?
06:22 AM nuxil: "simple" with a "pinch of salt"
06:41 AM daey: LeoNerd: hm. i havent tried it myself tbh. i didnt even bother after reading all the negative comments. i will give it a try
06:42 AM daey: i think most of it may have been from a post about a chinese fpga based logic logger which used a forked version of sigrok iirc.
08:36 AM jippo: Hi, I'm getting an error: "initializer element is not constant" when trying to create a static struct within an ISR. Here's the code: https://gist.github.com/anonymous/ac053088cf759b8ca5ca9fa0895469ea. I had a look around and it seems the error usually comes up because you use variables to define the static, but I've defined mine with the preprocessor
08:54 AM cehteh: dont use leading underscores for macros
08:54 AM cehteh: those are implementation reserved
08:55 AM cehteh: commonly only uppercase macro names, maybe use trailing underscores
09:21 AM jippo: cehteh: I wasn't sure about that, thanks for clearing it up.
09:22 AM jippo: what about macro functions like, _toRadians(deg)?
09:22 AM jippo: Should that be TORADIANS?
09:22 AM cehteh: do you define those?
09:24 AM jippo: yep. I've created _toRadians: #define _toRadians(deg) (deg * (M_PI / 180.0))
09:31 AM cehteh: macro is macro, no matter how its defined
09:31 AM cehteh: prolly it works anyway, but the C makes some reservations for some global/names
09:33 AM cehteh: about your bug above .. do you compile with --std=c11 or c99 and -Wall -Wextra?
11:21 AM Jartza: evening
11:29 AM gnom: https://youtu.be/9P1UJatH5jM?list=PLBPoTwsQYxSCc9C95p2RGuT-JulNEhsfH
11:31 AM gnom: http://www.lofibucket.com/articles/oscilloscope_quake.html
11:31 AM hetii: hi
11:34 AM gnom: hi
11:44 AM polprog: "use vga as dac"
11:44 AM polprog: well, imo if you are not after the wobbly and sketch effect, you can just make a vga to XYZ converter and use a scope as a crt
11:45 AM * polprog would give a lot to have a teeny tiny green CRT on his desk as a terminal
12:07 PM rue_mohr: 3/4"?
12:07 PM rue_mohr: er 3.4"?
12:07 PM rue_mohr: jippo,
12:07 PM rue_mohr: #define rad2deg(K) ((K)*(180.0/3.1415926535))
12:07 PM rue_mohr: #define deg2rad(K) ((K)*(3.1415926535/180.0))
12:08 PM rue_mohr: #define mm2inch(K) (K/25.4)
12:08 PM rue_mohr: #define inch2mm(K) (K*25.4)
12:08 PM rue_mohr: #define Min(X,Y) ((X) < (Y) ? (X) : (Y))
12:08 PM rue_mohr: #define Max(X,Y) ((X) > (Y) ? (X) : (Y))
12:09 PM rue_mohr: #define IsHigh(BIT,BYTE) ((BYTE & (1<<BIT)) != 0)
12:09 PM rue_mohr: #define IsLow(BIT,BYTE) ((BYTE & (1<<BIT)) == 0)
12:09 PM rue_mohr: #define SetBit(BIT,BYTE) BYTE |= (1<<BIT)
12:09 PM rue_mohr: #define ClearBit(BIT,BYTE) BYTE &= ~(1<<BIT)
12:09 PM rue_mohr: #define ABS(a) ((a) < 0 ? ((a)*(-1.0)) : (a))
12:09 PM rue_mohr: #define SIGN(x) ((x)==0?0:(x)>0?1:-1)
12:09 PM polprog: multipayer notepad!
12:09 PM rue_mohr: #define SQR(x) ((x)*(x))
12:09 PM rue_mohr: those are all the usualy common ones anyhow
12:14 PM Emil: rue_mohr: pls
12:14 PM Emil: use a paste service
12:14 PM polprog: nah, it'ok
12:14 PM polprog: those are pretty useful
12:14 PM polprog: ill save those for reference
12:14 PM Emil: polprog: yes, but with a paste service
12:15 PM Emil: instead of channel flood
12:15 PM Emil: also aren't setbit, clearbit and so on already given from the standard libs?
12:16 PM rue_mohr: if the channled is dead its ok to post content generally usefull to anyonw
12:17 PM rue_mohr: Emil, cant be, nobody uses them
12:17 PM Emil: rue_mohr: pbullshit
12:17 PM Emil: a) channel is not dead
12:17 PM rue_mohr: everyone crafts junk their own way, and makes the code unreadable
12:17 PM Emil: there is bit_is_clear at least
12:17 PM Emil: from the standard libs
12:17 PM Emil: and yeah bit_is_set also
12:18 PM rue_mohr: :) I wrote those macros before the standard libs were standard
12:18 PM Emil: from io.h
12:18 PM Emil: Doubtful
12:18 PM Emil: unless you wrote them for something else than avrs ;)
12:18 PM Emil: in which case sure
12:21 PM Emil: Oh yeah the sbi and cbi macros are no longer supported
12:22 PM Emil: http://www.nongnu.org/avr-libc/user-manual/group__avr__sfr.html
12:22 PM rue_mohr: I wont go back to 2002 and see if there was a macro or not
12:23 PM Emil: The don't make wild claims ;)
12:23 PM rue_mohr: its true and I dont care if you beleive me
12:23 PM Emil: lulz
12:23 PM rue_mohr: but I use those in more than just avr code
12:23 PM Emil: Yeah that's good, and they are good macros
12:23 PM rue_mohr: I use those in bitfield code on a PC
12:24 PM Emil: But with bitfields you can just set to 1 or 0
12:24 PM Emil: or just if(value)
12:24 PM rue_mohr: maybe you want to tell me there is a SQR() function in a standard C library that is data type independent?
12:24 PM Emil: since the compiler is guaranteed to generate the appropriate code
12:24 PM Emil: rue_mohr: chillax :D
12:25 PM rue_mohr: or abs, wtf is with fixed data types for abs?
12:25 PM Emil: C has limitations, I agree
12:25 PM Emil: you'd probably like C++
12:25 PM Emil: or a subset of it
12:25 PM rue_mohr: nope
12:25 PM rue_mohr: its easy to create a sqr and abs macro
12:26 PM Emil: true, true
12:26 PM Emil: but C++ allows you to not have to use a macro but get the same perf
12:26 PM rue_mohr: its just a mystery why its not standard
12:27 PM Emil: also
12:27 PM Emil: umm
12:27 PM Emil: that macro, SQR(x)
12:27 PM Emil: you don't need a macro for it
12:27 PM rue_mohr: yes, sadly you do
12:27 PM Emil: well, true
12:28 PM Emil: it's more readable
12:28 PM rue_mohr: esp when X is complex
12:28 PM rue_mohr: like ((a-b)+(c-d))
12:28 PM Emil: I've always wondered why people didn't just better C
12:28 PM Emil: Would be way nicer
12:29 PM rue_mohr: char and int shoud not exist
12:29 PM rue_mohr: there is no point in arbitrary size data types
12:29 PM rue_mohr: uint8_t
12:30 PM rue_mohr: as stupid a name it is, its specific
12:31 PM rue_mohr: I might agree that floating points could be arbitrary, but even that sounds dangerous, as you dont know what your numberical resolution really is
12:45 PM Jartza: well. people "bettered" C and made C++ ;)
12:46 PM rue_mohr: sorry c++ was a prank people were supposed to laugh at and never actaully use
12:46 PM rue_mohr: designed to cause so many problems that nobody in their right mind would try to actually make anything form it
12:46 PM Casper: don't make anything that someone else might not take as a prank...
12:46 PM rue_mohr: but, alas, people.
12:46 PM Casper: like that brainfuck language
12:47 PM rue_mohr: yup, bf is badass
12:51 PM rue_mohr: so, if a new type of integer data type were created in c, called zim, and the size was a complete secret, and different on every platform, people would just use it anyhow?
12:52 PM Jan-: hihi avr people :)
12:52 PM rue_mohr: zim i, j, k;
12:52 PM rue_mohr: on one system it might be 4 bits, on another it might be 64
12:53 PM Jan-: so, we're switching an arduino board around from using its onboard timing to using a TCXO
12:53 PM rue_mohr: cause, char and int are like this right now anyhow
12:53 PM Jan-: it's been suggested that we don't absolutely need to change the fuse bits in the AVR so that it expects a 5V clock signal, that we can leave it set up to use the normal crystal.
12:53 PM rue_mohr: jan how do you mean onboard timing?
12:53 PM Jan-: Is that true, and if so, which pin do we connect the TCXO to, and what do we do with the other pin?
12:54 PM rue_mohr: if you use the input pin, you can just shove in a ttl clock signal
12:54 PM rue_mohr: crstal set is an input and output
12:54 PM Jan-: which of the two clock pins is the input?
12:54 PM rue_mohr: datasheet has example of clock injection
12:54 PM Jan-: it has two XTAL pins, anyway
12:54 PM rue_mohr: clocking options
12:55 PM rue_mohr: is that what you meant?
12:55 PM Jan-: people have said that we can, in practice, leave it in crystal mode.
12:55 PM Jan-: apparently that's likely to work, as opposed to telling it to expect a 5V clock
12:55 PM Jan-: I'm trying to confirm if that's true
12:55 PM rue_mohr: XTAL1 is input
12:55 PM Jan-: OK
12:55 PM rue_mohr: on the m328
12:56 PM Jan-: OK.
12:56 PM Jan-: What would we do with the other pin.
12:56 PM rue_mohr: the oscillators are basically just a CMOS inverter with some resistor/capacitors
12:56 PM rue_mohr: nothing
12:56 PM rue_mohr: its an output
12:57 PM Jan-: Can we leave it connected to the little network of crystal and capacitors on the board
12:57 PM Jan-: to avoid cutting another track?
12:57 PM rue_mohr: no, you dont want the old crystal still conencted
12:57 PM Jan-: Obviously we have to disconnect from XTAL1. But what about XTAL2?
12:57 PM rue_mohr: it would be sitting there trying to resonate off-tune
12:58 PM rue_mohr: or just pull the crystal
12:58 PM rue_mohr: its not nice to leave it connected, it'll eb trying to resonate
12:59 PM Jan-: the thing is, it's a tiny surface mount crystal and if we pull it off, we'll never be able to reattach it
12:59 PM Jan-: so I guess we'll just cut both tracks
12:59 PM rue_mohr: huh k
12:59 PM Jan-: I wasn't proposing leaving it connected to both pins.
12:59 PM rue_mohr: no
12:59 PM Jan-: But if we only need XTAL1 to connect to the TCXO....
01:00 PM rue_mohr: the output will be a copy of that input
01:00 PM Jan-: hmm
01:00 PM rue_mohr: and the cap on the other side of the crystal creates a ground path
01:00 PM Jan-: ok.
01:00 PM rue_mohr: leaving the crystal shaking at not-its-freq
01:00 PM Jan-: we'll isolate it entirely I guess.
01:00 PM * Jan- has no idea how crystals work
01:00 PM * Jan- considers it witchcraft
01:01 PM rue_mohr: a crystal is a bell
01:01 PM rue_mohr: you tap it and it rings
01:01 PM rue_mohr: the trick is to take that ringing and feed it back to keep is ringing
01:02 PM rue_mohr: ever held a tuning fork infront of a loud speaker playing music
01:03 PM rue_mohr: its a great conversation starter at parties....
01:04 PM * Jan- wonders about the sort of parties rue_mohr goes to :)
01:06 PM Emil: Jan-: if your txco is an oscillator, don't leave it in crystal mode
01:06 PM Emil: if it's a crystal that's just temperature compensated then leave it in crystal mode
01:07 PM Jan-: It's designed, as far as I know, to produce a 5V square wave.
01:07 PM * nuxil smells burnt fuses
01:07 PM Jan-: People said we'd be OK to leave it in crystal mode, which seemed to reduce the chances for SNAFUs.
01:07 PM Jan-: but OK, if that's not the case, great.
01:08 PM Jan-: people have told us various things
01:11 PM Jan-: I'm a bit concerned that the second we tell it to stop using the crystal oscillator it'll stop working.
01:11 PM Jan-: Then if we switch out the crystal for the TCXO, and it doesn't work, we'll be screwed.
01:11 PM nuxil: unless you got a high voltage programer
01:12 PM Casper: afaik, the crystal mode just enable the clock out to drive the crystal
01:13 PM Casper: and all it do is waste a bit of power, and may introduce a slight extra noise on the ADC since there is more switching that occur
01:14 PM Jan-: mm.
01:14 PM Jan-: that was why people said just leave it in crystal mode, as far as I know
01:14 PM Jan-: then if we switch it back to the crystal it'll just work.
01:19 PM Aleks_ is now known as Aleks
01:21 PM Casper: there is always a way to recover, but it's a pain if it is a production run...
01:28 PM Jan-: Well this is a one off
01:28 PM Jan-: I just don't want to ruin a nice little arduino board
01:29 PM Casper: whatever you use, add provision for the other
01:29 PM Casper: if it is a one run, and you change later on, you can always recover with an external clock, like an avr in "insane led flashing demo"
01:30 PM Jan-: I'm just not that convinced any of this is going to work
01:32 PM * Jan- looks a bit worried
01:47 PM nuxil: yea. be glad your not a byte worried :p
01:50 PM nuxil: a avr with a flashing led flashing is a bit overkill isnt it ? :p . a schmitt trigger osc will do it aswell :)
01:51 PM nuxil: as simple as this http://electronics-course.com/image/schmitt-trigger-osc.png
01:54 PM nuxil: hell it dosent even need to be a shmitt trigger. many logical chips like nand etc have internal shmitt triggers.
01:58 PM Casper: most do not have those chips
01:58 PM Casper: but does have an extra avr around
01:59 PM nuxil: note. must be a "inverted" shmitt trigger or a inverter/nand etc,
01:59 PM nuxil: Casper, woot ?
01:59 PM nuxil: dont you have a shmitt trigger laying around + 1 resistor + 1 cap :p
02:01 PM nuxil: i thought everyone who do digital circuits had the basic logical building blocks laying around. :p
02:05 PM Casper: logic gates are a thing of the past now
02:05 PM nuxil: ppff :p
02:05 PM nuxil: dont make me feel old :p
02:06 PM nuxil: but hey. either way will work as a clock signal. avr. smhitt trigger osc. your func gen whatever :p
02:11 PM Casper: sound card? :D
02:11 PM nuxil: :D
02:11 PM Casper: would be slow, but could work
02:12 PM nuxil: yea. there are function gen apps that suppose to gen squar/saw/triangle/sinus waves.
03:52 PM rue_mohr: you can use a 555 too,
03:52 PM rue_mohr: put a resistor from output to (2,6) and a cap from 1 to 2
03:52 PM rue_mohr: done
03:52 PM rue_mohr: resistor 3-2 jumper 2-6 capacitor 1-2
03:53 PM rue_mohr: but the 74xx14 is available in a 6 pin tsop
03:53 PM rue_mohr: as a 1G
03:54 PM rue_mohr: you can also do a flashing led with
03:54 PM rue_mohr: connect .. I cant do this in my head, pn2222, 1 cap, 1 resistor, 1 led
04:07 PM gregor2: Hi
04:07 PM gregor2: its me
04:08 PM Emil: Hi
04:08 PM gregor2: I am the guy who thought he had bricked his ATmega328p
04:08 PM gregor2: Remember me?
04:08 PM Emil: yes and no
04:08 PM Emil: what's your question?
04:08 PM gregor2: I have no question.
04:09 PM Emil: Okay
04:09 PM Emil: Well, welcome back
04:09 PM gregor2: But now i really bricked something
04:09 PM nuxil: 100% sure this time ?
04:09 PM gregor2: I guess
04:09 PM gregor2: Its a motor encoder
04:10 PM gregor2: I accidentally pluged the Voltage the wrong way around/
04:10 PM gregor2: And something smelled burned.
04:10 PM nuxil: thats normal when you do that :)
04:11 PM gregor2: Its so easy to break something.
04:11 PM gregor2: I think once i did that to a ATMega328p.
04:11 PM gregor2: but its still working.
04:12 PM nuxil: i put my atiny85 the wrong way in my dip socket many many times.
04:12 PM nuxil: lol
04:12 PM Emil: gregor2: yes, avrs a resilient as fuck
04:12 PM nuxil: but i always got it out in time
04:12 PM gregor2: I time?
04:12 PM Emil: in time
04:12 PM Emil: yes
04:12 PM gregor2: So if you did that to long it would go up in smoke?
04:13 PM Emil: might
04:13 PM Emil: might not
04:13 PM Emil: probably yes
04:13 PM nuxil: mostlikely yes
04:13 PM Emil: At least it degrades the perf
04:13 PM gregor2: Yould have to look at the pins.
04:13 PM gregor2: I guess
04:13 PM gregor2: the periferals?
04:14 PM gregor2: Could it be, that only some parts of the mcu break?
04:15 PM nuxil: yes.. well . i killed pb4 on one of my atiny85. all the other pins works fine.
04:15 PM gregor2: So my mcu could be broken without me even knowing?
04:17 PM Emil: unlikely but yes
04:17 PM Emil: Now imagine
04:17 PM nuxil: problem is. your code might run fine until it suppoese to do something like read a pin. change a register value etc.
04:17 PM Emil: gregor2: now imagine this
04:18 PM Emil: how many transistors there are in a cpu?
04:18 PM Emil: or an mcu?
04:18 PM Emil: And now imagine that all of them have to work
04:18 PM Emil: isn't the concept terrifying? :D
04:20 PM nuxil: gregor2, so if you got a broken mcu that seems to be working it can drive you crazy.. not knowing if the bug is hw or sw :p
04:21 PM gregor2: I guess
04:21 PM gregor2: A good idea would be to write a Test programm/
04:22 PM gregor2: Which tests all the functions.
04:23 PM nuxil: Emil, most cpu/gpu's todat have "redundancy transistors" :)
04:23 PM nuxil: *tpday
04:23 PM nuxil: arg
04:23 PM nuxil: cant type
04:29 PM nuxil: gregor2, add a diode to your Vcc :p
04:29 PM nuxil: so you dont do this anymore :)
04:30 PM nuxil: v+ or whatever u call it
04:51 PM gregor2: thats so stupid!
04:52 PM gregor2: I could as well forget to put the diode in place.
06:56 PM rue_mohr: just put a 330R in series with each pin of your avr and you will be prttymuch protected from most stupid things
06:57 PM LeoNerd: You underestimate stupidity ;)
07:05 PM Emil: 200 ohms is plenty enough
07:05 PM Emil: I'd actually just use 100 ohms myself
07:05 PM Emil: a nice round number
07:06 PM LeoNerd: 200ohms means 5V can push at most 25mA; which is about what an AVR GPIO pin is happy with
07:06 PM LeoNerd: 100ohms means 5V could push 50mA, which is a bit much
07:07 PM LeoNerd: Ofcourse, if you've got 12V on your board like I often have, then even 330R may not save you
07:09 PM rue_mohr: yea, if you inject 12V into a pin, its probably done
07:09 PM rue_mohr: + for PICs tho, you can run them on 12V for a few seconds and their ok
07:09 PM rue_mohr: avrs = DEAD
07:10 PM LeoNerd: That's the point of the resistor. Put 12V in a GPIO pin via a 1k resistor and at most you're pushing 12mA to ground
07:11 PM Emil: rue_mohr: well, if it's 12V and you idle at 5V, it's only (12-5)/330 ;)
07:11 PM LeoNerd: If the GPIO pin isn't driven to ground but is floating, then that current flows out the highside ESD diode to the Vcc (5V?) line, so the 1k resistor has to drop 7V... 7mA
07:11 PM LeoNerd: The ESD diode will quite happily sink 7mA
07:11 PM Emil: LeoNerd: it won't go through the ESD-diode anyways
07:11 PM Emil: unless you are in high impedance state
07:11 PM Emil: in which case it does
07:12 PM LeoNerd: <LeoNerd> If the GPIO pin isn't driven to ground but is floating
07:12 PM Emil: sorry
07:12 PM Emil: missed that
07:12 PM LeoNerd: ;)
08:37 PM -!- #avr mode set to +o by card.freenode.net
09:09 PM Tom_itx is now known as Tom_L
11:10 PM day__ is now known as daey