#avr Logs

Oct 29 2018

#avr Calendar

01:02 AM day__ is now known as day
01:10 AM rue_bed: --
01:11 AM rue_bed: so, 4 hobby servo pwm channels under 9600 baud serial still seems to be a challange for a tiny13
01:12 AM rue_bed: the duality between the serial timing and the pulse timing is defeating me
04:55 AM thardin: hot tip, you can space pwm pulses quite far apart
04:55 AM thardin: or you know, use a better micro
06:20 AM specing_ is now known as specing
09:16 AM rue_mohr: --
09:16 AM rue_mohr: thardin,
09:17 AM rue_mohr: changing the 20ms spacing alters the feedback level for standard hobby servos
09:17 AM rue_mohr: and, its a tech challange
09:17 AM thardin: oh? I haven't had that problem
09:18 AM rue_mohr: I can do it if I dont care about the jitter
09:18 AM rue_mohr: I want to keep the output timing jitter the same as the tiny13s clock jitter
09:19 AM thardin: then you might have quite a tricky thing on your hands
09:19 AM rue_mohr: its a little puzzle
09:19 AM thardin: the timers can be used to toggle pins, right?
09:19 AM rue_mohr: yes, but not 4 different pins
09:20 AM thardin: right. well, timer interrupt then perhaps
09:20 AM rue_mohr: so, I could do 2 channels
09:20 AM rue_mohr: but I want 4 channels
09:20 AM thardin: your ISR only has to do PORTA = 0; or so
09:20 AM rue_mohr: agreed
09:20 AM rue_mohr: so, what if that happens in the middle of the serial RX interrupt
09:21 AM thardin: don't do serial in interrupts?
09:21 AM thardin: also, one of them is likely to be higher prio
09:21 AM rue_mohr: 9600 baud, I'm using the ADC conversion complete as a timing interrupt for the serial
09:21 AM rue_mohr: the tiny13 has no uart
09:21 AM thardin: oof
09:22 AM rue_mohr: mhm
09:22 AM thardin: well, you can probably use a timer for that too
09:22 AM rue_mohr: its like one of those wire puzzles
09:22 AM thardin: how many timers does it have?
09:22 AM rue_mohr: it has 1 8 bit timer
09:22 AM rue_mohr: with 2 compare channels
09:22 AM rue_mohr: BUT, I can use the adc conversion complete as a timer
09:22 AM rue_mohr: cause, for this project, I dont need adc
09:23 AM rue_mohr: the adc generates an interrupt every 13 or 14 cycles (its constant, I'm just not sure)
09:23 AM thardin: mkay. so you can set that up at say 500 Hz. set PORTA=0 on compare, then count the number of overflows for sequencing channels
09:23 AM rue_mohr: and you can divide its clock by whatever
09:24 AM rue_mohr: yes, I wanted to avoid having to count overflows, but yea
09:24 AM thardin: maybe count time between uart transitions or something
09:25 AM rue_mohr: the other thing is that if I use the output match compare, and dont reset the counter value, I have a bit of jitter in the compare interrupt
09:26 AM rue_mohr: so, I'm still chewing on it
09:26 AM thardin: tricky
09:27 AM rue_mohr: but, int he process of working on it, I'v learned how touse the adc as a timer
09:28 AM rue_mohr: and I'v got 3 versions of serial rx code, one that uses the main timer counter, one that uses compare registers, and one that uses the adc
09:29 AM rue_mohr: and I'v uncovered a mystery, in almost all cases the avr seems to be running at half the clock it seems it should be
09:29 AM rue_mohr: 4.8M instead of 9.6M
10:49 AM merethan_w: I want to use functions in my writings to reuse one piece of code in multiple places, and for readability´s sake. The performance penalty however is problematic. Should I solve this with declaring functions inline?
10:49 AM cehteh: depends, inline may bloat
10:50 AM cehteh: and gcc is pretty smart about inlining when optimizing, iirc it mostly ignores inline except for its semantic effects
10:51 AM cehteh: you may experiment with link time optimization, sometimes that gives a big benefit, sometimes not
10:52 AM merethan_w: When I look at my compiler output, it pushes everything on the stack, writes to one register, and pops the stack back down. Yes, for a function writing a value to a register. (Which, again, is only written like that for readability and code reus purposes.)
10:53 AM merethan_w: I could be overlooking something here :P
10:53 AM cehteh: do ypu turn optimization on?
10:53 AM cehteh: i mean normal one -O2 or -O3
10:53 AM cehteh: and the register is tagged as volatile right?
10:53 AM merethan_w: It is on -O2
10:54 AM cehteh: that prevents some optimization
10:54 AM cehteh: try w/ inline and see if it helps, may or may not
10:54 AM cehteh: also try -flto
10:54 AM merethan_w: void dac_output(uint16_t raw) { DACA.CH0DATA = raw; }
10:54 AM cehteh: (compile and link)
10:55 AM cehteh: DACA.CH0DATA << is somewhere defined as volatile
10:55 AM cehteh: you use that function from different source files?
10:55 AM cehteh: for inlining to be effective you need to move it to a header and declare it as static inline
10:57 AM cehteh: just inline wont help when the function is used from elsewhere where its definition isnt known at compiletime, actually it would be worse, it has still to be emited as callable function then and from within the same source it would be inlined, so you get bloat + external function calls :)
10:58 AM merethan_w: lol
10:58 AM cehteh: well that function wont bloat anyway
10:58 AM merethan_w: I ´ll use the inline kw in the header
10:58 AM cehteh: you need static inline
10:58 AM cehteh: and define it there, not only declare
10:59 AM cehteh: but when you prefer such a coding style (which isnt bad) you may really try -flto which can help a lot
11:15 AM merethan_w: Oh damn defining things in the header gets really messy
11:18 AM cehteh: so, try -flto
11:41 AM merethan_w: So, if I understand this thing correctly, -flto and defining functions inline on declaration only should work?
11:44 AM merethan_w: If that be the case, I might have the perfect solution for my needs :)
11:57 AM Rickta59: the godbolt thing is useful for trying out different coding approaches
11:57 AM Rickta59: https://godbolt.org/z/KO_U0M
11:59 AM Rickta59: you can get the same effect as static if you use an anonymous namespace
12:17 PM merethan_w: I´ll try that later Rickta59. Tnx.
12:19 PM cehteh: merethan_w: -flto is independent from inlining
12:20 PM merethan_w: Then I misunderstood it.
12:20 PM cehteh: pushes a lot optimization to link time where the optimizer has a broad view over the whole program
12:20 PM cehteh: looks like someone puts it in a mixer and then reassembled it afterwards :D
12:37 PM merethan_w: I´m confused on what it is you are advising me to do. Given I prefer not to include definitions in my headers, you say I should use the -flto switch and have the compiler/linker sort it out, instead of doing inline static, right?
12:38 PM merethan_w: (@ cehteh )
12:38 PM cehteh: these tips are idependent of each other
12:38 PM cehteh: try -flto (at compile AND link time)
12:39 PM cehteh: see if it improves the code even when the function was only 'normal' declared/defined and not inlined
12:39 PM cehteh: also try -Os
12:40 PM cehteh: if nothing helps use a static inline function or hide it behind a macro
01:20 PM merethan_w: Mm I will look into the output of my compiler later. I´m going to wrap up for today.
01:20 PM merethan_w: Tnx for help!
02:31 PM Smashcat: Hi, I'm using Atmel Studio with an ATMega328PU, but cannot program it - it fails with "Got 0xCC, expected 0x00". This is the second chip I've tried, so wondering if I have a bad batch. Using the ATMel ICE programmer. It works fine on an identical board with an ATMega328P
02:32 PM Smashcat: (I've just thrown away another board with the same issue, so now wondering about throwing the whole waffle tray out, if the chips are all bad.
02:33 PM Smashcat: Checked all the pins and connections are all good to chip - it has power, and ISP pins are all ok. The board does have a 16mhz crystal connected, even though that chip should be running at the default 1mhz at the moment.
02:35 PM Smashcat: Oh FFS, the IDE kept resetting the ISP clock to 1mhz... Just edited the project file and now it's ok...
08:35 PM [1]MrMobius is now known as MrMobius