#avr Logs

Jan 20 2019

#avr Calendar

05:39 AM jancoow: Someone could help me setup a cmake file for compiling with the avr-gcc? :d
05:43 AM jancoow: I finally managed to program my attiny414 with that updi thingy
06:48 AM cehteh: do yourself a favor and use plain make
06:48 AM cehteh: maybe gnu flavored
06:57 AM nohit: he is probably asking because he uses clion
07:03 AM TechChristoph: jancoow: do you use git ?
07:11 AM jancoow: cehteh: yeah that's probably easier then
07:11 AM jancoow: Makefile works fine
07:21 AM [1]MrMobius is now known as MrMobius
07:28 AM [1]MrMobius is now known as MrMobius
07:52 AM jancoow: I guess I need to install avr studio anyways ugh
07:52 AM jancoow: And windows.
07:52 AM cehteh: yep
07:52 AM cehteh: yep i mean ugh ... dont
07:52 AM cehteh: why?
07:53 AM jancoow: I'm used to autocomplete and error / warnings real time :P
07:53 AM cehteh: emacs can do that, vim prolly too
07:53 AM jancoow: I'm having trouble to set that up
07:54 AM cehteh: this windows and avr studio make that easier :D
07:54 AM jancoow: yeah :P
07:54 AM jancoow: And for some reason I'm not able to compile it for the attiny414
07:54 AM jancoow: It keeps saying registers are undeclared et.c
07:54 AM jancoow: etc.*
07:55 AM cehteh: thats your fault :D
07:55 AM jancoow: haha yeah probably
07:55 AM jancoow: https://jancokock.me/f/18f8b
07:55 AM jancoow: it should be PORB.dir
07:56 AM jancoow: and simply compiling it with avr-gcc -mmcu=attiny414 -DF_CPU=16000000 -Wall -Os -o main.elf main.c
07:57 AM cehteh: huh
07:57 AM cehteh: what runtime lib is that?
07:59 AM jancoow: sorry?
07:59 AM cehteh: $ rgrep PORTB Atmel.ATmega_DFP.1.3.300/include/avr/iom328pb.h
07:59 AM cehteh: #define PORTB _SFR_IO8(0x05)
08:00 AM cehteh: .. i dont know that you can access .DIR on those
08:00 AM jancoow: ewh
08:00 AM jancoow: yeah maybe I understand the documentation wrong
08:00 AM jancoow: It's already a long time ago I did any mcu programming
08:01 AM cehteh: acvr-studio wont help you then :D
08:01 AM jancoow: but AFAI I should write to the registers: PORTA.DIR, PORTA.OUT etc.
08:01 AM jancoow: and PORTB
08:02 AM cehteh: a) i never did that b) my code works
08:03 AM jancoow: mmh
08:04 AM jancoow: mmh yeah it's really not rocket science what I want to do :P Just set some timers and do some software pwm
08:05 AM cehteh: $ rgrep 'define *_SFR_IO8' /usr/lib/avr/
08:05 AM cehteh: /usr/lib/avr/include/avr/sfr_defs.h:#define _SFR_IO8(io_addr) ((io_addr) + __SFR_OFFSET)
08:05 AM cehteh: /usr/lib/avr/include/avr/sfr_defs.h:#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
08:05 AM cehteh: .. i dont really see how your code could work :D
08:05 AM jancoow: it doesn't work
08:05 AM jancoow: haha
08:05 AM cehteh: well if you do it wrong then it wont work .. no matter what editor/OS/IDE you use
08:06 AM cehteh: maybe there is some c runtime around i dont know where PORTB is defined to something more fancy .. whatever :)
08:07 AM jancoow: Ah. The autocomplete helped me in atmel studio
08:07 AM jancoow: its PORTA_DIR
08:07 AM jancoow: lol
08:10 AM cehteh: i just use ther DDRx = .... thing
08:10 AM jancoow: that's for the older attinys
08:11 AM jancoow: this is the newest one
08:11 AM cehteh: all my code so far
08:11 AM cehteh: well havent worked with the tiny you use
08:12 AM cehteh: but would surprise me when they changed the API substiantally
08:36 AM jancoow: they did
08:36 AM jancoow: it's the merge from microchip and atmel
08:36 AM jancoow: that's why this one has that new udpi one wire program thingy instead of regular isp
08:37 AM cehteh: time to move to arm cortex and risk-v
08:39 AM jancoow: why?
08:40 AM cehteh: more powerful, same price or cheaper, 32bit core
08:41 AM jancoow: well I just made some tiny pcb's where I only need a couple of pins
08:42 AM jancoow: with the price of 0.60 euro it's fairly cheap
08:42 AM jancoow: and if it works it's fine for me
08:42 AM cehteh: sure and AVR's are very easy to program
08:42 AM jancoow: yeah
08:42 AM cehteh: thats their biggiest advantage
08:42 AM jancoow: I did a big arm project a few years ago
08:42 AM * polprog sticks a 68k oon a breadboard and moves to a mountain hut
08:42 AM jancoow: isn't that hard either to program
08:43 AM nohit: i think codevison avr uses that PORTB.DIR
08:59 AM jancoow: well atmel studio works fine :)
08:59 AM jancoow: Bummer it's based on visual studio IDE
08:59 AM jancoow: That must be the reason it's not available for linux.
09:02 AM TechChristoph: ??
09:03 AM jancoow: ??
09:08 AM jancoow: cehteh: this code works fine https://jancokock.me/f/8a30f
09:09 AM jancoow: only timing isn't accurate
09:09 AM cehteh: ok
09:09 AM polprog: whats those defines o_O
09:09 AM cehteh: well sure, use hardware PWM
09:09 AM polprog: no DDRB/PORTB?
09:09 AM cehteh: see aboce
09:10 AM cehteh: newfangled microchip stuff
09:10 AM polprog: ah
09:10 AM jancoow: well it's about 3 seconds delay instead of 1 haha
09:10 AM polprog: great, i hope libc keeps backward comp
09:10 AM jancoow: polprog: yeah these defines are different then regular avr chips apperently
09:10 AM polprog: jancoow: what are your cflags?
09:11 AM jancoow: where can I see that?
09:11 AM cehteh: never ever use _delay* stuff
09:11 AM jancoow: I know
09:11 AM jancoow: It was just a quick test if code works
09:11 AM polprog: ah youre using avrstudio
09:11 AM cehteh: then steop using it
09:11 AM polprog: maybe in some console otuput? no idea
09:12 AM jancoow: sec
09:13 AM jancoow: what particlar one are you looking for?
09:13 AM polprog: the gcc invocation
09:13 AM cehteh: delay is documented as "works only correct when you set the right optimization flags'
09:13 AM polprog: yeah that^
09:13 AM cehteh: plus F_CPU .. and clkdiv8
09:14 AM jancoow: ah right
09:14 AM cehteh: and moon phase
09:14 AM jancoow: makes sense
09:15 AM cehteh: either way, just drop that and switch right away to a proper timer
09:15 AM jancoow: yeah that's what I'm going to do now lols
09:15 AM jancoow: it was just a test
09:15 AM jancoow: Now I need to make 9 pwm signals with... 4 timers. yay
09:15 AM jancoow: Dunno what software pwm solution is the best
09:15 AM cehteh: _delay_ms iirc lso wants a float and pulls in truckloads of float code
09:16 AM cehteh: how fast?
09:16 AM jancoow: led strip dimming, so dunno how fast I need
09:16 AM cehteh: either way looks to me like you used the wrong mcu then
09:16 AM jancoow: It was cheaper :P
09:16 AM cehteh: but doesnt work for the task ;D
09:17 AM jancoow: well it will work fine
09:17 AM cehteh: well software pwm will do
09:17 AM jancoow: yeah
09:17 AM cehteh: then one timer would be enough
09:17 AM jancoow: this simple board will only need UART and 9 soft pwm channels
09:18 AM cehteh: ok uart+soft pwm looks like trouble
09:18 AM jancoow: it has hardware uart
09:18 AM jancoow: so will be fine
09:18 AM cehteh: yes
09:18 AM cehteh: still
09:19 AM jancoow: you think it won't work?
09:19 AM cehteh: maybe you can get it with little noticeable flicker
09:19 AM cehteh: doable yes, easy no
09:20 AM cehteh: how many brightness levels do you need?
09:20 AM jancoow: 255 is fine
09:21 AM cehteh: w/ 8bit timer there are not many useful levels, because human perception is logarithmic and you need to account for that
09:21 AM cehteh: i usually go for 16 brightnes levels on 8 bit timer only
09:21 AM jancoow: the attiny414 has 2 16 bit timers
09:21 AM cehteh: and 2x 8 bit :D
09:21 AM jancoow: yeah you can split it
09:21 AM jancoow: so 4* 8 bit
09:21 AM cehteh: ah
09:22 AM cehteh: dont know that chip
09:22 AM jancoow: and apprently 12 bit timer and a 16 bit RTC time counter
09:22 AM cehteh: well maybe use 1 timer and a constant time loop to generate all pwm and pet the uart
09:22 AM jancoow: yeah that was what I was thinking indeed
09:22 AM jancoow: timer at 200hz or something?
09:23 AM cehteh: try to make it as fast as you can do, effectively how fast you can handle the uart will be the limiting factor
09:24 AM cehteh: not only the upper limit also the lower
09:24 AM jancoow: but the UART has it's own interupt right?
09:24 AM cehteh: interrupts would disturb your software PWM
09:24 AM cehteh: will flicker
09:25 AM cehteh: maybe not noticeable, but up to you to figure out
09:25 AM jancoow: rgb levels will be send through UART. so simply a char array which each containing an rgb level so: RGBRGBRGB
09:25 AM jancoow: which will set each channel respectifly
09:25 AM jancoow: ah right, understand
09:26 AM jancoow: so if something is sending uart messages 100* per seconds it will definitely be noticable on the led strip
09:26 AM cehteh: of course woukld be easierst when using interrupts and hardware PWM .. but you dont have the right mpu for that
09:26 AM jancoow: yeah I know
09:26 AM jancoow: ah well let's see :P
09:39 AM jancoow: so yeah
09:40 AM jancoow: if I want to have 255 dimming steps, at say 50hz , I need to create 50*255 = 12750 timer int / per second
09:43 AM cehteh: yep
09:43 AM cehteh: 16000000 / 12750 = approx. 1254.902
09:44 AM cehteh: clock cycles available
09:44 AM cehteh: should be dobale
09:44 AM jancoow: Yeah I really need to remember this :P Long time ago I used timers lols
09:44 AM jancoow: yeah exactly
09:44 AM cehteh: unless you use floats
09:44 AM cehteh: or divisions
09:49 AM jancoow: well
09:50 AM jancoow: In each interupt event I simply calculate the rest value: counter % 255
09:50 AM jancoow: and then the output of the desired pin is rest > R/G/B value
09:50 AM cehteh: dont forget what i've saied about logarithmic perception
09:50 AM jancoow: dunno how much cpu cycles that takes
09:51 AM cehteh: ideally you calculate a mask for all outputs bit by bit and finally latch it .. having all leds on the same port
09:52 AM cehteh: well you could do the brightness level logarithmic stuff on the sender side
09:52 AM cehteh: but maybe you want higher resolution than 8 bits then good luck optimizing that
09:54 AM jancoow: nah I think this is fine
09:54 AM jancoow: Currently my other application is also using 8 bit
09:54 AM jancoow: which is more then fine
09:57 AM jancoow: well let's see if I can configure the timer correctly and get this to work on 1 channel
10:27 AM jancoow: cehteh: uhm yeah so. The max devision is 1024. So that would be 16000000/1025=15625 e
10:28 AM cehteh: since you now do it in software you can happily use a single 16 bit timer
10:28 AM jancoow: this is the 16 bit timer
10:29 AM cehteh: ok
10:29 AM cehteh: eh that should plenty fast enough
10:30 AM jancoow: and then just simply set the TOP value to 1 ?
10:30 AM cehteh: oh moment .. you only need to time each step in the cycle
10:30 AM jancoow: the cpu can also run at 20mhz btw :P
10:30 AM cehteh: i dont know how you now want to do it, i have some unrefined idea how i would do it, but i am busy with my own stuff right now
10:31 AM jancoow: ah no worries
10:31 AM cehteh: 16mhz should be plenty and also one single 8bit timer might be plenty
10:32 AM jancoow: okay what I want to do: set the timer division to 1024. Set the TOP value to 1 and let it interupt on each overflow
10:32 AM cehteh: actually you may even account for the logarithmically there increasing (or decreasing) the TOP on each cycle
10:32 AM jancoow: then I've 15625%255 = 70Hz
10:32 AM cehteh: use a smaller timer divider and set top higher
10:32 AM jancoow: uh.
10:33 AM jancoow: 15625/255 = ~61
10:33 AM cehteh: you have plenty of storage to spare right? simple project
10:34 AM jancoow: yes
10:34 AM cehteh: so you could do a table for the top values
10:35 AM jancoow: why?
10:35 AM cehteh: uint8_t top[255] { 1,1,2,4,6,..whatever }
10:35 AM cehteh: ok you saied you dont care for the logarithmic stuff
10:36 AM jancoow: I don't think it's nececary for a led strip
10:36 AM jancoow: But I could be wrong
10:36 AM cehteh: anyway on each tovf you just calculate wich io shall be on or off
10:36 AM jancoow: yeah exactly
10:36 AM cehteh: puush that out and rinse repeat
10:36 AM jancoow: Okay; I will try to make the code :P
10:37 AM cehteh: you most likely need this log compensation if you want a full, even brightness range
10:37 AM cehteh: when you dont care about the evenness ... then not
10:37 AM jancoow: Let's just see how this works out :D
10:38 AM cehteh: for example brightness 0 (off), 1, 2 will have a pretty visible brightess step (esp 0 and 1 :D)
10:38 AM cehteh: while you wont notice a difference between 254 and 255
10:39 AM cehteh: prolly you wont even notice a difference between 240 and 255
10:39 AM jancoow: right!
10:40 AM cehteh: so you either dont care, or let the sender compensate for that, or code some compensation for that
10:40 AM jancoow: Let's just first get the simple thing work, then check how I could implement the compensation
10:40 AM cehteh: but when you want many brightness steps you also want a reasonable higher resolution becasue many of those steps are not useable
10:41 AM jancoow: yeah exactly
10:41 AM jancoow: then 1024 steps would be usefull
10:41 AM cehteh: input can still be 8 bit but you map that to 10-16bits logarithmically
10:41 AM jancoow: at least more then 255
10:41 AM jancoow: yeah exactly!
10:41 AM jancoow: That's what I thought
10:41 AM cehteh: much more than 255 otherwise you'll see some aliasing
10:42 AM jancoow: you think?
10:42 AM cehteh: depends on the application
10:42 AM cehteh: (and color)
10:42 AM cehteh: changes in green are pretty noticeable, blue and red not so
10:44 AM cehteh: anyway thats where my idea about the lookup table comes into play, you can pretty easily tune the brightnesss curve with that
10:44 AM jancoow: yes I understand :D
10:44 AM cehteh: a table all the same value for example would be no curve/linear
10:46 AM cehteh: also less than 155 values in the table are feasible you just double or interpolate the missing values
11:15 AM jancoow: cehteh: first I'm trying to get the timer to work :P
11:16 AM jancoow: https://jancokock.me/f/59ff1
11:16 AM jancoow: can;t see why the timer interupt isn't triggered
11:17 AM cehteh: you need to to globally enable interrupts sei() .. or whatever that new API uses
11:19 AM cehteh: and all this 0bxxxx things are confusing, i have no idea what you are doing there
11:19 AM cehteh: doesnt this new api provide names for things
11:19 AM cehteh: TOIE0 oe whatever
11:20 AM jancoow: Oh yeah ofcoures.. I totally forgot that
11:20 AM jancoow: and uhm; that represent the bits in the register
11:21 AM jancoow: I really like setting the registers like that, but what do you prefer?
11:23 AM cehteh: something readable
11:24 AM cehteh: UCSR##hw##B = _BV(TXEN##hw) | _BV(RXEN##hw) | _BV(RXCIE##hw);
11:24 AM jancoow: ah yeah
11:24 AM cehteh: hehe .. from a macro here the ##hw gets macro expanded
11:24 AM jancoow: I'm not sure where to find all the value defines
11:24 AM cehteh: and some people prefer (1<<NAME) instead _BV
11:25 AM cehteh: the datasheet names those
11:25 AM jancoow: the 0b00000000 just represents the bits in the register, I really like this method when comparing it with the datasheet
11:25 AM cehteh: thats really not maintainable/readable
11:25 AM jancoow: But I understand that's not readable at all without datasheet
11:26 AM cehteh: whenever you have to debug that shit in a week or 2 you have to look up that register in the datasheet and check what each and every bit means
11:26 AM jancoow: haha
11:26 AM jancoow: But hey! It kinda works
11:26 AM cehteh: also when you use the names the code becomes a bit more portable between AVR chips
11:29 AM jancoow: okay using a 1024 prescaler was definitly a to low value
11:31 AM cehteh: told ya
11:32 AM jancoow: Just measured the voltage on my multimeter
11:32 AM jancoow: Changed the prescaler to 256 and it seems way more stable
11:39 AM circuit is now known as elektrinis
12:02 PM rue_bed: you could run it thru gpp and get it to resolve the macros for ya
12:02 PM rue_bed: jancoow, is it adc?
12:04 PM jancoow: rue_bed: no timer
12:08 PM cehteh: some multimeters have frequency/duty cycle measurment
12:09 PM cehteh: otherwise just measuring voltage on a PWM signal is pretty pointless
12:09 PM cehteh: you may filter it to a DC level but still not whats interesting here
12:10 PM cehteh: when you really want to see, then scope it
12:10 PM jancoow: Or just connect a led strip
12:10 PM jancoow: I'm going to solder all the smd mosfets now
12:10 PM cehteh: yeah, when you dont have a scope
12:11 PM jancoow: unfortinally not
12:11 PM jancoow: I can use the rpi as scope tho
12:11 PM jancoow: :P
12:11 PM cehteh: how that?
12:11 PM cehteh: rpi has no analog input
12:11 PM jancoow: no, but it's a digital signal anyways
12:11 PM cehteh: ah
12:11 PM jancoow: and it can poll pretty fast
12:12 PM jancoow: not sure how fast tho
12:12 PM cehteh: well yes forget about that get one of these 12$ logic analyzers saleae clones
12:12 PM cehteh: they are great and helpful for the price
12:12 PM jancoow: but I used it once to decode an unknown I2C signal :p
12:12 PM jancoow: are they?
12:12 PM cehteh: yep
12:12 PM jancoow: Many people say it's a waste of money and say I should buy a good scope
12:13 PM jancoow: instead of a fairly cheap one from china
12:13 PM cehteh: scope != logic analyzer
12:13 PM cehteh: https://www.amazon.de/Logic-Sekunden-Analyzer-Debugger-Analysator/dp/B07J9PQNZQ/
12:13 PM jancoow: but it can be
12:14 PM cehteh: i meant those
12:14 PM cehteh: of course they dont compare to a 10000$ agilent device
12:15 PM cehteh: *but* they are prolly 10% as useful for 0.01% of the price at least when your signals are slower than lets say 12mhz
12:17 PM cehteh: https://public.pipapo.org/pulseview1.png .. w/ sigrok/pulseview linux software pretty much fun
12:19 PM jancoow: ah yeah
12:19 PM jancoow: that looks pretty hadny
12:19 PM jancoow: I mean; I don't wanna buy a scope of 600 euro's if I only use it a few times
12:20 PM cehteh: scope and logic analyze have pretty different purposes
12:21 PM cehteh: i brought a reasonable cheap bit okish scope .. helped me already a lot and payed its price back
12:22 PM cehteh: when you want some exact timing/measurements then you really need a scope, eventually it helped me with optimization and finding bugs
12:22 PM jancoow: yeah
12:22 PM jancoow: would be pretty handy in this case to
12:22 PM cehteh: well your thing is so trivial, not really :D
12:23 PM jancoow: well the next project is
12:23 PM jancoow: a 230V dimmer with zero cross timing
12:23 PM jancoow: :D
12:23 PM cehteh: shopuld be reasonable simple as well
12:25 PM jancoow: well wanna make that current sensing too
12:25 PM jancoow: so led light bulbs will also dim nicely
01:33 PM rue_shop3: ac current sensing is much easier
01:33 PM rue_shop3: throw 10000 turns on a toroid and your laughing
01:45 PM jancoow: cehteh: ugh. Made another fault in the pcb
01:45 PM jancoow: cehteh: flipped the mosfet footprint
01:45 PM jancoow: cehteh: had to solder all the mosfets upside down..
01:58 PM rue_shop1: pu them on the bottom
01:58 PM rue_shop1: means you can scrw them to a heatsink plate that sits under the board
01:59 PM rue_shop1: -------------
01:59 PM rue_shop1: L=====
01:59 PM rue_shop1: --------------------
01:59 PM jancoow: these are SMD ones
01:59 PM rue_shop1: haha
01:59 PM rue_shop1: yer screwed
01:59 PM jancoow: to-23
01:59 PM jancoow: nah; it works
01:59 PM rue_shop1: so, how about the value of etching your own baords for the first few goes eh?
01:59 PM jancoow: board doesn't look very nice but it works
02:00 PM rue_shop1: mhm
02:00 PM jancoow: well; the first 2 pcb's where great! This one just messed up
02:00 PM jancoow: also got some other faults on this board with the 12V to 3.3V circuit.. Totally used the wrong footprint for the buck converter
02:00 PM jancoow: but with pulling some wires and scratching some traces it works
02:01 PM cehteh: sometimes perfboars is the first choice :D
02:04 PM jancoow: yeah
02:04 PM jancoow: Ah well; lessons learned
02:04 PM jancoow: Pcb
02:04 PM jancoow: Pcb's wheren't that expensive
02:13 PM rue_shop1: Only about $50 for the set?
02:17 PM jancoow: $2 for 10
02:17 PM jancoow: ex components
02:24 PM rue_shop3: with setup and shipping?
02:24 PM jancoow: without shipping
02:25 PM jancoow: But I ordered some other pcbs and all the components there
02:25 PM jancoow: roughly 60 euro for 20 pcbs and all the components
02:27 PM rue_shop1: right
02:27 PM rue_shop1: so, $120 for 20 baords
02:27 PM rue_shop1: ?
02:27 PM jancoow: no, $70
02:27 PM jancoow: including all components and shipping
02:28 PM rue_shop1: these never work out for me
02:28 PM rue_shop1: like vaporware
02:28 PM rue_shop1: I'v tried to get 2 baords done, and each time they ran into problems I couldn't resolve
02:29 PM rue_shop1: or it came out to more than $50 for like 5 or 10 baords
02:38 PM jancoow: okay I did already 5 different designs
02:38 PM jancoow: with no problem at all
02:49 PM jancoow: cehteh: still there?
02:51 PM cehteh: yeah
02:52 PM jancoow: code works :D
02:53 PM jancoow: Set the division on 4 now :P
02:53 PM jancoow: But also no flicker at 8
02:53 PM cehteh: good
02:53 PM jancoow: so wanna implement your color correction table now
02:54 PM cehteh: and brightness range/steps between dim and bright?
02:54 PM jancoow: gonna check that now
03:00 PM jancoow: mmh; only the first 5-10 steps a
03:00 PM jancoow: other then that the dimming looks fine
03:02 PM cehteh: thats logarithmic for you
03:11 PM jancoow: any suggestion how I could implement that?
03:11 PM jancoow: what would be faster; a lookup table or a formula?
03:16 PM cehteh: usually a lookup table
03:16 PM cehteh: when you have the program space or ram to spare
03:17 PM jancoow: https://learn.adafruit.com/led-tricks-gamma-correction/the-quick-fix
03:17 PM jancoow: like this
03:18 PM cehteh: thats far less than 256 brightness levels
03:18 PM jancoow: yeah it jsut maps a 8 bit input to other 8 bit
03:18 PM jancoow: but I want to map 8 bit to 16 bit I guess
03:18 PM jancoow: or 10 bit
03:18 PM cehteh: then that wont work for you
03:19 PM jancoow: unfortinally not
03:19 PM cehteh: you use a 8 bit timer?
03:19 PM jancoow: no 16 bit
03:19 PM jancoow: do you want to see my beautiful code?
03:19 PM cehteh: how much memory can yoou spare for the table?
03:19 PM cehteh: no :D
03:20 PM jancoow: jancokock.me:/f/e5514
03:20 PM jancoow: https://jancokock.me/f/e5514
03:20 PM cehteh: looks lazy, no much code :D
03:20 PM jancoow: the while loop is just a test :P
03:20 PM jancoow: yeah not much code. Only need to program the uart
03:20 PM jancoow: and that's not rocket science either
03:21 PM cehteh: well uint16_t tableTOPvalues[] = { ......}
03:21 PM cehteh: feed that with top values to define each step
03:21 PM jancoow: avr studio says: program memory usage: 382 bytes (9.3% full) and data memory usage: 11 byres (4.3%full)
03:21 PM cehteh: how much do you have on that chip?
03:22 PM cehteh: anyway you can interpolate so even a small table may work
03:22 PM jancoow: 256bytes
03:22 PM cehteh: flash, not ram
03:23 PM cehteh: ok ram may work as well .. but 32 values would already be 64 byte 1/4 of your ram
03:23 PM jancoow: 4kb, sorry
03:23 PM cehteh: usually you better put such a table into flash
03:23 PM jancoow: yeah much faster
03:23 PM cehteh: not faster, but more space
03:24 PM jancoow: uhm when putting it in ram *
03:24 PM cehteh: its not that much faster, fey cycles penality only, wont matter muich here
03:25 PM jancoow: Well..
03:25 PM cehteh: anyway so you have this table somewhere, and just load the next TOP value from that
03:25 PM cehteh: making each step a bit slower (or faster)
03:25 PM jancoow: Well it's accesing the table 9 times per cycle
03:25 PM cehteh: up to 256 steps .. then again
03:25 PM cehteh: huh?
03:25 PM cehteh: nah
03:25 PM jancoow: and it's doing 16000000/4 = 4000000 cycles per second lol
03:26 PM cehteh: once per overflow isr
03:26 PM jancoow: the top value is steady to 0x0001
03:26 PM cehteh: yes thats a bad idea
03:26 PM jancoow: why is that a bad idea
03:26 PM cehteh: change the top
03:26 PM cehteh: because you cant change the step time then
03:27 PM jancoow: That's true
03:27 PM jancoow: but that's impossible because i'm using 1 timer for 9 pwm channels
03:27 PM jancoow: so I can't just dynamicly change the step time
03:27 PM cehteh: you can
03:28 PM jancoow: I don't understand how that would work
03:28 PM jancoow: Did you look at how I currently implemented it?
03:28 PM cehteh: yes
03:29 PM cehteh: just add TOP= table[current_tick]; there
03:30 PM cehteh: thats basically all .. but of course you need the right values in the table and a lower prescaler
03:30 PM jancoow: huh
03:31 PM cehteh: simple or? :)
03:31 PM cehteh: btw what interrupt flag do you clear there?
03:31 PM cehteh: interrupts clear their flags
03:31 PM cehteh: themself
03:31 PM jancoow: the overflow
03:31 PM cehteh: actually this you may miss interrupts
03:32 PM jancoow: This flag is set either on a TOP (overflow) or BOTTOM (underflow) condition, depending on the
03:32 PM jancoow: WGMODE setting. OVF is not automatically cleared and needs to be cleared by software. This is done by
03:32 PM jancoow: writing a one to its bit location
03:32 PM cehteh: huh ok
03:32 PM cehteh: other avr's clear it
03:33 PM jancoow: So I guess that I need to write a one to that register?
03:33 PM cehteh: strange new avr
03:33 PM jancoow: anyhow; I don't get how your solution could work :P
03:33 PM jancoow: so it will dynamicly scale the ticks
03:34 PM cehteh: just do as i say, make a table in PROGMEM with 256 elements .. for a test say all values there to be 64
03:34 PM jancoow: yes
03:34 PM jancoow: so the top value will be set to 64
03:35 PM rue_shop3: I missed the goal, whats it?
03:35 PM cehteh: that should be equal to what you have now
03:35 PM jancoow: yes exactly
03:35 PM jancoow: just set the prescaler on 1
03:36 PM cehteh: so now imagine you have values from lets say 32...128 in that table
03:36 PM cehteh: first steps wil be fast then getting slower
03:36 PM cehteh: spreading the duty cyles over more time
03:37 PM cehteh: rue_bed: bitbanging pwm for 9 led brightness channels
03:37 PM cehteh: rue_shop3: .. from how many coputers are you logged in, get a boucner man :D
03:37 PM jancoow: (wait a sec. My prescaler is 4 atm. So if I lower that to 1, I need to set my top value to 4)
03:37 PM jancoow: not 64
03:38 PM cehteh: just do
03:38 PM cehteh: will become slower yes, you cant go that high speed this way
03:38 PM jancoow: I can set the cpu to 20mhz
03:38 PM jancoow: :D
03:38 PM jancoow: But okay. Let's try
03:38 PM cehteh: well i havengt done the calc
03:39 PM rue_shop3: cehteh, I dont want a bouncer
03:39 PM rue_shop3: thanks
03:39 PM cehteh: prescaler = 4 thats not /4 but the 4th prescaler selected wich is something kiek /256 or?
03:39 PM cehteh: /1 might be to fast
03:39 PM jancoow: DIV4
03:39 PM jancoow: so 16mhz/4
03:40 PM jancoow: that's what I'm currently runnign
03:40 PM cehteh: i dont know that chip you have there, just do the math by yourself
03:40 PM jancoow: 16mhz/8 is also working without flickering
03:40 PM cehteh: and when it slowly blinks yousee it working you can later make it faster again
03:40 PM cehteh: with that little instructions it shouldnt become much slower
03:41 PM cehteh: but faster timer and higher top value gives you more resolution
03:41 PM cehteh: so if you can make the timer as fast as possible and use a higher top
03:42 PM cehteh: and avoid those shifts in the ISR .. or look at the assembler, i bet they are expensive
03:42 PM cehteh: unless gcc optimizes them well
03:43 PM cehteh: i'd double check the generated machine code for that
03:43 PM jancoow: ewhh
03:44 PM cehteh: you may uint8_t out = strip_2_val[2] > current_tick; out = out<<1| (strip_2_val[1] > current_tick); ....
03:44 PM cehteh: PORTA_OUT = out;
03:45 PM jancoow: why would that be any faster?
03:45 PM cehteh: check he machine code, may or may not
03:46 PM jancoow: okay dimming still looks good
03:46 PM cehteh: anyway PORTA_OUT is volatile, i'd rather try to touch volatiles the least possible, not a problem her but in other code it may be
03:47 PM jancoow: ah yeah
03:47 PM cehteh: and shifting (unless optimized) is one bit per instruction, i bet gcc optimizes that there, but i would want to make sure
03:47 PM cehteh: esp since you shift by a constant .. thats usually well optimized
03:48 PM jancoow: cool :D
03:48 PM cehteh: anyway ... now try a table with increasing values
03:49 PM jancoow: so start at what? 0 ?
03:49 PM cehteh: the exact values which give a nice brightness curve are left for excercise :D
03:49 PM jancoow: hahaha
03:49 PM cehteh: nah somtthing higher
03:49 PM jancoow: I can use that adafruit as an example I guess
03:49 PM cehteh: 32,32,33,33,34,34, ....
03:50 PM cehteh: no thats another algorithm that wont work
03:50 PM jancoow: more to see the difference they are using
03:50 PM cehteh: you isr will be waaay to fast and not cope well with small values
03:51 PM cehteh: actually maybe you can leave the table out and just start with TOP=32 or whatever and increase top every 2nd,3rd or 4th ISR
03:52 PM cehteh: not sure but maybe that already works well, worth a try
03:52 PM jancoow: then it would still liniar
03:52 PM cehteh: nope
03:52 PM jancoow: while parabolic would be better
03:52 PM cehteh: because you stretch the time
03:52 PM jancoow: oh
03:53 PM jancoow: understand
03:53 PM jancoow: that sounds.. okay?
03:53 PM cehteh: dunno, try it
03:53 PM cehteh: lots of flexibility to tune it and try
03:53 PM jancoow: and reset it if current_tick == 0
03:53 PM jancoow: ?
03:54 PM cehteh: actually at 255 or when the TOP is buffered even earlier
03:54 PM cehteh: depending on WGM
03:54 PM cehteh: read datasheet
03:54 PM jancoow: wgm?
03:54 PM cehteh: the timer mode
03:54 PM jancoow: oh
03:55 PM cehteh: eh didnt you change the timer mode?
03:55 PM cehteh: // Timer A top 1
03:55 PM cehteh: TCA0_SINGLE_PER = 0x0001;
03:55 PM cehteh: .. is that even effective?
03:55 PM cehteh: because in default mode you cant change the TOP
03:55 PM cehteh: but i dont know that api and i dont kow the chip you have ...
03:56 PM jancoow: the chip is an attiny 414
03:56 PM jancoow: the default mode is "normal mode"
03:56 PM cehteh: i am actually wondering that div/4 isnt waaaay tooo fast
03:56 PM jancoow: I've currently set it to 1
03:56 PM jancoow: :D
03:56 PM cehteh: ok read datasheet again by yourself .. i am not in mood for it
03:57 PM jancoow: understand haha
03:57 PM cehteh: the avr's i know ignore TOP setting in normal mode
03:57 PM jancoow: Thanks you very much already for all the help today
03:57 PM cehteh: iam out now .. have fun
03:58 PM jancoow: In normal operation, the counter is counting clock ticks in the direction selected by the Direction bit (DIR)
03:58 PM jancoow: in the Control E register (TCA.CTRLE), until it reaches TOP or BOTTOM. The clock ticks are from the
03:58 PM jancoow: peripheral clock CLK_PER, optionally
03:58 PM jancoow: rescaled, depending on the Clock Select bit field (CLKSEL) in the
03:58 PM jancoow: Control A register (TCA.CTRLA).
03:58 PM jancoow: When up-counting and TOP is reached, the counter will wrap to zero at the next clock tick. When downcounting, the counter is reloaded with the Period register value (TCA.PER) when BOTTOM is reached.
03:58 PM jancoow: okay! Again: Tahnks for the help and speak to you later :D
04:11 PM rue_shop1: ok whats a clean way to look for a condition going from false to true
08:32 PM davor_ is now known as davor
11:52 PM day_ is now known as day