#avr Logs

Mar 19 2017

#avr Calendar

12:02 AM z3t0: should uint_16 be used for avr programming or is it fine to just use uint
12:38 AM Chillum: I don't know
12:43 AM Casper: Chillum: is there actually anything that you do know? :D
12:43 AM Chillum: there might be, but I don't know
12:45 AM Casper: that kind of talk remind me of a french song
12:47 AM xentrac: z3t0: you can just use `unsigned` too
12:47 AM xentrac: nowadays I often typedef `s32`, `u32`, `u16`, `s16`, etc.
12:48 AM xentrac: but surprisingly often it's nice to have C code that can deal with more than 65536 items if you're running it under Linux, but not on the AVR where there isn't room anyway
12:48 AM Casper: that song basically say: when I was a kid, I was always saying "I know, I know", but when I got 18 I said "Now I know, this time I know". But now, I realise that I don't know how the world turn. At about 25 I knew everything! Then I learned more. Now that I'm 60, I know one thing: We never know. But that, I know!
12:49 AM Casper: personally, I try to always use uint16_t and the like
12:49 AM Casper: that way, no confusion...
12:51 AM Chillum: I often forgo implied information and make it explicit in programming in favour of clarity
12:51 AM Chillum: I have been accused of using parenthesis to excess
12:52 AM Casper: I love parenthesis too
12:52 AM Casper: and extra spacing here and there
12:53 AM Chillum: this bugged me all day when I first say it: https://xkcd.com/859/
12:54 AM Chillum: I will spare you, here it is )
12:54 AM Chillum: s/say/saw/
12:56 AM Casper: yeah same, somehow
12:59 AM xentrac: I, on the other hand, read IOCCC entries for entertainment
01:05 AM Chillum: )))
01:08 AM Casper: it's annoying sometime in code what a missing ) can do... and where the compiler think the error is
01:11 AM Chillum: ya, error on line 3 hehe
01:11 AM z3t0: hi all
01:12 AM Chillum: good evening folks, I am outa here for the night
01:12 AM z3t0: okay so i have managed to measure the pulse width of a 20ms pulse by saving icr1l and then irc1h << 8 into one uint16_t
01:12 AM z3t0: i do that for each edge
01:12 AM z3t0: and i also have an over flow interrupt that counts the total overflow
01:13 AM z3t0: however i am getting negative values when reading ICR1 which makes no sense to me
01:13 AM z3t0: oddly it seems the only time i get negatives is on overflow
01:13 AM z3t0: are timers signed ? should they not be unsigned? thanks
01:14 AM Casper: nite Chillum
01:14 AM daey_ is now known as daey
01:16 AM z3t0: nevermind i was using itoa instead of utoa
01:16 AM z3t0: avrs are a lot of fun to program haha!
01:19 AM z3t0: okay so i have a question
01:20 AM z3t0: now that i have figured out how to count time using timer1
01:20 AM z3t0: is there any downside to using no prescaler and simply counting overflow?
01:20 AM z3t0: that way i can get the most accurate results from my sensor
01:21 AM Casper: more code, more cpu usage, more ram. If you can live with that then it's fine
01:21 AM Casper: also
01:21 AM Casper: do you get the pulse with a simple "on off" pin?
01:21 AM Casper: if so, check for pin interrupt
01:22 AM Casper: might make the code easier and save on cpu cycles
01:29 AM z3t0: Casper: i do but i need some way to measure its width?
01:29 AM Casper: use the interrupt to start/stop the timer
01:32 AM z3t0: would you mind if i pasted my code to take a quick look at what I am doing?
01:42 AM Casper: I'm going to sleep
01:42 AM Casper: wake up time in 3 hours
01:43 AM z3t0: ok later
04:42 AM Emil: z3t0: did you get it working?
05:55 AM Emil: z3t0: https://emil.fi/jako/koodi/ping.c should work
05:56 AM Emil: I also expect feedback on it
05:57 AM Emil: Leonerd, Lambda_Aurigae, others
05:57 AM LeoNerd: Hi?
06:03 AM Emil: LeoNerd: look at the link
06:03 AM Emil: Tell me your thoughts
06:06 AM Emil: Also, share your uart printing code
06:07 AM Emil: Like ascii decimal printing
10:46 AM thoquz: Has anyone here used an Arduino Uno board as a AVR development board?
10:47 AM thoquz: It seems to work like any other board except for having a built in bootloader over USB, but when I add anything other than main function, even though the other function doesn't get called, the main function ceases to work anymore. Any ideas?
10:47 AM specing: thoquz: anyone who has ever used an arduino uno board?
10:47 AM specing: in other news, water is wet
10:48 AM thoquz: specing: So do you know why I cannot have another function besides a main function on this development board? I'm using AVR-gcc
10:49 AM specing: if you are using the arduino bootloader, do you have the proper startup?
10:50 AM specing: also why not use an ISP and ignore the loader?
10:50 AM thoquz: I'm not familiar with the Arduino bootloader, could you give me a link explaining the proper startup?
10:51 AM thoquz: I could use the ISP, then it would work, but I want to get it working with the bootloader, making it a bit more portable, without having to lug around the ISP too.
10:52 AM specing: you come into an AVR channel and expect us to know wtf the arduino people are doing?!
10:52 AM specing: go to #arduino and get nooobed
10:53 AM thoquz: It's the Arduino bootloader for the AVR, I don't want to use the Arduino software.
10:53 AM specing: It is part of arduino software, even though it isn't running on your PC
10:53 AM thoquz: One more question, is there any defacto standard for performing nanosecond delays besides using NOP's in inline ASM?
10:54 AM specing: Yes, it is "using a processor capable of nanosecond delays"
10:54 AM specing: that means >=1 GHz
10:55 AM thoquz: I'm not saying specifically one nanosecond. I'm saying in the range of nanoseconds, for example 350 nano seconds
10:55 AM specing: NOPs
10:56 AM thoquz: If you read my question, I was asking if there was built in function that calculates it based on F_CPU, instead of using NOP's with inline ASM.
10:56 AM specing: yes, _delay..
10:56 AM thoquz: <util/delay.h> can do float amount of delay, but it's quite off.
10:57 AM thoquz: The tolerance is massive
10:57 AM specing: Did you check disasm?
10:58 AM thoquz: Not yet, you mean to check with GDB after I compile with debugging symbols on?
10:58 AM thoquz: Or are you referring to a specific tool?
10:58 AM specing: the later. objdump
10:59 AM thoquz: Are you implying that I might find a bug which is affecting the _delay functions?
11:00 AM thoquz: Is there a alternative library for calculating the amount of NOP's dynamically from my F_CPU value?
11:01 AM specing: no, I am implying that you might learn what delay is doing and be able to reason about "it's quite off"
11:01 AM specing: not that I know of
11:08 AM Lambda_Aurigae: one NOP takes one clock cycle.
11:08 AM Lambda_Aurigae: if you can't calculate from that I suggest redoing 9th grade math.
11:09 AM Lambda_Aurigae: avr_libc delay function is not super accurage...for doing a half second blinky light it's functional...for doing a few millisecond accurate timing,,,not even close.
11:11 AM Lambda_Aurigae: this is basically common knowledge and documented in dozens of places(if not more)
11:27 AM polprog: thoquz: if you need accurate timing take a look at avr timers.
11:28 AM polprog: Lambda_Aurigae is right, _delay is not very useful for time critical stuff
11:28 AM Lambda_Aurigae: woohoo...I've been right twice in a week!
11:29 AM polprog: ;)
11:31 AM polprog: did he just part?
11:37 AM Emil: polprog: who?
11:37 AM Emil: thoquz: https://emil.fi/avr
11:37 AM Emil: Lambda_Aurigae: grade my code, bitch
11:37 AM Emil: https://emio.fi/jako/koodi/ping.c
11:37 AM Emil: https://emil.fi/jako/koodi/ping.c
11:38 AM Lambda_Aurigae: D-
11:38 AM Lambda_Aurigae: oh, I have to look at it first?
11:38 AM Emil: ;)
11:38 AM Emil: The tasteful thickness of it, the functions without state (hidden inside registers
11:40 AM Lambda_Aurigae: yeah, so?
11:41 AM Emil: Just wondering how'd you go about doing that ping thing
11:42 AM Emil: polprog: if you want to see what forced async code looks like then look at the above link :D
11:48 AM Lambda_Aurigae: Emil, if I were a teacher and critiquing the code, it would lose lots of points for NO COMMENTS
11:54 AM Emil: mfw no comments when full of comments
12:01 PM Lambda_Aurigae: duh...
12:01 PM Lambda_Aurigae: sorry
12:01 PM Lambda_Aurigae: I only saw the first few lines.
12:02 PM Lambda_Aurigae: I need a nap.
12:18 PM Emil: heh
01:10 PM mindw0rk: hey guys, quick question. Atmel ICE in isp + avrdude seems pretty slow by default, anyway to make it faster?
01:17 PM polprog: increase baudrate? i never worked with ICE
01:18 PM polprog: which part is slow exactly?
01:29 PM mindw0rk: yeah baudrate.
02:12 PM NoHitWonder: <enhering>THIS MAY BE USEFUL: If you use Atmel-ICE and avrdude on a mac, and you feel ISP programming is WAY TOO SLOW, set -B 1 on avrdude command line..
02:48 PM mindw0rk: NoHitWonder: thanks, but that seems to screw up the programmer itself, not even trying to get target data :/
02:56 PM mindw0rk: NoHitWonder: ah, target clock was too slow. It worked, thanks.
02:57 PM NoHitWonder: np
04:20 PM z3t0: hi all
04:20 PM z3t0: is it possible to have an interrupt based on an analog value threshold?
04:22 PM xentrac: I think so; what does the datasheet say?
04:26 PM Lambda_Aurigae: not that I've ever seen.
04:27 PM z3t0: theres something called an analog comparator?
04:28 PM z3t0: http://forum.arduino.cc/index.php?topic=17450.0
04:29 PM Lambda_Aurigae: The Analog Comparator compares the input values on the positive pin AIN0 and negative pin AIN1. When the
04:29 PM Lambda_Aurigae: voltage on the positive pin AIN0 is higher than the voltage on the negative pin AIN1, the Analog Comparator
04:29 PM Lambda_Aurigae: output, ACO, is set.
04:29 PM Lambda_Aurigae: you have to have 2 analog inputs for that.
04:30 PM z3t0: ah hence "comparator"... makes sense
04:30 PM Lambda_Aurigae: so, read the datasheet
04:31 PM Lambda_Aurigae: no clue what your forum link says there as I get a 404 error with it...but my firewall blocks that domain.
04:31 PM z3t0: ah okay
04:31 PM z3t0: it just shows someone using the comparator interrupt, but in their instance they might as well just use an interrupt on completing a conversion
04:33 PM polprog: z3t0: what's your aim? to trigger when a pin on AIN0 is higher/lower than the one on AIN1?
04:38 PM xentrac: you could drive the reference pin froma filtered PWM output
04:46 PM z3t0: polprog: im reading a qrd1114 line sensor that needs to know black from white
04:47 PM z3t0: my aim is to interrupt when the value is < x which means white
04:47 PM z3t0: one thought i had was to just figure out the correct pull up resistor i need and then use a digital read instead of analog
04:49 PM xentrac: yeah, you may be able to use a voltage divider or something, but the digital read inputs have I think some hysteresis
04:49 PM xentrac: which may be fine
05:25 PM Emil: z3t0: https://emil.fi/jako/koodi/ping.c
05:27 PM z3t0: Emil: thank you!
05:29 PM Emil: it *should* work
05:29 PM Emil: But I coded it in 30 minutes without any testing
05:30 PM z3t0: you set ocr1a=80
05:30 PM z3t0: how do you get to that number
05:32 PM Emil: It is documented in the code
05:33 PM z3t0: hmm okay its just that when i do ((16000000 / 8) * 0.000005) -1
05:33 PM z3t0: i get 9
05:33 PM Emil: And commented
05:34 PM Emil: z3t0: like I said, commented in 30 minutes :D
05:34 PM Emil: yeah change it to 9
05:34 PM z3t0: haha okay yeah i figured it out
05:34 PM Emil: coded*
05:34 PM z3t0: your ocr1a is meant for no prescaling
05:34 PM Emil: ywah
05:35 PM z3t0: unless, is f_cpu = 16Mhz on your micro?
05:36 PM Emil: but then I checked how long the pulse can be
05:36 PM Emil: I assume 16MHz
05:36 PM Emil: and divisor 8
05:36 PM Emil: so ocr1a must be 9
05:38 PM Emil: z3t0: tell me if it works
05:38 PM z3t0: yeah will do, im testing it right now
05:51 PM z3t0: getting an odd error
05:51 PM z3t0: OCIEA not defined
05:51 PM z3t0: OCIEA1 is also undefined
05:54 PM z3t0: TIMSK1 = _BV(OCIE1A); //Enable compare match interrupt
05:54 PM z3t0: works
06:00 PM z3t0: okay i think it is working now
06:35 PM Emil: z3t0: yeah the names are annoying sometimes
06:35 PM Emil: but it works? Glad to hear
06:35 PM xentrac: yay, congratulations, z3t0
06:35 PM xentrac: and Emil
06:35 PM z3t0: yeah it works!
06:35 PM z3t0: thanks for the help, really
06:35 PM Emil: (it is also coded for m328p)
06:36 PM z3t0: earlier i had an implementation where i had the interrupt working for the edge detection but used a delay for the trigger
06:36 PM z3t0: but yeah using a comp vect is much smarter
06:36 PM Emil: z3t0: also look at https://emil.fi/avr if you are interested in some if the basics
06:36 PM z3t0: will do thanks
06:36 PM z3t0: nice website design haha
06:37 PM Emil: z3t0: the main site is actually designed, that page is like that so that you can curl url | less it ;)
06:38 PM z3t0: ah
06:38 PM z3t0: it looks very nice though
06:38 PM z3t0: i like t he ascii art <3
06:38 PM Emil: xentrac: oh and I was just interested in the challenge ;)
06:38 PM z3t0: what language is that?
06:39 PM Emil: the tld should give it away :D
06:39 PM z3t0: tdl?
06:39 PM z3t0: tld*?
06:39 PM z3t0: ohh
06:39 PM z3t0: yeah my bad haha
06:39 PM z3t0: i thought that was a part of your name
06:39 PM z3t0: like emil fi
06:41 PM Emil: z3t0: it actually is :D
06:41 PM z3t0: should i be concerned about data being corrupted inside interrupts or when accessed outside etc?
06:41 PM Emil: My last name starts with fi
06:41 PM z3t0: cool!
06:42 PM Emil: It's a nice domain hack, though, I agree
06:42 PM Emil: was really surprised it was available
06:43 PM z3t0: :)
06:44 PM z3t0: time to go clean up my code for an hour :)
08:13 PM enhering: Having problems with ATMEL-ICE? There them at ##atmel-ice and help keep the channel
08:15 PM enhering: There = share
08:15 PM z3t0: if you send me one il do that :)
08:16 PM specing: stm32....
08:16 PM enhering: Sure, z3t0
08:16 PM z3t0: lmao actually? enhering
08:16 PM enhering: Send me your address and I'll send you one tonight
08:17 PM z3t0: i cant tell if you're joking
08:17 PM Emil: Is the double speed bit off?
08:17 PM enhering: I can't either.
08:17 PM z3t0: lol
08:17 PM Emil: If your clock is divided by 8 programmming takes ages
08:19 PM Emil: enhering: PL13300, 00076 Aalto, Finland or Otakaari 5, 02150 Espoo, Finland or Otakaari 18 C 70, 02150 Espoo, Finland
08:19 PM Emil: enhering: I'll be waiting
08:19 PM enhering: Seat down, Emil.
08:19 PM Emil: enhering: you promised :(
08:20 PM z3t0: enhering: send me your email and il send my address
08:20 PM z3t0: im also waiting :)
08:20 PM Emil: And I dont have one
08:20 PM z3t0: same
08:20 PM Emil: :/
08:20 PM z3t0: stuck using leds :p
08:20 PM enhering: :/
08:21 PM enhering: I just opened a channel to help other people with ATMEL-ICE problems. Or to share them.
08:22 PM enhering: I took weeks to discover the slow programming speed using avrdude.
08:22 PM Emil: mate
08:22 PM Emil: why
08:22 PM Emil: fragmentation is like, you know, bad :D
08:22 PM enhering: Programming speed was around 10k in 100s
08:23 PM z3t0: what slow programming speed though
08:23 PM Emil: do you have the divide by 8 fuse set
08:23 PM enhering: using avrdude
08:23 PM z3t0: no ida
08:24 PM z3t0: idea*
08:24 PM Emil: z3t0: google "avr fuse calculator"
08:24 PM Emil: burn new fuses
08:24 PM Emil: program faster
08:24 PM Emil: it is mentioned in the https://emil.fi/avr guide
08:25 PM z3t0: self promoting much haha
08:25 PM xentrac: heh, it's amusing that the AVR has a fuse that could be described as a "fast-burning fuse"
08:25 PM Emil: heh
08:25 PM Emil: xentrac: yeah I have no idea wtf is the point of that fuse
08:25 PM z3t0: why would you want to slow down the avr to 8?
08:25 PM Emil: (well, I do, but why as default)
08:26 PM xentrac: to use less power and be able to use a lower voltage (which also lowers power usage)?
08:26 PM z3t0: oh fair point
08:26 PM xentrac: still, if you're really concerned about power usage, you might prefer to not use the AVR
08:26 PM z3t0: in my applications the mc uses negligible power anyways so i guess i neveer actually think about it
08:26 PM Emil: z3t0: I dont even track visitors. Just that thw knowledge you seek is on that page quite well written down
08:27 PM Emil: you can do "cuel https://emil.fi/avr | less" for maximum cli action ;)
08:27 PM Emil: "curl https://emil.fi/avr | less"
08:28 PM xentrac: as far as I know all the AVRs use around 8 nanojoules per 8-bit instruction
08:28 PM Emil: now that's an interesting metric
08:28 PM z3t0: xentrac: is that a made up number? lmao
08:28 PM xentrac: low-power micros like the MSP430 family and the LPC1110 use like 0.9 or 0.3 nanojoules per instruction, and are 16-bit or 32-bit
08:29 PM xentrac: z3t0: I hope it isn't made up! I calculated it from teh datasheet but I can't find my notes right now
08:29 PM Emil: and actually says that slow execution actually increases power consumption
08:29 PM z3t0: ahh ok
08:29 PM z3t0: is it because its not idling as much?
08:29 PM z3t0: or do avrs even idle?
08:29 PM xentrac: so I might be misremembering it or I might have calculated it wrong or the datasheet might be pessimistic
08:29 PM z3t0: probably not?
08:29 PM Emil: xentrac: well yeah, but they dont rock the rock solid development environment ;)
08:29 PM xentrac: I think the ATMega has three power-down modes
08:29 PM xentrac: Emil: true enough
08:29 PM Emil: z3t0: theres idlw
08:30 PM z3t0: ah ok
08:30 PM Emil: what xentrac said
08:30 PM xentrac: and you can power down individual peripherals also
08:30 PM Emil: it is all in the datasheet
08:30 PM z3t0: oh thats cool
08:30 PM z3t0: yeah the 400 page datasheet.....
08:30 PM xentrac: I think the ATTinies only have one
08:30 PM Emil: hehe
08:30 PM xentrac: yeah, you should definitely read the 400 page datasheet
08:30 PM Emil: z3t0: try looking at arm datasheets
08:30 PM z3t0: [insert any question about anything to do with micros] : answer = "read the datasheet"
08:31 PM z3t0: hehe
08:31 PM Emil: suddenly avrs seem like gid tier
08:31 PM Emil: but seriously
08:31 PM xentrac: even if you don't read the whole thing, you should read through the parts that you're using
08:31 PM xentrac: like the timer documentation
08:31 PM Emil: you _have to_ rtfm
08:31 PM z3t0: yeah i generally read through the sections when i need them
08:31 PM z3t0: like timers, adc, interrupt etc
08:32 PM z3t0: opens terminal types 'man life' -> 'life is undefined'
08:32 PM Emil: I usually only read reg descriptions and othrr relevant parts of the doc
08:32 PM xentrac: I read through parts that seem like they might be relevant
08:32 PM xentrac: even when they probably aren't
08:33 PM Emil: But really the circle jerk is there for a reason
08:33 PM xentrac: the pJ/insn metric has remained stagnant for a long time. the SA-1110 already used a nanojoule per instruction back in the previous millennium
08:33 PM Emil: AVR datasheets are so much better compared to many others
08:34 PM xentrac: even MSP430 is only down by a factor of three from that (but features very quick wakeup times, so you can get very low duty cycles)
08:34 PM xentrac: the GreenArrays chips are dramatically better in theory but they are hard to program
08:34 PM Emil: z3t0: what modifications did you do to the codr btw?
08:35 PM xentrac: and there are a couple of sub-10-picojoule-per-instruction processors in the academic literature but nothing in production
08:35 PM Emil: The academia is full of low power micros
08:36 PM xentrac: at 10 pJ/insn you can run at 10 MIPS at 0.1 mW
08:36 PM Emil: Many of my friends have played with their "own" design and achieved quite nice perf
08:38 PM xentrac: Emil: fabricating silicon via CMP, or what?
08:40 PM xentrac: this 20-gram cellphone Li-ion cellphone battery is rated as 930 mAh at 3.6V; draining it at 0.1 mW it would theoretically run for 45 months (though I think its self-discharge is faster than that)
08:41 PM xentrac: so being able to get down into that 10pJ/insn range is really exciting
08:41 PM z3t0: Emil: well first i removed all the 1<< with _BV() :p
08:41 PM z3t0: and then removed the prescaler for more accurate results
08:42 PM xentrac: but apparently either that's harder than it sounds in the papers or it is a lot less exciting to NXP, Microchip, etc., than it is to me
08:42 PM z3t0: added an overflow counter, given that theres no prescasler
08:42 PM z3t0: that was about it
08:42 PM z3t0: i can make a paste bin if you want? I didnt change that much really
08:43 PM z3t0: also i dont like writing directly to registers, so i replaced = with &= and |= where applicable
08:45 PM xentrac: the Landauer limit at room temperature is about 2.8 zeptojoules per bit erasure, so even the 10 pJ level is about eight or nine orders of magnitude away from the fundamental physical limit
08:45 PM z3t0: is there any way to get more useful feedback from a c compiler? especially as it has trouble when a single ; is missing and i have to scour through the whole file
08:46 PM xentrac: usually gcc will tell you what line and character your ; is missing on
08:46 PM xentrac: if you're running it under Emacs or similar, you can click on the error message and jump to the line
08:47 PM xentrac: a missing } can be more problematic in that sense
10:23 PM LoRez: anybody play with the digispark?
10:24 PM LoRez: I'm trying to work out how to get some 4-wire PWM fans under control. Need the PWM freq to be up in the 25-28kHz range AFAICT
10:50 PM Casper: 20kHz
10:51 PM Casper: 30-100%, 0-5V signal
10:58 PM LoRez: yeah, and I can either get 1k-ish or 32k-ish
10:58 PM LoRez: I think it's using the timers for the USB bit-banging
10:59 PM Casper: but the timing seems to be very forgiving actually
10:59 PM Casper: I think they mostly just average the pulse and then use an analog circuitry inside