#avr Logs

Oct 02 2019

#avr Calendar

01:47 AM jmorris: how can I set a pin on the microcontroller to logic high?
01:52 AM jmorris: I tried DDRC = (1<<0)
03:40 AM julius: vmt, #1 of avrs is you do not talk... i mean use *alloc - does that continue with rule #2 you do not talk about avrs? ;)
03:49 AM cehteh: morning
04:48 AM skz81: julius, rather : "Rule 2: you do not talk about #avrs"
04:49 AM julius: ah i see
04:49 AM julius: but still, its from fight club
04:50 AM skz81: Yeah, caugth the reference ;°)
04:53 AM julius: i still dont get how this guy [1] gets to display a temperateure in degree celsiuis with this formula: float celsius; celsius = (ADC_Read(0)*4.88); celsius = (celsius/10.00); the adc is in 10bit mode, so he would get a number like (512 * 4.88) / 10 = 249.8 or is there some magic in this line: sprintf(Temperature,"%d%cC ", (int)celsius, degree_sysmbol); that moves the dot one to the left? [1]: http://www.electronicwings.com/avr-atmega
04:53 AM julius: /lm35-temperature-sensor-interfacing-with-atmega1632
04:58 AM cehteh: using floats on a avr is already a bad idea
04:58 AM cehteh: at least for that
05:07 AM julius: right, the adc returns 0....1023
05:08 AM julius: but with the multiplication he ends up with a float, right?
05:13 AM cehteh: yes
05:16 AM cehteh: still you can do all caclulations in integer and you can/should oversample a bit toi get more precise results
05:17 AM cehteh: you can add up to 64 times without overflowing a 16 bit uint, rolling average
05:18 AM skz81: sumthing like (adc*488)/1000 will give the same result, furthermore given it is rounded at printing
05:18 AM cehteh: i wont even do something like that
05:18 AM skz81: (adc/1000)*488 ?
05:18 AM cehteh: initialize with: temp = adc * 64;
05:19 AM julius: yes its the same result, but i was expecting to see a degress celsius value and not: (512*488)/1000 = 249.856
05:19 AM cehteh: then on each iteration temp = temp - temp/64 + adc;
05:19 AM skz81: julius, that seems hot, even in farenheit
05:19 AM cehteh: that gives a full 16 bit oversampled result with rolling average
05:19 AM julius: skz81, yes i believe its wrong
05:19 AM cehteh: 0..65535
05:20 AM julius: skz81, i made up the 512
05:20 AM cehteh: to get celsius (or 1/100, 1/1000 °C or whatever you need) you need one divison
05:21 AM cehteh: maybe little more when you want to split integer/fractional parts for printing
05:21 AM Smidge204: That seems cold, goven in Kelvin
05:22 AM skz81: cehteh, ok got what you're doing, unsure why last measure weigths more that previous ones. Does solve the volt to degrees convertion.
05:22 AM skz81: Mine stays on integer domain that's just the point
05:22 AM cehteh: there are datasheets for the lm35 which explain how you translate the sensor value to °C or whatever
05:22 AM skz81: anyway, burger ready, see you later :)
05:23 AM julius: skz81, happy hunting
05:24 AM julius: yes, 1 degree celsius is 10mv
05:24 AM cehteh: oversampling helps a bit when you want to increase precision together with noise which make the LSB fluctuate you get closer
05:25 AM julius: true, i read about that
05:25 AM cehteh: ideally you sweep the AREF on 1LSB .. my code above is a gross oversimplification, but its extremely easy and yield much better results already, thats the minimum one should use
05:26 AM julius: yes but i dont get it :I(
05:26 AM cehteh: also turn on the internal 1.1V AREF and measure against that, not VCC because VCC is shit
05:26 AM julius: why do you multiply by 64?
05:26 AM cehteh: just to initialize it
05:27 AM cehteh: you can do for (i = 0; i<64; ++i) temp += adc; as well
05:27 AM julius: yes that should do the same
05:27 AM cehteh: actually when you start up you should throw away the first few adc reads because the AREF isnt stable yet
05:28 AM cehteh: so in real code i do for (i = 255; i; --i) if(i<=64) temp += adc;
05:29 AM cehteh: where adc is a single sensor read of course, not just the ADC value
05:29 AM cehteh: but, thats only needed when you need stable/exact temperature values from start on
05:29 AM djph: cehteh: you really need to go through 192 loops before the aref is stable?
05:30 AM julius: i also read about that,makes sense
05:30 AM cehteh: otherwise it will be simpler just to do temp=adc*64 and expect it to settle within a few iterations
05:31 AM cehteh: djinni_: no you dont need 1-2 is enough, but sometimes i just dont care about the starttup time and that makes it easier to replace the oversampling factor (8, 16, 32, 64)
05:31 AM cehteh: djph: ^
05:32 AM djph: AH
05:35 AM julius: temp = temp - temp/64 + adc; <- wouldnt it be easier to: initial: temp = adc; and now loop: temp = temp + adc and after the loop divide trough the runs?
05:36 AM cehteh: rolling average you dont need to wait 64 measurements for the next result
05:40 AM julius: but still, you need some new measurements or youre just guessing data
05:41 AM cehteh: thats why its initialized with adc*64 .. the first measurement is already as correct as your adc/sensor is, just not oversampled yet
05:41 AM julius: oh wait, right, moving average makes that
07:03 AM skz81: ouch misread your code cehteh. I read like temp = temp/64 + adc => Nth value in chrono. order of reads should then be weighted 1/(64^(M-N))
07:03 AM skz81: w/ M then total nb of reads
07:03 AM skz81: erm. with M: the to nb of reads
07:03 AM skz81: ok i give up :p
07:06 AM cehteh: mhm?
07:07 AM cehteh: its a bit dirty math, donno how its named, because it substracts the current average rather than the oldest value, still works reasonable
07:08 AM merethan_w: Averaging & stuff: https://hackaday.com/2019/09/06/sensor-filters-for-coders/
07:09 AM cehteh: merethan_w: the idea is that one doesnt needto keep an array
07:10 AM merethan_w: There´s a few options in there for that too.
07:10 AM merethan_w: Like sliding average
07:10 AM cehteh: as shown above
07:11 AM merethan_w: Thereś other ones too.
07:11 AM merethan_w: Also see comments there. Lots of intruiging bits.
07:11 AM cehteh: sure
07:12 AM cehteh: but not much thats simpler
07:13 AM cehteh: if course as almost any filster, esp simple filtering you get some phase shift/lag .. but for temperature measurments or any masurement where your sampling frequency can be way above the system frequenency it wont matter
07:40 AM merethan_w: Are there some .elf tools recommended? I got one .elf with bootloader, fuses and lockbits. And another .elf with appcode. I want to combine them to make production-programming a little more idiot-proof.
07:43 AM cehteh: dont you need to relink them?
07:53 AM Kliment: merethan_w: avr-objcopy can do that
07:53 AM Kliment: merethan_w: extract, combine, etc different .elf files
07:56 AM merethan_w: Is this supposed to be pasrt of avr-gcc toolchain Kliment?
07:56 AM merethan_w: The one installed by Atmel Studio
07:59 AM Kliment: merethan_w: not sure, I use Linux
07:59 AM merethan_w: I wish I did too
07:59 AM Kliment: merethan_w: it's part of avr-bintools, which should be included
07:59 AM Kliment: merethan_w: but check if it's on your system
07:59 AM merethan_w: It is. Tnx.
08:00 AM merethan_w: Unfortunately I am sort of forced to use windows during my employment hours. I prefer a linux box.
08:01 AM Kliment: if it's W10 it comes with builtin linux
08:16 AM merethan_w: Can you give me some hints on how to use objcopy Kliment?
08:16 AM merethan_w: I´m trying to understand its help output but so far it confuses me.
08:26 AM Kliment: merethan_w: what exactly are you trying to do?
08:28 AM Kliment: merethan_w: I think this might help you https://www.avrfreaks.net/forum/combining-hex-files
08:28 AM merethan_w: I got one .elf with bootloader, fuses and lockbits. And another .elf with appcode.Both produced by avr-gcc. Now I try to merge them. Meaning .text .data and .bss need to be merged.
08:29 AM merethan_w: And .fuse and .lock be carried over unchanged.
09:27 AM cehteh: mhm as long you dont need to relink parts, objcopy is the tool
09:29 AM cehteh: but i rather do the opposite, my toolchain generates a .elf and i cut out the app.hex and the eeprom.hex
05:21 PM julius: something is wrong with these 8 lines of code: https://bpaste.net/show/_CWJ my bluetooth app isnt receiving data from that loop. but i can send the avr a 'a' to blink a specific led, so the rest of the code works
05:21 PM julius: any ideas?
05:27 PM cehteh: what does USART_transmit() do? ,, do you need to check if there is buffer space available before you call it?
05:27 PM cehteh: and usart may send directly, but maybe you receiving side is line buffered you should send a newline
05:28 PM julius: shit, i just roasted a lm35
05:29 PM cehteh: lol
05:30 PM cehteh: i somewhere read yesterday "when you connect it wrong then it burns" :)
05:30 PM julius: https://bpaste.net/show/pp8w
05:30 PM cehteh: ew blocking
05:31 PM julius: those morons at ti printed the bottom view for the chip i bought. they printed 3 top views and one bottom...great
05:31 PM julius: http://www.ti.com/lit/ds/symlink/lm35.pdf - page 3
05:31 PM cehteh: and you want \r\n after you send all 4 bytes 1234\r\n
05:31 PM cehteh: not after each one or?
05:31 PM julius: right, that code was used before when i was just sending one char
05:32 PM julius: but it should send something
05:32 PM cehteh: i am doing interrupt driven io
05:37 PM cehteh: your code looks right on a first glance
05:38 PM julius: im reading up on interrupts right now
05:38 PM cehteh: what happens when you: USART_transmit('X'); USART_transmit('\r'); USART_transmit('\n');
05:39 PM cehteh: https://git.pipapo.org/?p=muos;a=blob;f=hw/atmel/avr/serial.c;hb=refs/heads/devel#l185 << my serial driver stuff
05:39 PM cehteh: well there is bit more in the back, this the cbuffer impementation for cyclic buffers etc
05:41 PM cehteh: https://git.pipapo.org/?p=muos;a=blob;f=serial.c;h=a077ee5eb5fca0053d8aa8588911745e3ed48596;hb=refs/heads/devel#l97
05:41 PM cehteh: thats queueing a single byte to the buffer
05:51 PM julius: ok, i for got to call ADC_init()
05:51 PM julius: now it is sending data
05:51 PM julius: with the lm35 connected its 1023 all the time, so i guess it has been a bit to hot for that chip
05:53 PM cehteh: lol
05:53 PM julius: when nothing is connected to pa0 its around 250
05:53 PM julius: 350
05:53 PM cehteh: do you use the internal 1.1vref instead VCC for measureing?
05:53 PM cehteh: noting ocnnencted means floating, that can be anyting
05:55 PM julius: no, the example started with avcc and i know you said to use internal, but i wanted to get something working first before tinkerin gwith the code
05:55 PM julius: im just wondering why floating is so constant
05:55 PM julius: its between 340 and 350
05:55 PM cehteh: ok, well you need to change the input then to be in the right range (voltage divider)
06:13 PM julius: i have no more lm35's lying around so they are safe from me, but i found some: https://github.com/Jacajack/avr-ds18b20 sensors
06:13 PM julius: gonna try them tomorrow
06:13 PM julius: thanks for the help
06:22 PM cehteh: i wondered why you dont use the ds18b20 at first because those are much easier to use :D
06:55 PM julius: the lm35 sounded easier to me
06:55 PM julius: for the other one you need a library
06:57 PM cehteh: btw there is a buildin temperature sensor in AVR's you can use it to develop the driver and test it
11:09 PM rue_mohr: lm35 is easier
11:48 PM day__ is now known as day