#avr Logs

Jan 21 2019

#avr Calendar

12:44 AM Emil_ is now known as Guest19888
12:56 AM proteus-guy is now known as proteusguy
01:55 AM aborazmeh_ is now known as aborazmeh
09:51 AM Igloo_ is now known as Igloo
12:26 PM FozzWorth: Hi folks, I'm getting an initialization failed, rc=-1 error from avrdude. This started after trying to program an Arduino sketch to control a peripheral attached via SPI. avrdude -v -F shows that the device signature is not what avrdude is expecting. Is there a likelihood that I've clobbered my fuses?
12:26 PM LeoNerd: How did you last reprogram it?
12:27 PM LeoNerd: Also: far more likely is just some interference of other stuff on the SPI bus
12:27 PM FozzWorth: it's a 328p with external 16Mhz clock. A fresh 328p with internal oscillator is read just fine.
12:27 PM FozzWorth: I last tried to program it using the Arduino IDE
12:27 PM FozzWorth: via USBtiny
12:27 PM LeoNerd: Over ISP?
12:28 PM FozzWorth: yes
12:28 PM LeoNerd: Mm.. do you really mean "external clock"?
12:28 PM LeoNerd: Or do you mean crystal?
12:28 PM FozzWorth: sorry, yes. External crystal
12:28 PM LeoNerd: If you didn't request to write the fuses specifically, then they won't have been changed
12:28 PM LeoNerd: So in all likelyhood it's SPI bus intereference
12:30 PM FozzWorth: So I detached all the SPI peripheral from the chip and avrdude still won't read it.
12:31 PM LeoNerd: Ah, tricky. What does it read, as a signature?
12:31 PM FozzWorth: I confirmed the crystal is still operating at the 16Mhz needed
12:31 PM FozzWorth: avrdude: Device signature = 0x683b6f
12:31 PM FozzWorth: avrdude: Expected signature for ATmega328P is 1E 95 0F
12:31 PM LeoNerd: Hrmmm... that looks more likely just trying to program too fast. Can you ask for a slower bitspeed?
12:33 PM FozzWorth: interestingly, this command line has always been able to successfully pull information from the chip
12:33 PM FozzWorth: avrdude -p m328p -c usbtiny -P usb -v -F
12:33 PM FozzWorth: sorry, without the -Force flag
12:33 PM FozzWorth: I will try a lower bitspeed
12:37 PM vmt: what about bytespeed?
12:37 PM FozzWorth: I just read about bytespeed in the man page. I think that's what I'm after, since I'm not programming via rs232?
12:38 PM vmt: ...gotcha. what about wordspeed?
12:38 PM FozzWorth: or rather, -B bitclock instead of -b baudrate
12:41 PM vmt: wordspeed, helloooo?
12:42 PM FozzWorth: I'm looking for any ref to wordspeed in avrdude man page. I don't follow quite yet. Setting -B5 produces the same result
12:47 PM vmt: dwordspeed might be of interest, too
12:49 PM FozzWorth: I'm afraid that's a bit over my head.
01:14 PM vmt: yeah, that happens sometimes
01:41 PM jancoow: cehteh: hey
01:42 PM cehteh: haha ... found your bug?
01:43 PM jancoow: which bug? :P
01:43 PM jancoow: I didn't continue yesterday, I was going to sleep aswell
01:43 PM jancoow: I do have time to work on it now :P
01:44 PM cehteh: there is a big mistake .. you'll spot it eventually
01:44 PM jancoow: I plotted how the gamma correction of the adafruit source looks: https://jancokock.me/f/506fe
01:44 PM jancoow: err; why not tell me? :D
01:45 PM cehteh: does your DMM have frequency measurements?
01:45 PM cehteh: basically your ISR ignores the timer and just runs almost as fast as it can do
01:46 PM jancoow: how that so?
01:46 PM cehteh: i was wondering why so low prescalers seem to work
01:48 PM cehteh: you clear the interrupt flag at the end .. but whule your code runs your timer would've generated plenty interrupts when you set it at high speed (small prescaler/small TOP value) which just get ignored
01:48 PM cehteh: so your code likely returns from the interrupt and just gets triggered again
01:48 PM jancoow: you think?
01:49 PM cehteh: how many instructions are in your ISR?
01:49 PM cehteh: or better how many cycles would it take?
01:49 PM jancoow: That's something I don't know
01:50 PM cehteh: ISR itself is at least 6 cycles, plus pushing some registers on the stack, plus your code which might be arouund 100 cycles or so
01:50 PM cehteh: just guess ...
01:50 PM cehteh: but when you have the prescaler at /4 and TOP at 1 then you get an interrupt every 8 cycles
01:51 PM cehteh: no way your mpu can handle that
01:51 PM jancoow: ah yeah you are right
01:51 PM cehteh: even a naked interrupt without any code takes longer
01:51 PM jancoow: however when I set the top to 64
01:51 PM jancoow: and a prescaler of 1
01:51 PM jancoow: it also worked fine
01:52 PM cehteh: by chance
01:52 PM jancoow: so that's 16000000/64/256 =
01:52 PM jancoow: roughly 1000hz
01:52 PM cehteh: it basically just runs in a loop, constantly triggered as soon its finished, but dropping/loosing interrupts
01:52 PM jancoow: yeah understand!
01:52 PM jancoow: But a lower refresh rate also works fine without flickering
01:53 PM cehteh: so do your math get it to some sensible frequency. maybe 100hz
01:53 PM jancoow: So it's a good thing that I don't need that high refresh rate
01:53 PM cehteh: yes
01:53 PM jancoow: You think a prescaler of 1 and a top value of 64 is still to much?
01:53 PM cehteh: but the dimming wont work reliable and the uart code wont work wehn you have no processing power left
01:53 PM cehteh: yes
01:54 PM cehteh: dump the asm .. or time the code
01:54 PM jancoow: I can still increase the mcu speed to 20mhz :D
01:54 PM cehteh: that only gives a litte speed improvement
01:55 PM cehteh: first you need to fix the code to work correctly
01:55 PM cehteh: if that then is to slow you optimize the code
01:55 PM jancoow: what can I fix about it? :P
01:55 PM cehteh: by that you may get it twice or more as fast
01:55 PM jancoow: I'm going to change the top now to 128 to see if it's going to flicker more
01:55 PM jancoow: that's around 500hz
01:56 PM cehteh: increasing the frequnecy by 4Mhz isnt much
01:56 PM cehteh: dont try, do the math
01:57 PM cehteh: note that the frequncy is also affected by the values in the table
01:57 PM jancoow: I currently "disabled" the table
01:58 PM jancoow: just to see the effect
01:58 PM jancoow: 500hz still no noticable flickr
01:58 PM cehteh: you really have to figure out how long your ISR takes, that the baseline for the fastest (lowest value) for prescaler and TOP value
01:58 PM cehteh: of course not
01:58 PM cehteh: *but* as long your code is not correct your testing tells nothing because it probably does not run at 500hz
01:58 PM jancoow: ah right
01:59 PM jancoow: so how can I exactly see how many ticks my ISr takes?
01:59 PM cehteh: and you need th time for the shortest 'on' time .. most dim level
01:59 PM jancoow: looking at the assembler mode?
01:59 PM cehteh: thats one way
01:59 PM jancoow: code*
01:59 PM cehteh: counting beans :D
01:59 PM jancoow: I don't have much debug capabilities yet
01:59 PM jancoow: without uart
02:00 PM jancoow: :P
02:01 PM jancoow: I clearly can see flicker when setting the TOP to 256 :P And the main loop code is working faster. So you are totally right. It can't keep up at 500hz
02:01 PM cehteh: most instructions have on cycle, except branches which take 2 cycles, add few more for safety, plus 6 cycles for ISR .. say 10 .. then you get into the right ballpark
02:01 PM cehteh: no need to be exact, but must not be slower
02:01 PM jancoow: where can I see the assembly code
02:01 PM jancoow: is it just the hex?
02:02 PM cehteh: also i asked if your DMM can measure frequency
02:02 PM cehteh: no
02:02 PM jancoow: That's something I'm not sure of
02:02 PM cehteh: well look at ylur DMM does it have a Hz selector?
02:02 PM jancoow: I'm not sure what a DMM is :/
02:03 PM cehteh: digital multi meter
02:04 PM jancoow: oh
02:05 PM cehteh: avr-objdump -S *.elf with * the name of your project or whatever you set up
02:05 PM cehteh: gives asm
02:06 PM jancoow: okay my multimeter doesn't have a HZ selector
02:07 PM cehteh: get a proper one :D
02:07 PM jancoow: however
02:07 PM jancoow: it does have such symbol
02:07 PM jancoow: https://www.amazon.de/Soundex-digitale-multimeter-DM-65/dp/B005657WY6 near the PNP
02:07 PM cehteh: well learn how to use it
02:08 PM cehteh: ok that wont do it
02:08 PM jancoow: yeah not sure what it is :P
02:09 PM cehteh: well you could measure the output frequency ... then decrease TOP until the frequency doesnt drop anymore
02:09 PM cehteh: thats the max speed your ISR can serve
02:09 PM jancoow: yeah it doesn't measure anything
02:10 PM cehteh: you need something to measure the freq .. not that DMM
02:10 PM cehteh: the _-_-_ symbols if for measuring duty cycle (i guess)
02:10 PM cehteh: not frequency
02:11 PM jancoow: yea
02:12 PM jancoow: https://jancokock.me/f/a37ce/
02:12 PM jancoow: this is the assembly :P
02:14 PM cehteh: too mcuh code :D
02:14 PM jancoow: yeah
02:14 PM cehteh: well ideally you make it without branches (should be doable)
02:15 PM cehteh: ah moment .. gcc optimized not that bad
02:16 PM cehteh: branches are always forward as much i see .. and i dont kn ow much about asm either
02:16 PM jancoow: it are a lot of instructions
02:16 PM cehteh: just count the instructions (__vector_8) .. add lets say 20 for safety ... should be good
02:17 PM cehteh: not the exact way to do this but good enough for now
02:17 PM jancoow: do you think that could be optimized?
02:17 PM cehteh: certainly
02:18 PM cehteh: but you optimize at last when everything runs correctly but is too slow
02:18 PM cehteh: make it correct first
02:18 PM jancoow: so with 20 instructions
02:19 PM jancoow: a TOP value of 64 should be duable
02:19 PM jancoow: if I'm not wrong
02:19 PM cehteh: so i count 87 lines .. lets for now just assume thats 87 cycles .. say 100 ... plus 20
02:20 PM cehteh: so 120 cyles is your pessimistic baseline
02:20 PM jancoow: oh sorry
02:20 PM jancoow: so a top value of 128 then :P
02:20 PM jancoow: leaves 8 cycles of uart lols
02:20 PM cehteh: prescaler at /1 and the table smallest value at 120
02:21 PM cehteh: *but* you increase the values in that table
02:21 PM jancoow: yes
02:21 PM cehteh: ah moment thats the code with table lookup disabled
02:21 PM cehteh: of course you need to enable it
02:21 PM jancoow: yes I just wanna say that
02:21 PM cehteh: then count again
02:21 PM cehteh: and get a scope or multimeter with frequnecy measurement
02:22 PM cehteh: makes this much easier when you dont want to count the instructions
02:22 PM jancoow: here it should be enableD: https://jancokock.me/f/30fc0/
02:22 PM cehteh: i just counted the lines .. do that by yourself
02:23 PM jancoow: 87
02:23 PM jancoow: lol wut
02:23 PM cehteh: sure you recompiled?
02:23 PM jancoow: no not really lol
02:23 PM cehteh: may make a difference :D
02:24 PM jancoow: 98
02:24 PM jancoow: :D
02:24 PM jancoow: https://jancokock.me/f/a2609/
02:25 PM cehteh: ok lets still say 128 .. soemthing along that, its just for excercise
02:25 PM jancoow: yeah
02:25 PM jancoow: so that's the minimum I can go\
02:25 PM jancoow: but still, no room left for uart
02:25 PM cehteh: with the table increasing there will be room
02:26 PM jancoow: ah yeah that's true
02:26 PM cehteh: maybe you can just remove the table as i suggested the other day, increase top every 2nd loop
02:27 PM cehteh: but dont forget to reset it to 127 at the end
02:27 PM jancoow: that would require top += (step %2 == 0)
02:27 PM jancoow: or top = 127+(step %2 ==0)
02:27 PM cehteh: if (current_tick&1) ++top;
02:27 PM vmt: jancoow: do you get a lot of flak for your last name?
02:28 PM jancoow: vmt: no
02:28 PM vmt: hmm. you really should
02:28 PM jancoow: However, I've studied for 6 months in NZ. There I never said my last name
02:28 PM cehteh: lol
02:28 PM vmt: ...for reasons which are blatantly obvious
02:28 PM jancoow: Can I help it
02:28 PM jancoow: My parents are farmers
02:29 PM cehteh: esp kock.me :)
02:29 PM jancoow: They never though being in a foreign country
02:29 PM vmt: cehteh: that's what she said
02:29 PM vmt: however, carry on, i'm just passing by
02:30 PM cehteh: i am going to gix my own bugs now
02:30 PM cehteh: fix
02:30 PM jancoow: :p
02:31 PM cehteh: massive rewrite if my UART cdoe to handle multiple uarts and other devices .. but the lineditor has some fuckup doesnt redraw lines correctly
02:33 PM jancoow: cehteh: lol
02:33 PM jancoow: cehteh: this takes 107 instructions
02:33 PM jancoow: 9 more then the table
02:33 PM cehteh: hap shittens
02:37 PM jancoow: :P
02:37 PM jancoow: so it's better to use a table then I guess
02:39 PM cehteh: best is to make it work
02:50 PM jancoow: well the basic code works now
02:50 PM jancoow: with the lookup table
03:27 PM jancoow: cehteh: so yeah dunno what I can do to reduce the instructions
03:32 PM cehteh: good opportunity to learn it
03:32 PM jancoow: yea
03:33 PM cehteh: i had a similar, but much more complex problem few weeks ago, generating signals for stepper motors
03:34 PM cehteh: recalculate the TOP value on each step, doing some actions at positions etc .. and generating signals at 10-20 khz
03:35 PM jancoow: so that's better optimized then my code
03:35 PM jancoow: I think the compares and the shifts can be better
03:35 PM jancoow: but not sure how
03:35 PM cehteh: dont compare, dont shift :D
03:36 PM jancoow: lols
03:36 PM jancoow: yeah thats one solution :P
03:36 PM jancoow: but for real
03:36 PM cehteh: ok you need the compares *but* not all, think about how you can remove them
03:37 PM jancoow: we are talking about the compares for the individual rgb channels, right?
03:37 PM cehteh: for example keeping the times in a sorted array, then you only need to compare against the smallest one and know you dont need to compare the others because they are greater
03:37 PM jancoow: yeah I was thinking about that
03:37 PM jancoow: but sorting an array takes more itterations
03:38 PM cehteh: and the shifts are already optimized out by gcc as far isee
03:38 PM jancoow: which only need to be done once it set by uart
03:38 PM cehteh: yes but you dont need to sort that in the ISR
03:38 PM cehteh: also an full brightness cycle takes 255 steps .. plenty of tiem for the uart
03:39 PM jancoow: don't I only have to flip the bit in the PORT if the value == current_tick
03:39 PM cehteh: if you want cycle precise updates, possibly you dont even need that
03:39 PM jancoow: and flip everything on again when current tick == 0
03:39 PM jancoow: ?
03:39 PM cehteh: yes
03:39 PM jancoow: I guess a == takes less steps then a compare?
03:40 PM jancoow: and no un-needed writes
03:40 PM cehteh: so basically you have a list of up to 9 time values each associated with a port output
03:40 PM cehteh: sorted list
03:40 PM cehteh: then only one compare and output
03:41 PM cehteh: maybe double buffer that list then your uart code can lazily flip it when done
03:41 PM jancoow: but then my uart will be limited; 20-30hz isn't duable then
03:41 PM cehteh: first make it work correct, then optimize
03:41 PM cehteh: even when it flickers and your uart runs at 150 baud only
03:42 PM cehteh: having a correct solution is the best start for optimization
03:42 PM cehteh: wont help you when you optimize the wrong thing
03:42 PM jancoow: yeah that's true. It's just hard to test the speed and stuff
03:43 PM jancoow: I bet the current solution will work fine too
03:43 PM jancoow: but have to implement the uart for that
03:43 PM cehteh: some mesuring device would be handy ... logic analyzer, dmm with frequency counter, scope
03:44 PM cehteh: btw in my code i toggle the led on the board whenever something is busy or a isr is running
03:44 PM cehteh: that gives a good indication how busy the mpu is
03:46 PM jancoow: I could use this on my pi :P http://abyz.me.uk/rpi/pigpio/piscope.html
03:47 PM jancoow: not sure if that can keep up
03:47 PM cehteh: maybe, just be careful not to destroy the pi ... the pi is 3.3V and not all (or none? dunno) inputs are 5V tolerant and its pretty mcuh more fragile electronically than a AVR
03:48 PM jancoow: I know
03:48 PM jancoow: but the attiny runs on 3.3
03:48 PM cehteh: ah ok
03:48 PM jancoow: I also use it to programm the attiny :)
03:48 PM cehteh: then you cant run it at 20mhz or?
03:48 PM cehteh: dunno that part
03:49 PM jancoow: no not at all; I guess max 1mhz
03:50 PM cehteh: nah should be faster than that, well read datasheet
03:50 PM cehteh: the 328 here can do 4mhz at 1.8V .. tinys should be equal or better
03:51 PM jancoow: oh sorry
03:51 PM jancoow: I mis-readed that
03:51 PM jancoow: but yeah; It should be able to run at 20mhz
03:51 PM cehteh: really?
03:51 PM cehteh: if you say so
03:52 PM jancoow: – 16/20MHz oscillator (OSC20M)
03:52 PM jancoow: – 32KHz Ultra Low Power oscillator
03:53 PM cehteh: see 'speed grades'
03:53 PM jancoow: https://jancokock.me/f/5ed01
03:54 PM cehteh: the AVR's i know need 4.5V or more for 20Mhz
03:54 PM jancoow: https://jancokock.me/f/48f00 *
03:54 PM jancoow: you are right.
03:55 PM jancoow: wait.
03:56 PM jancoow: Wait what. It can only run at 10mhz
03:56 PM jancoow: ..
03:56 PM cehteh: :D
03:56 PM cehteh: normally you first read the datasheet before starting a project
03:57 PM jancoow: funny
03:57 PM cehteh: no tonly you dont have enough PWM it also wont run fast enough on your vcc
03:57 PM cehteh: not funny .. harsh reality
03:57 PM cehteh: 'but it was cheap' :)
03:57 PM jancoow: :/
03:58 PM jancoow: yeah idk. It just says 16/20mhz internal oscilator
03:58 PM jancoow: and an input voltage of 1.8-5.5
03:58 PM jancoow: then I would guess it can run on that speed on these values
03:59 PM cehteh: study the datasheet .. i bet its still running at 1Mhz or did you change that in your code?
03:59 PM cehteh: and your guess is wrong
03:59 PM jancoow: uuh
03:59 PM jancoow: I did not
04:00 PM jancoow: I only defined the F_CPU
04:00 PM cehteh: F_CPU does nothing
04:00 PM jancoow: I know :D
04:01 PM cehteh: well somewhere i have some code which checks the configuration of the chip and switches on that
04:01 PM cehteh: anyway i dont know the tiny you use and i wont download and read the datasheet for you
04:04 PM jancoow: haha
04:04 PM jancoow: you shouldn't do that indeed
04:04 PM jancoow: It has some registers where it shows the error in frequency on different voltages
04:04 PM cehteh: i call it a day now ..
04:05 PM jancoow: thats pretty cool
04:05 PM jancoow: yeah me too; gonna get some sleep
04:05 PM jancoow: auf wiedersehen ;)
04:07 PM jancoow: yep you are right it's on 1mhz LOL
04:08 PM jancoow: That explains a lot why the delay function didn't work properly LOL
09:10 PM rue_shop3: didn't test your clock speed first?
09:10 PM rue_shop3: F_CPU just tells the code what the clock rate actually is
11:51 PM day_ is now known as day