#avr Logs

Jun 12 2020

#avr Calendar

10:34 AM PublicWiFi is now known as MaccasWiFi
10:40 AM MaccasWiFi is now known as pfsense
03:12 PM teus: hi. im trying to figure out how many hardware interrupts the lineup of AVR chips have
03:15 PM teus: some chips allow every digital pin to be used like an interrupt pin
03:18 PM teus: its all pretty fussy to look up
03:19 PM vmt: well... what's the requirement?
03:22 PM teus: read a rotary encoder
03:22 PM teus: seems simple but its given me giant headaches and bursts of anger
03:24 PM teus: found a library of someone complaining about how most code for this sucks, and his library works with either polling or interrupts. so i would need 2 interrupts
03:25 PM vmt: what's the problem exactly wrt interrupts?
03:25 PM teus: its hard to figure out how many interrupt pins are available
03:26 PM teus: or what the difference is between the interrupts you configure in software
03:47 PM cehteh: hey teus :D
03:49 PM cehteh: teus: there are basically 2 kinds of interrupts: INT which can trigger only on one edge but can wake up from deeper sleep, often tied to 2 pins only
03:50 PM LeoNerd: All pins Px2 and Px6 on AVR 1-series chips
03:50 PM cehteh: and pinchange which can be arbitiarly configured on almost all pins (depends on the actual mcu you use, see datasheet)
03:51 PM cehteh: yeah and the new -0 and -1 series are all different
03:51 PM LeoNerd: Nicer :)
03:52 PM LeoNerd: Well, all except the t1616 package size.. tiiiiny and a right pain to solder
03:52 PM teus: hi cehteh
03:53 PM teus: ok let me look that up
03:54 PM teus: im working with an attiny85 in a headphone amplifier, because it can be easily swapped on the devices i ship out
03:55 PM cehteh: battery operated?
03:55 PM teus: no
03:55 PM cehteh: then you can use pinchange on any pin
03:56 PM cehteh: you already made the firmware or just in planning?
03:56 PM teus: i already have it working with polling
03:56 PM teus: but when i turn the rotary encoder a bit more quickly, it can't keep up
03:56 PM cehteh: oops
03:57 PM cehteh: shouldnt happen even with polling :D unless you have a really fine notched encoder
03:57 PM teus: the library supports interrupts too, i believe i still need to add the flags for the attiny85
03:58 PM cehteh: and dont forget about proper debouncing, encoders like to bounce like shit
03:58 PM teus: with one encoder it didnt bounce at all
03:59 PM teus: but yeah the pcb has provision for it anyway
03:59 PM teus: https://www.dropbox.com/s/6wysiu04s4t0d83/2020-05-20%2023.49.15.jpg?dl=0
04:00 PM cehteh: zoom in
04:00 PM cehteh: and depends what encoders are that are
04:00 PM cehteh: optomechanical? sliding contacts?
04:01 PM teus: just a knob
04:01 PM teus: but okay, sounds good then. now im wiring everything on perfboard and long cables to the avr
04:02 PM teus: with the new pcb made it'll be properly wired, so i'll check with a better scope for bouncing
04:04 PM cehteh: better look at the datasheet of the encoder
04:04 PM cehteh: usually they specify bounce time
04:05 PM cehteh: which also limits the speed how fast you can operate it
04:05 PM teus: mmh right
04:06 PM cehteh: and on another note: some cheaper encoders have surprisingly much wear and are specified for little 'operation'
04:06 PM teus: hah
04:06 PM teus: my enclosure only allows for a height of 10mm
04:06 PM teus: i hardly have any choice
04:07 PM cehteh: usually its fine, you just need to be aware of that
04:07 PM teus: alright
04:07 PM teus: thanks :)
04:07 PM cehteh: esp when its human operated it should be ok
04:07 PM teus: oh, yeah, totally
04:07 PM teus: are you into headphones?
04:08 PM cehteh: recently someone came up with a cheap encoder and it was rated for 50000 turns or so
04:08 PM cehteh: and wanted to drive that from a robot wheel
04:08 PM cehteh: prolly a bad idea :)
04:08 PM teus: yeah
04:09 PM cehteh: i am not much into headphones except being a user :)
04:10 PM teus: alright. i sent nebuk a prototype this week
04:11 PM cehteh: huh do you work together on that?
04:11 PM teus: he's testing it for me
04:11 PM cehteh: ah
04:11 PM teus: need opinions about it. he says it can be commercialized
04:12 PM vmt: who's nebuk
04:12 PM cehteh: when i visit him i may take a look at it :D
04:12 PM teus: kraut who lives in the same area as cehteh
04:12 PM cehteh: friend of ours :D ... lives in the same town as me
04:12 PM vmt: mmm. kraut.
04:12 PM cehteh: german
04:12 PM vmt: yes, i figured
04:13 PM teus: there's worse references for them
04:13 PM teus: traditionally they were called "mof" (sleeve) here
04:13 PM cehteh: lol
04:13 PM teus: because german soldiers during a siege were wearing them at night to keep their hands warm
04:13 PM vmt: i'm not gonna get into this
04:13 PM cehteh: i dont remember germans have any special words for belgians
04:14 PM teus: people found it very effeminate for men to be wearing such sleeve, and the word stuck around
04:14 PM vmt: belgians holy hell. flamish along with dutch are amongst the most horrible sounding languages in the world
04:14 PM cehteh: haha
04:14 PM vmt: guttural sounds rofl
04:14 PM vmt: or is it flemish?
04:14 PM vmt: i guess it's flemish actually
04:14 PM teus: ya
04:14 PM cehteh: i never heared flamish .. but i can read dutch, but no chance understanding it
04:15 PM teus: flanders has dialects too
04:15 PM teus: my native dialect one is the most infamous
04:15 PM cehteh: https://www.youtube.com/watch?v=s-mOy8VUEBk but :)
04:15 PM teus: if we go 50km east nobody can follow
04:16 PM vmt: cehteh: sure, all scandinavian languages are horrishit, danish is probably the worst though
04:16 PM vmt: or icelandic, don't know they all sound horrible
04:16 PM teus: ha
04:16 PM teus: yeah i dont know a word in those scandinavian languages
04:16 PM vmt: but at least they are free of the flemish/dutch guttural sounds with regards to r
04:17 PM vmt: it's not an "r" it's "xchrcrh"
04:17 PM teus: ha
04:17 PM vmt: borderline that of arabic
04:18 PM teus: people drew up a map of the word frikandel here
04:18 PM vmt: had a dutch friend teach me some dutch. all i can remember that cock was "pik", if memory serves
04:18 PM teus: yeah thats the dutch term
04:19 PM vmt: think i'll go to places with that
04:19 PM vmt: at any rate i digress, enough offtopic for me
04:19 PM teus: oki
04:19 PM teus: i once heard nebuk talk german to his parents
04:19 PM vmt: and no don't take it seriously, i'm just messing with you :D
04:19 PM teus: very hard to understand
04:21 PM vmt: my native finnish is a real oddball language and sounds fucking horrible to europeans, so it's alright:D
04:21 PM teus: ah, finnish
04:21 PM teus: peculiar people
04:21 PM vmt: you sure could say that
04:22 PM vmt: but yeah, i'm out for a while, toodles
04:22 PM cehteh: at leas all scandinavians speak a pretty good english
04:23 PM cehteh: teus: what does the tiny85 in your headphone amp?
04:26 PM teus: convert rotary encoder to volume up/down
04:26 PM cehteh: lol thats all? :)
04:26 PM teus: the regret is real. so much work and frustration for something to stupid
04:26 PM teus: yes
04:26 PM cehteh: haha ok
04:26 PM teus: well
04:26 PM teus: while im at it, i can control a few leds and so
04:26 PM cehteh: may use a smaller tiny instead :D
04:27 PM cehteh: tiny13
04:27 PM teus: dunno. dip is nice, so i can replace it
04:27 PM teus: without soldering
04:27 PM cehteh: same dip
04:27 PM cehteh: or tiny25 thats like the 85 but less memory
04:29 PM cehteh: i coulld've suggested you my micro OS .. but for such a simple task it really doesnt matter
04:29 PM teus: perhaps, i just took the attiny with most features
04:29 PM cehteh: while you need almost no features :)
04:34 PM teus: mhmh
04:34 PM cehteh: btw when your polling code cant keep up; are you sure it runs at 8Mhz and not 1Mhz? (well even at 1Mhz it should be fast enough, or that library is extremely crappy)
04:34 PM teus: really not too concerned
04:34 PM teus: indeed, i was just looking at it, should be 8mhz
04:35 PM teus: programmer says 8mhz internal clock
04:35 PM cehteh: CKLDIV8 fuse is set by default
04:35 PM cehteh: yes
04:35 PM cehteh: but its divided by 8
04:35 PM cehteh: and you can/should just leave that fuse but change the prescaler at the beginning of main
04:35 PM cehteh: then it runs at 8Mhz
04:36 PM teus: oh
04:36 PM cehteh: and hey since its a tiny85 you can evne use its PLL to run at 16Mhz ... thats a quite unique feature :D
04:36 PM teus: https://github.com/buxtronix/arduino/tree/master/libraries/Rotary
04:37 PM cehteh: eww c++ :D
04:37 PM cehteh: eww++ arduino
04:37 PM teus: yeah.
04:37 PM teus: looking at his code and i don't see any ISR() there
04:38 PM teus: yeah, be my guest to figure it all out for me. i waited 6 months for nebuk to have a look
04:38 PM cehteh: on my one and only arduino prokect i use code for a roatry encoder that uses isr'S
04:38 PM cehteh: https://git.pipapo.org/?p=dinoheat;a=blob;f=DinoEncoder.ino;h=a37a17bc5f5ed12622ce133203e1a9957bc50ecf;hb=50ae17e9510e6224e32d9c8960c11c8203d1b5ce
04:39 PM cehteh: but its a bit special purpose and just uses delay() for debouncing
04:39 PM cehteh: nowadays i would do it differntly
04:40 PM cehteh: https://muos.pipapo.org/ << ;)
04:40 PM cehteh: i ever wanted to add a driver for rotary encoders there
04:40 PM teus: cute
04:41 PM cehteh: thats completely async/event driven w/o all the arduino overhead
04:43 PM teus: ah
04:43 PM teus: i see
04:43 PM vmt: cehteh: that sounds a bit overkill
04:43 PM cehteh: yeah for that sure
04:44 PM vmt: alas, embrace the madness and let's build one with a real scheduler
04:44 PM cehteh: but as it already exists and i ever wanted an ecoder driver it could be an option
04:44 PM vmt: sure
04:44 PM cehteh: what do you mean by real scheduler?
04:45 PM vmt: well off a quick glance your muos doesn't have a scheduler per se
04:45 PM cehteh: what is your definition of scheduler?
04:46 PM cehteh: beause it schedules function calls
04:46 PM cehteh: but it is cooperative, which makes a lot things simpler
04:46 PM vmt: doesn't your os pop stuff off the queue and execute them until they yield or return?
04:46 PM cehteh: yes
04:47 PM cehteh: yield,return or wait
04:47 PM vmt: well yes
04:47 PM cehteh: cooperative scheduling
04:47 PM cehteh: only one stack
04:47 PM vmt: so it doesn't have a scheduler that has a finer grain of control wrt execution. can't do context switching at will
04:48 PM cehteh: it does not do context switching .. but it does scheduling
04:48 PM vmt: well, yeah
04:48 PM cehteh: which is a huge advantage
04:48 PM teus: ok, got it working with interrupts but no improvement
04:48 PM teus: i'll wait for the pcb and do debouncing
04:48 PM cehteh: otherwise you waste shitloads of ram on these tinys and you need thread synchronization primitives
04:48 PM teus: or check the prescalers
04:49 PM cehteh: teus: when its arduino then it should do the right thing and run at 8mhz
04:49 PM cehteh: teus: just let it blink at 1 sec interval on a pin
04:49 PM cehteh: then you see if the timing is correct instantly
04:49 PM teus: hm?
04:49 PM teus: oh, if delay of 1000ms actually corresponds to 1sec?
04:50 PM cehteh: (you'll notice when it blinks in 8 secs instead 1)
04:50 PM vmt: but what if someone wrote shitty blocking code
04:50 PM cehteh: roughly
04:50 PM vmt: it's imperative that the LED TURNS ON
04:50 PM teus: yeah, okay, its correct in that case
04:50 PM cehteh: delay is a bit malpractice but ok for a test
04:50 PM teus: led blinking seems correct
04:51 PM cehteh: yeah .. thats the only advantage of arduino that it sets this right 'most of the time' hahah
04:51 PM cehteh: otherwise it has so much overhead
04:51 PM teus: would be much better to properly code it with less overhead
04:51 PM teus: but i cba
04:51 PM teus: i dont like writing software
04:52 PM teus: if there's plenty of shitty libraries floating around, it'll take time to make something that doesnt suck
04:52 PM cehteh: normally i'd expect an 8mhz avr to work correctly when you spin the encoder with an electric drill at hihger speed :D
04:52 PM vmt: we need a pre-emptive scheduler for avrs, defo
04:52 PM cehteh: up to the debounce time of the encoder which is usually around 1ms
04:53 PM vmt: i'm almost sure that some retard has already made one
04:53 PM cehteh: arduino is famous for pretty doubful code quality and libs esp external ones
04:53 PM cehteh: no error handling and 'worked once for me, ship it' metality
04:54 PM cehteh: teus: how much steps has your encoder?
04:54 PM cehteh: per turn
04:55 PM cehteh: lets be conservative and say 5ms per step ... * steps then you get the max speed it should be capable
04:55 PM cehteh: max speed
04:56 PM cehteh: if it cant handle that, then the code is broken 5ms is lots of time even at 8mhz
04:58 PM cehteh: for example 8 steps at 5ms thats 40ms for a rotation thats 1500rpm i doubt that any human can operate it so fast :D
05:00 PM teus: uhmmm i'd have to look
05:00 PM cehteh: (and that are conservative estimates, usually debouncing for 1ms is enough, gives 7500rpm)
05:00 PM vmt: ladies and gentlemen bruce lee on the rotary encoder
05:00 PM cehteh: yeah
05:01 PM teus: whut
05:01 PM cehteh: but .. bouncing will cause misreads and the faster you turn the more it bounces, prolly thats what you observe when you turn fast
05:02 PM teus: yeah
05:02 PM teus: https://www.digikey.be/product-detail/nl/bourns-inc/3315C-001-006L/3315C-001-006L-ND/1088224
05:02 PM cehteh: i cant imaginge the arduino being that crappy
05:02 PM teus: 6 per revolution? seems low
05:02 PM teus: checking datashit
05:03 PM teus: 5ms bounce, max 120rpm, 100 000 cycles at 6 PPR, 25 000 at 16 PPR
05:04 PM cehteh: you may consider a slightly better encoder :D
05:04 PM teus: yeah i mislinked
05:04 PM teus: i got the 16 PPR one
05:04 PM cehteh: even that
05:04 PM vmt: 1500 rpm is like what, 9k deg/s av, easy!
05:05 PM cehteh: wind a shoelace around it and pull
05:05 PM teus: :)
05:06 PM cehteh: https://www.reichelt.de/drehimpulsegeber-15-impulse-30-rastungen-vertikal-stec11b03-p73913.html?&trstct=pos_0&nbc=1
05:06 PM cehteh: check datasheet of those
05:07 PM teus: for what?
05:08 PM teus: 2ms bounce
05:08 PM cehteh: max rpm, bounce time, lifetime/cycles
05:08 PM teus: mrrrh
05:08 PM teus: not too concerned now
05:08 PM cehteh: ok
05:09 PM teus: preferrably i'd have one with a bigger shaft and a click you can feel when turning it
05:11 PM cehteh: and prolly more steps
05:11 PM cehteh: anyway ok for a test
05:11 PM teus: yeah
05:11 PM teus: if i cant find it, i can make a cutout in the pcb or so
05:11 PM cehteh: but there should be no way that an attiny85 cant handle those at insane speeds when programmed correctly
05:12 PM teus: hmm actually i could make a small cut in the enclosure and i could push the max height to 11mm
05:12 PM teus: cehteh: sounds like debouncing is next
05:12 PM cehteh: actually you may use the code i posted earlier with the delay() ... its malpractice but since the thing doesnt do anything else it wont interfere with anythnig
05:13 PM cehteh: you can as well store timestamp and see if it at least increased by 1ms
05:13 PM teus: no worries there
05:14 PM cehteh: mhm dunno if its sane to call millis() from an isr .. iirc thats broken in arduino
05:15 PM teus: oh im using it
05:15 PM teus: it works to blink a led when i cant use delay
05:15 PM cehteh: arduino is broken in some surprising and undocumented ways :D
05:16 PM teus: :)
05:21 PM teus: i go sleep
05:21 PM teus: thanks for the help
05:23 PM cehteh: cu o/
05:42 PM cehteh: ah teus when you read this tomorrow .. i had the idea i wanted to implement that an encoder takes track of the direction it moves and would detect a 'sudden' direction change as fluke
05:43 PM cehteh: that'll eliminate a lot bounce related inprecision w/o extending the bounce time
08:06 PM markasoftware: so I see that there are some really small AVRs with differential adc (eg, attiny84) and then some large ones (attiny164, eg, with like 40+ pins). Is there anything in the middle, around 30 pins, with a differential adc?
08:07 PM markasoftware: I mainly need around 20 pins, which is mainly why I don't want 40+ pins
08:22 PM Smidge204: have you tried Microchip's parametric selector tool?
08:26 PM Smidge204: https://www.microchip.com/paramchartsearch/chart.aspx?branchID=1005 Oddly there's no option to link filtered results
08:27 PM Smidge204: But select your CPU Type (e.g. 8-bit AVR if that's what you want), and pin count (e.g. hold CTRL to select 20, 24, 28) and whammo
11:31 PM day_ is now known as day