#avr Logs

Oct 10 2020

#avr Calendar

06:07 PM bedah: I now have 8-channel pwm for LED lightning, triggered by timer0, with a somehow new algorithm to suppress flickering. I wonder if i reinvented an elder wheel.
06:14 PM vmt: ah, you just barely missed the nobel prize
06:14 PM bedah: ignobel would be nicer, but i solved a problem nobody but me had, so no price :)
06:14 PM vmt: you might have invented an elder square
06:14 PM vmt: you should hook up with rue he really is into that kind of stuff
06:17 PM cehteh: possibly flickers when you do other things that block interrupts for some times
06:18 PM bedah: it's like when you use a ws2812 led, set it to "1", and move the led - then you'll see the flicker i mean
06:18 PM cehteh: yes
06:18 PM bedah: "1 out of 255"
06:19 PM cehteh: well dunno the ws2812 pwm freq
06:19 PM cehteh: ideally i make the freq high enough, but with software that has some limits
06:20 PM bedah: I simply distributed the on-time in my pwm, so it behaves similar to delta-sigma-modulation
06:20 PM cehteh: PCM
06:21 PM cehteh: still when there is some load on the mcu and interupts are blocked you will see brightness changes and flickering
06:22 PM bedah: yes of cause
06:22 PM cehteh: possibly not much because it needs quite some time to change that significantly
06:22 PM cehteh: and you possibly have some rather high load already or?
06:23 PM bedah: no, just an atmega328, listening on uart, and changing pwm values, with ISR running
06:25 PM bedah: https://github.com/dk5ee/7leds/blob/master/code/main.c comments welcome
06:26 PM bedah: argl.. there are some artifacts in the code.. but it works
06:27 PM cehteh: hehe
06:28 PM cehteh: in the ISR you should prepare the port byte in a uint8 instead manipulating the port in all those if's and set it at the end ... or actualy:
06:28 PM vmt: that last ISR though
06:28 PM cehteh: store that in a static uint_8 and set it at the begin (the result from the last pass) that gives slightly better timing
06:28 PM bedah: hehe yes :D it's the last ISR
06:28 PM cehteh: PORT is volatile accessing it is costly
06:29 PM bedah: my leds are on portb and portd
06:30 PM cehteh: then 2 vars
06:30 PM vmt: yeah
06:30 PM cehteh: what i wanted to say is that any volatile should be accessed as least as possible, even making a copy of it is more efficient
06:31 PM bedah: it's ugly, i know, but the speciality is the "-148" and "+107" - this distributes the on-time over the 255 ticks
06:31 PM cehteh: and that its favorable to do timing critical stuff at first and then the rest is only the 'preparation' for the next iteration which isnt timing critical anymore
06:32 PM cehteh: may even be done outside of the isr
06:32 PM bedah: ah.. i see.. only change portb at the end of all changes of portb
06:32 PM bedah: i did that with "uint8_t count"
06:32 PM cehteh: that gives additional latency but more precise timing
06:33 PM bedah: good hint, cehteh
06:33 PM bedah: but this will make the code even more not-understandable
06:34 PM bedah: will implement that :D
06:34 PM vmt: no, not really
06:34 PM cehteh: well i'd remove all the spaghetti code and make it somewhat generic
06:35 PM vmt: a special tingling in my butt suggests this is almost surely optimizable
06:35 PM bedah: this will need a loop. but a loop is nonlinear, so i unrolled it
06:35 PM cehteh: also not overcommenting your code, but when there is a // set value from last iteration ..... // prepare value for next interation .... comment is ok
06:36 PM cehteh: aka code should be self explanatory, but sometimes give some hints about the intents why its done this way
06:36 PM vmt: from a purely aesthetic point of view there's no reason to use /**/ for single line comments and span them multiple lines i.e. /*\ncomment\n*/
06:37 PM cehteh: whatever .. its more about what you comment, not how
06:37 PM vmt: yeah but my screen has a limited amount of lines
06:38 PM bedah: there are no real comments in the code.. just my dirty code
06:38 PM bedah: will remove the /* */
06:39 PM vmt: it's really just aesthetics. i figure old beards use it because ansi-c compatibility is for reasons unknown somehow important and/or they're stuck in some weird time loop in the 1980s
06:41 PM cehteh: my documentation system uses // so i stay with it :D .. well it would support /* */ to but there is really no reason to use it in modern C, esp the nesting semantic of /**/ was and is crappy anyway
06:41 PM bedah: I so laughed when there was the problem of "tabs vs spaces" on "silicon valley"
06:42 PM vmt: i find aesthetics extremely annoying and i just felt to interject with that to seem like a smartass and have something to say
06:44 PM bedah: the other problem i had with this project is not AVR related - getting to let ppl over the internet controll the leds
06:45 PM vmt: oh no i smell a raspberry pi or espruinoduinocappuchinofdsafspruino
06:45 PM bedah: hehe
06:45 PM cehteh: raspberry pi, small webserver ...
06:45 PM cehteh: yeah
06:45 PM bedah: no.. running on my notebook, tunnel to a server. that way
06:45 PM cehteh: well better than some ethernet shield
06:46 PM bedah: python. in same repository.
06:46 PM vmt: bedah: well you would be better off then with a usb mcu then
06:47 PM vmt: now you no doubt have some ftdi (or whatever that other mf was) usb uart chip
06:47 PM bedah: yes
06:47 PM vmt: but you could even code up a webserver, put that on a raspberry pi and control the leds directly there
06:48 PM bedah: ch430 or ftdi.. cheap chinese arduino clones are cheap
06:48 PM vmt: that would seem like the sanest option on a lot of levels
06:48 PM cehteh: well use a proper mcu with 8 PWM channels and usb that can do TCPIP to begin with
06:49 PM cehteh: or rpi .. iirc plenty of its gpio's have hardware pwm
06:49 PM bedah: that what i did. python webserver on port 8080, talking to atmega over ttyUSB, tunneled to be accessed on internet
06:49 PM vmt: but that needs your laptop, lol
06:49 PM vmt: cehteh: or just use a multisexer
06:51 PM bedah: can be easily replaced.. but the problem then was: syncing the display, when one user changes one LED, this should be displayed for others..
06:51 PM bedah: it was funny, to have this problems with a real existant device
06:52 PM vmt: err what do you mean? taking still pictures?
06:53 PM bedah: no, a slider to change the value.. this problem is independend of this pwm-thingy
06:54 PM vmt: well, with a webserver meant for this you could actually solve this super easily and having the led control on the same piece of hardware
06:54 PM vmt: easypeasy
06:54 PM vmt: anyway, bedtime for moi. night folks
06:54 PM bedah: gn8 vmt
06:55 PM bedah: .oO I still need to solve the "who controls the LED problem"
11:37 PM day_ is now known as day