#avr Logs

Nov 28 2018

#avr Calendar

12:17 AM grog_o is now known as grog
03:03 AM vmt: --
06:42 AM cehteh: wtf ... i'm tying to generate a inverted fastPWM signal, but whatever i set the output it wont invert
06:55 AM s8548a: https://www.facebook.com/kicadeda/posts/505170286632479
08:09 AM LeoNerd: cehteh: "won't invert"?
08:30 AM cehteh: LeoNerd: i need a pulse which starts low driven (for 3µs) and then going high for a configureable time (OCR1B/ICR1 .. whatever mode)
08:31 AM LeoNerd: OCM_SET then? Period in ICR, 3µs in OCR
08:33 AM cehteh: OCM_SET?
08:34 AM LeoNerd: Er.. whatever the setting is. That's the name of my constant, anyway
08:34 AM cehteh: dont find it
08:34 AM LeoNerd: PWM in "set at output compare time" mode. When the timer is running a PWM mode, it'll clear at timer reset then set at OC match
08:34 AM cehteh: yes
08:35 AM * cehteh thinks i have some brainfuck there
08:36 AM LeoNerd: Timers can be varied and subtle. Their behaviour changes quite a bit based on the mode they're in
08:36 AM cehteh: yes
08:36 AM LeoNerd: In a PWM mode it'll manage the IO pins differently to a non-PWM mode. That keeps tripping me up
08:36 AM cehteh: i know i read the datasheet multiple times now
08:37 AM cehteh: still thatz wont change the output :D
08:37 AM LeoNerd: Did you remember to set the corresponding DDR bit?
08:37 AM cehteh: yes it does output i mean, but not inverted
08:37 AM LeoNerd: You're supposed to always, but it turns out a few ATtiny chips don't need you to. That often trips me up, when I copy code from one chip to another
08:38 AM cehteh: i get -_____ but i want _----
08:38 AM LeoNerd: ATtiny84 if I recall, doesn't need it
08:38 AM LeoNerd: The docs /say/ it's needed but in actual practice it turns out not to
08:38 AM cehteh: 328 of course
08:38 AM LeoNerd: Hrm.. try OCM_CLEAR just for interest?
08:39 AM cehteh: wher is that defined?
08:39 AM cehteh: and how
08:39 AM LeoNerd: It's whatever the bit patterns are.. one mo
08:40 AM cehteh: $ rgrep OCM_CLEAR /usr/lib/avr || echo nop, nothing
08:40 AM cehteh: nop, nothing
08:40 AM LeoNerd: https://paste.debian.net/1053572/ - random bit of my code
08:40 AM LeoNerd: Oh, avr-libc doesn't really provide a HAL, other than a few odd bits of isolated cases
08:40 AM LeoNerd: Folks tend to make their own
08:40 AM LeoNerd: Theabove is a paste from some of mine
08:41 AM cehteh: ah yes i set those modes
08:42 AM cehteh: on 0 i get nothing (of course), on 1 i get -_____ , on 2 i get noting (huh?) , on 3 i get -_____ (same as 2)
08:42 AM cehteh: thats confuses me
08:42 AM LeoNerd: That sounds odd...
08:42 AM LeoNerd: ATmega328, you say?
08:42 AM LeoNerd: ... or perhaps the PB?
08:42 AM cehteh: 328p
08:43 AM cehteh: not pb
08:43 AM LeoNerd: Hrm.. Timer 1, channel B?
08:43 AM cehteh: yes
08:43 AM cehteh: and wgm mode 14 or 15
08:43 AM LeoNerd: Any other code that prods the corresponding PORT register?
08:43 AM cehteh: fast pwm, either with ocra or icr
08:44 AM cehteh: no
08:44 AM cehteh: well lemme try, i think i commented everything else out, but i just copy paste that to the start of main and do a busy loop
08:45 AM LeoNerd: "The setup of the OC1x should be performed before setting the Data Direction Register for the port pin to output." says data sheet
08:45 AM LeoNerd: Beware, I have had weird bugs by not observing the correct sequence of operations before; tha simply swapping two lines of code can change things
08:47 AM cehteh: wtf .. leme try
08:48 AM cehteh: but .. .there are case (actually my case) where you want to change OC1x with the timer running
08:48 AM cehteh: i need to change TOP
08:49 AM LeoNerd: Use the ICR mode
08:50 AM cehteh: later i want the buffered update, but i like toi have it working with icr1 now
08:51 AM LeoNerd: The difference is when it takes effect, to avoid glitches during counting
08:52 AM cehteh: https://paste.debian.net/1053577/
08:52 AM cehteh: yes
08:53 AM cehteh: i thought i know that stuff, thus it surprises me it wont work
08:54 AM LeoNerd: Ohh,, |=
08:55 AM LeoNerd: I usually like doing the initial setup with a plain = to know that I'm setting just the right values
08:55 AM LeoNerd: TCCR1A |= (3 << COM1B1); <== that looks wrong
08:55 AM LeoNerd: 3 shifted up by the 1 bit of COM1B1
08:55 AM LeoNerd: Surely you wanted 3 << COM1B0, or maybe _BV(COM1B1)|_BV(COM1B0) or such?
08:55 AM cehteh: öh
08:56 AM cehteh: see.. i saied i have some brainfuck :)
08:56 AM cehteh: thats it
08:56 AM cehteh: thanks
08:56 AM LeoNerd: 🙌
08:57 AM LeoNerd: This is why I usually make myself a HAL so I don't have to think about things
08:57 AM LeoNerd: In a main .c file now, the only bit-twiddling I need to do is direct DDR/PORT/PIN stuff, or a few rare things like AC or PCINT
08:59 AM cehteh: well this *is* for my hal :D
09:00 AM LeoNerd: https://paste.debian.net/1053578/ - is how I'd write that
09:00 AM cehteh: i hacked the init routines together, didnt worked, thus i isolated the code / copy pasted and investigated and cursed why it didnt worked
09:00 AM LeoNerd: Ahh
09:00 AM LeoNerd: I should consider publishing mine, as a "simple non-nonsense" thing, but.. meh.. effort
09:01 AM LeoNerd: Well, no. Publishing isn't the effort; the effort is dealing with all the whiney folks who make comment about it afterwards
09:01 AM cehteh: i generate code for multiple timers with the preprocessor
09:02 AM cehteh: just writing a stepper motor driver
09:02 AM cehteh: anyway thanks a ton, was just some stupid bug i've overseeen
09:03 AM LeoNerd: Eh; no need to use preproc. gcc -flto -ffunction-sections can do that just as efficiently
09:03 AM LeoNerd: It inlines function calls, merges updates to registers (hence why = rather than |= is important), etc...
09:03 AM LeoNerd: It'll const-fold parameters between function calls between .c files even, so all the setup parameters become inlined
09:04 AM cehteh: preprocessor takes configuratiion from makefile about how to configure the timers
09:04 AM cehteh: i use lto as well
09:05 AM LeoNerd: Ah; yeah I have a `local-config.h` for things like which IO pins to use in some of my bitbanged virtual peripherals
09:05 AM LeoNerd: Like my vuart.c ;)
09:05 AM cehteh: but some things are not doable with that, lie changing the number of timers to generate code for
09:06 AM LeoNerd: Mhmm
09:06 AM cehteh: anyway that part works
09:07 AM LeoNerd: :)
09:07 AM cehteh: going on to fix that shit now
09:07 AM cehteh: heh few days a go i made nice excercise about how to increment generic numbers with the preprocessor
09:08 AM cehteh: needed some surprisingly shitloads of code
09:09 AM LeoNerd: I don't tend to do fancy preprocessor tricks, other than simple bits of #ifdef
09:09 AM cehteh: i dont really use that becasue its too complicated, but wanted to know if it works
09:09 AM cehteh: https://public.pipapo.org/pptest.h.txt
09:10 AM cehteh: note the 2nd number needs a reversed internal format 123 -> 3,2,1
09:11 AM cehteh: DECIMAL converts that back to normal numbers
09:11 AM cehteh: but there is no way to do the opposite conversion
09:11 AM cehteh: but with that machinery one can write indexed loops in preprocessor alone, for whats worth
09:12 AM LeoNerd: Sounds pretty scary
09:12 AM cehteh: it is
09:13 AM cehteh: i now hardcoded that on the old unrolled style way for numbers from 0 to 16 .. good enough for me
09:13 AM cehteh: so bbl
11:50 AM [1]MrMobius is now known as MrMobius
03:48 PM vmt: --
03:49 PM polprog: pop $vmt
03:56 PM vmt: push me and then just pop me
03:57 PM polprog: till i can get() my $satisfaction;
03:58 PM vmt: ;D high-five
03:59 PM polprog: :P
04:00 PM polprog: so weve got assembly, java and perl
04:00 PM polprog: the three riders of the apocalypse
04:02 PM vmt: last one can be a number of things i figure
04:02 PM vmt: wait. they all can
04:04 PM vmt: i think js nigs love lambdas because well, i really don't know why so --
04:04 PM polprog: its just an anonymous function
04:05 PM polprog: i was using "lmbdas" in java before i knew what a lambda is
04:05 PM polprog: if i understand it correctly
04:05 PM vmt: var satisfaction = (me) => { return touch(me); }
04:05 PM vmt: yes it is
04:06 PM vmt: but people using languages with lambdas cream when they get mentioned
04:06 PM polprog: lol, i knew it would be something fucked up
04:06 PM polprog: https://stackoverflow.com/questions/7343526/how-to-run-an-anonymous-function-in-perl
04:06 PM polprog: i like this language, scripting like any other, but the syntax...
04:06 PM polprog: its just plainly horrible
04:07 PM vmt: i honestly think lambda functions bring nothing to the table
04:08 PM vmt: and now i'm sure, it won't take long before some c++-acolyte will put me in my place, telling me how fakking amazing they are
04:08 PM polprog: i think they sort of declutter stuff when you need a one-off function, but its not THAT useful
04:08 PM LeoNerd: They're handy when they *capture* variables that can outlive them
04:08 PM polprog: id rather take a long function in a known place rather just some anonymous thing plastered inbetween code
04:08 PM LeoNerd: Which is why they don't exist in plain C, because that won't work
04:09 PM vmt: oh yeah of course, when people still recite idiotic mantras from god knows where "functions (well methods) *have* to be under 25 LOC..."
04:09 PM polprog: ive seen stupid mantras
04:09 PM LeoNerd: int *make_iter(int start)() { int x = start; return int (*){ return x++; } }
04:09 PM polprog: like, one guy was arguing to drop the 80 char margin
04:09 PM LeoNerd: ^-- consider what happens to int x here
04:09 PM polprog: they dont get it that this is just a guideline, to make the code readable on most screens
04:10 PM polprog: instad he would write some long lines that wrap 5 times or something
04:10 PM polprog: he wrote lisp so i dont really take him seriouslt
04:10 PM polprog: :D
04:12 PM vmt: for(i++\n;i<j;\ni++)\n{\n...\n}
04:12 PM polprog: lol
04:12 PM vmt: i've blown a quarter of my function LOC budget
04:12 PM vmt: i mean a fifth.
04:12 PM polprog: LOC?
04:12 PM vmt: lines of code
04:12 PM polprog: ah
04:12 PM vmt: there is an age-old mantra which states functions (well oop, methods really) have to be under 25 LOC each
04:12 PM polprog: well, there are people who do int\nsomefunc(int a)\n{
04:13 PM polprog: ugh, i hate this sort of stuff
04:13 PM polprog: it looks bad on my 1080 screen, it must have looked atrocious on a 24 line terminal
04:15 PM vmt: i actually write qualifiers and the return type on a separate line in function definitions
04:17 PM polprog: i leave every second line empty so i can add comments and edits with my pen easier
05:32 PM Ameisen: A note for people doing C or C++ with GCC...
05:32 PM Ameisen: I suspect it's much worse on AVR but I haven't tested it
05:33 PM Ameisen: both GCC and Clang _always_ treat && and || as short-circuiting, even in trivial cases.
05:33 PM Ameisen: (a == 1) || (b == 2) generates far worse code than (a == 1) | (b == 2) on x86, at least
05:34 PM Ameisen: not sure why the optimizer is incapable of handling it at that point... either it's stuck on it being short-circuiting, or it's failing to realize that both sides can only be 1 or 0, or both
07:35 PM devinmcelheran: Would someone mind helping me understand where the seed^=0x18; seed >>= 1; seed|=0x80; comes into play in 1-wire CRC8? Source lines 57-59 https://www.microchip.com/wwwappnotes/appnotes.aspx?appnote=en591191
07:36 PM devinmcelheran: My understanding is that it should XOR with a byte that is representative of the CRC polynomial then shift and proceed.
11:35 PM day__ is now known as day