#avr | Logs for 2016-01-19

Back
[02:02:58] <Martin90> Can we do Context switching in atmega16 ?
[04:00:44] <phinxy> when setting variables to eeprom values (read) do you need a wait while busy between the variables?
[04:27:51] <pepijndevos> Are there any sleep modes where PWM and timer interrupts keep working?
[04:28:07] <pepijndevos> (atmega328p)
[04:32:11] <Xark> pepijndevos: IIRC, SLEEP_MODE_IDLE
[04:32:27] <pepijndevos> Will try.
[04:33:02] <Xark> http://www.engblaze.com/hush-little-microprocessor-avr-and-arduino-sleep-mode-basics/
[04:33:43] <pepijndevos> The datasheet only mentions Timer2 as a wake up source.
[04:33:52] <Xark> (and if you want a "deep dive" http://www.gammon.com.au/forum/?id=11497 )
[05:30:58] <phinxy> <pepijndevos> i went trough that yesterday
[05:31:21] <phinxy> its IDLE you want, all clocks run in that mode and all interrupts will wake up
[05:31:58] <phinxy> if you want to save more power like with mode POWER_DOWN you could use the timer2 but its only a 8bit timer
[05:32:40] <phinxy> or the watchdog timer also works but its not accurate
[06:00:14] <phinxy> im making a tachometer for a motorcycle, is a timer interrupt each millisecond enough accuracy?
[06:00:51] <phinxy> i guess its not easy to answer without any more data like wheel circumference or so..
[06:32:30] <Flutterbat> phinxy: timer interrupt? how are you measuring the speed? it sounds like an magnetic/optic approach as its used on bikes.
[06:32:45] <Flutterbat> i would wire the interrupt to the sensor and not the timer :/
[06:33:20] <phinxy> its an interrupt
[06:33:30] <phinxy> but i need a timer to measure actual time in between
[06:33:35] <Flutterbat> yeah and?
[06:33:53] <phinxy> ..and im trying to figure out how fast the clock needs to tick
[06:33:54] <Flutterbat> sensor triggers interrupt > read timer; reset timer
[06:34:05] <phinxy> i figured 10,000 ticks per second should be enough but im not sure if i calculate correct
[06:34:39] <Flutterbat> how slow do you want to be able to measure?
[06:35:05] <Flutterbat> you could always do it dirty by overflowing into a variable
[06:35:38] <Flutterbat> at least i assume a 16bit counter should itself offer enough resolution
[06:38:56] <phinxy> i just figured i want to be able to have some resolution between rising and falling edge
[06:39:08] <phinxy> so i could compare ratio between a magnet and the actual distance
[06:40:10] <Flutterbat> well depending on what exactly you measure i think you can go a bit faster than 10k/sec
[06:40:12] <phinxy> so each third tick ill do a check if the ratio is correct. 8:31,4
[06:40:38] <phinxy> with 10k/sec each 4mm traveled is a tick and the magnet is 8mm
[06:40:41] <phinxy> at 200km/h
[06:40:54] <Flutterbat> you have 2^16 available. unless you care about speeds at 6+s/360°
[06:42:43] <phinxy> i guess if the rising and falling edge happens at the "same time" i just assume the next tick is the distance.
[06:43:27] <phinxy> i want a little control because i think sometimes the sensor does only send one tick instead of two per magnet
[06:47:31] <Lambda_Aurigae> it's a balmy 256.317Kelvin here today.
[06:47:51] <Lambda_Aurigae> sensor has to engage and disengage.
[06:47:57] <Lambda_Aurigae> it is going to do two per.
[06:48:12] <Lambda_Aurigae> it can't engage, then engage again, without disengaging in between.
[06:53:04] <phinxy> is 256 oscillations enough to set a uint16_t ?
[06:53:42] <Lambda_Aurigae> uint16_t will hold a number up to 65535....not sure what your question is though.
[08:33:39] <phinxy> Is there a CPU flag for when a overflow happens when subtracting?
[08:34:00] <phinxy> i mean when adding
[08:34:40] <LeoNerd> O
[08:34:44] <phinxy> ty.
[08:34:55] <LeoNerd> Er.. V, even
[09:17:24] <nuxil> <Lambda_Aurigae> it's a balmy 256.317Kelvin here today.
[09:17:35] <nuxil> its about 253.1 here :D
[09:18:47] <nuxil> one big sniff of air with my nose and all my buggers are ice :p
[11:11:40] <cehteh> yay .. logic analyzer arrived, works
[11:12:02] <nuxil> :)
[11:12:37] <nuxil> what brand?
[11:12:47] <nuxil> how much did you pay for it?
[11:14:51] <cehteh> 17 Eur salae clone :D
[11:16:51] <nuxil> 17€ isnt bad. did come with cables and thouse small grabs/claws on them,, or whatever its called.
[11:17:44] <cehteh> some cheap plugs, but i have clips in the workshop, while actually i am using it on a breadboard, just with pins
[11:18:05] <Chillum> I have a cheapo $7 one coming, I figure even if it sucks it can't be worse than whatever else I would spend $7 on
[11:18:42] <nuxil> hehe .. true enuf
[11:19:01] <cehteh> http://public.pipapo.org/logic_analyzer.png
[11:19:02] <nuxil> Chillum, ordered from china ?
[11:19:24] <cehteh> http://www.amazon.de/gp/product/B00DPCDEV2 that one, prolly the same you get for $7
[11:19:48] <Chillum> nuxil: hong kong, soo yes. www.ebay.ca/itm/331736423509
[11:20:11] <Chillum> looks like it cehteh
[11:20:11] <cehteh> yes same one
[11:20:19] <nuxil> Leider kann dieser Artikel nicht nach Norwegen,, what does that mean,.. something about norway
[11:20:24] <cehteh> so far, first test, works nicely as is
[11:20:38] <cehteh> wont ship to norway
[11:20:42] <nuxil> darn
[11:20:49] <cehteh> german amazon, try amazon.no
[11:20:50] <Chillum> as long as it analyses signals I am happy
[11:20:53] <Chillum> don't need high speed
[11:21:02] <Chillum> not right now
[11:21:11] <nuxil> cehteh, is software included ?
[11:21:40] <cehteh> nah i am free linux software
[11:22:05] <cehteh> someone here ( Lambda_Aurigae ?) recommended that all.
[11:35:53] <phinxy> why does this output 0
[11:35:54] <phinxy> tmpcalc = (36/2000) * 320;
[11:37:06] <nuxil> cos ..(36 / 200) == 0.018 . which is rounded to 0
[11:37:10] <nuxil> use double/float
[11:37:23] <cehteh> callulate the other way around
[11:37:38] <cehteh> 36*320/2000
[11:37:59] <cehteh> (but be aware of overflows)
[11:38:27] <phinxy> no need to include any libraries for floating point math or anything?
[11:38:50] <cehteh> floats on avr suck
[11:39:07] <cehteh> it has no floating point unit, that needs a shitload of code and is slow
[11:39:08] <LeoNerd> You generally don't want to be doing floating-point maths on an AVR
[11:39:18] <LeoNerd> Stick to fixedpoints, ideally scaled integers
[11:39:28] <cehteh> exactly
[11:39:48] <cehteh> consider if you can remove the division
[11:40:21] <cehteh> dunno what you are doing but sometimes thats easily doable
[12:03:39] <Chillum> decimal places are only an illusion created by humans
[12:07:44] <phinxy> hilarious, when i save my general settings the odometer says magnets
[12:07:51] <phinxy> how do they work
[12:08:45] <nuxil> illusion ? nah its a invetion by us humans. its the way to describe fractions of stuff. ex half a apple. lookin at them both, you can say they both are 1, but one of them is only half of the other so we invented a way to describe this ;p
[12:09:25] <nuxil> phinxy, woot?
[12:09:31] <inkjetunito> nuxil: how to describe 1/3?
[12:10:05] <nuxil> as desimals ? 33.333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
[12:10:10] <nuxil> error.. buffer overflow
[12:10:16] <phinxy> nuxil, its a bug!
[12:10:56] <nuxil> what is?
[12:12:18] <phinxy> im making a tacho+odometer
[12:13:10] <nuxil> yeah. i got that.. but what's the bug?
[12:13:18] <nuxil> 36/2000 ?
[12:14:42] <phinxy> no it was just a typo, copying a string to the wrong location.
[12:16:48] <cehteh> still ... try too measure everything in integers, decimal points are just for the show. store cm traveled, not km. handle speed in cm/hour (cm is just an example here, maybe you want some different unit)
[12:17:21] <nuxil> thats a good suggestion
[12:17:22] <cehteh> try to do math in the most exact lossless way
[12:18:16] <cehteh> even cm miught be bad if your sensor gives one signal per wheel rotation .. so most natural way would be to store then number of your wheel rotations
[12:18:34] <cehteh> and later for display you calculate that with the wheel circumference
[12:18:58] <nuxil> i would just store the num of rotation.. knowing the diameter of the wheel you can easly calulate how far you have tranvled.
[12:19:08] <cehteh> best math is the math you can avoid :D
[12:19:16] <nuxil> ^
[12:21:33] <nuxil> phinxy, (PI * diameter of wheel) * numrotation = distance travled
[12:21:45] <nuxil> :p
[12:22:37] <phinxy> Pi is amazing
[12:23:35] <phinxy> i will measure the circumference with a string or with markers
[12:23:53] <phinxy> sitting on the bike will make the circumference slightly less.
[12:25:08] <inkjetunito> circumference? or diameter :p
[12:27:07] <inkjetunito> and how does this all affect aerodynamic?
[12:28:06] <inkjetunito> anyway. have fun :)
[12:30:43] <cehteh> just add a GPS to the tachometer
[12:30:54] <nuxil> phinxy, so if you have a 20" rim including the tire you would get something like pi * ~130 shoul be around. 408 cm .. you would use this in your mcu. its a nice int number and precise enough.. so you end up with (408 * numer of rotation) / 1000 = traveled kilometer.
[12:32:12] <nuxil> erm
[12:32:14] <nuxil> meters
[12:32:38] <cehteh> with some clever algorithm you should be able to use GPS to calibrate the circumference over time
[12:32:44] <cehteh> and you get an exact clock
[12:33:22] <nuxil> lol
[12:45:36] <Lambda_Aurigae> well, exact plus or minus 10ns or so...if you know your position.
[12:46:51] <Lambda_Aurigae> because the time is accurate at the satellite...but travel of the signal can vary depending on your position and the position of the satellite.
[14:44:48] <nuxil> anyone got an idea on how i can create a random delay ?
[14:47:34] <nuxil> i basically know how i could do it.. use the watchdog to create a random number,, then a huge function wich has lots of switchs in it. so the void rndsleep(n) { switch(n) {case 1: delay_ms(1); break; case 2: _delay_ms(2) and so on.. but is there a simpler way.. cos i want a random sleep effect that can vary from 1ms to 100ms.
[14:47:46] <nuxil> and i do not want to make a switch/case for that
[14:48:47] <snooky> hi all
[14:48:53] <nuxil> hello
[14:48:59] <snooky> i dont really good speak english. but i need help
[14:49:04] <snooky> can i use google translate?
[14:49:05] <nuxil> nor do i
[14:49:09] <nuxil> no
[14:49:23] <nuxil> you type well so far :p
[14:50:13] <snooky> I read from a photoresistor by ADC. This works well as far. The value do I store and let him buy me on a display. However, "jumps" the value during the conversion. So every 5 seconds tick the numbers as quickly and then the value is again constant. So each time during the conversion. How I handle this problem? The value of the ADCs can yes 0 - its 1023rd So far so good. I need However, a value of 0 - 100. The conversion will not som
[14:51:22] <snooky> So the photo resistor to regulate the display brightness. This goes from 0 - 100. So the brighter it is brighter and the display. The ADC is gepullt with a 4.7k. The photoresistor switched GND. However, it works the other way around but not quite accurate. how "invert" I value now? So now it is, the darker it is the brighter the display.
[14:52:14] <nuxil> invert ? ~value
[14:52:23] <snooky> yes
[14:52:41] <snooky> the adc is 0 - 1023
[14:52:43] <snooky> right?
[14:52:59] <nuxil> what chip?
[14:53:04] <snooky> atmega128A
[14:53:06] <nuxil> i thought it to be 255
[14:53:09] <nuxil> oh
[14:53:16] * nuxil summons the avr masters
[14:53:20] * nuxil hides himself
[14:53:30] <snooky> ?
[14:53:53] <snooky> https://www.mikrocontroller.net/topic/387423#new
[14:53:56] <snooky> theres my code
[14:56:34] <nuxil> sorry.. i have no idea about adc or the 128A.
[14:57:12] <nuxil> i think somone in here has used it and messed around with adc.
[14:58:16] <nuxil> but to invert a value you use use the ~ bit operator.. example. value = 0b1000.. inverted = ~value becomes --> 0b0111
[14:59:56] <nuxil> is it me or are switches real slow with gcc avr ???
[15:00:23] <snooky> avr-gcc
[15:00:31] <snooky> i must have so ^^
[15:00:47] <nuxil> hehe
[15:00:50] <snooky> 1023 adc value = 0 my value
[15:00:57] <snooky> 0 adc wert = 100 my value
[15:01:50] <snooky> ((fotowid_temp / 10) - 100) + 100;
[15:01:57] <snooky> but so it doesnt runs ^^
[15:09:49] <JesseG_Work> Howdy Folks!
[15:10:54] <JesseG_Work> So I'm trying to figure out how to connect to the target (SAMD20E17, but never mind that he he) using arm-none-eabi-gdb.exe on the command line. Using Atmel-Ice and Atmel Studio 7
[16:27:01] <nuxil> anyone got an idea how i do circular rotation from left to right ?
[16:29:00] <RikusW> what do you need to rotate ?
[16:29:22] <nuxil> well a int that is 16 bit..
[16:30:06] <RikusW> in c or asm ?
[16:30:11] <nuxil> C
[16:30:23] <RikusW> in asm use rol + ror
[16:30:40] <RikusW> by 1 bit or variable ?
[16:30:43] <nuxil> basically what i want to do is something like this. 0110.. 0011.. 1001.. 1100
[16:31:05] <RikusW> ah 1 bit
[16:31:14] <nuxil> yea
[16:32:04] <nuxil> but i cant do asm.
[16:32:26] <nuxil> i can barly understand what im doing in C :p
[16:32:30] <RikusW> if(x & 1) { x >>= 1; x |= 0x8000; } else { x >>=1; }
[16:32:42] <RikusW> 0x08 for 4 bits...
[16:33:11] <nuxil> i replace that with 0xfff ?
[16:33:16] <RikusW> x >>= 1; ----> x = x >> 1;
[16:33:17] <nuxil> +f
[16:33:54] <RikusW> and do make sure you only use a 16 bit type for that to work
[16:34:48] <RikusW> or easier x = x >> 1 | x & 1 ? 0x8000 : 0;
[16:35:50] <nuxil> ok.. why 0x8000 and do i need to replace that with 0xffff or ? since you said its for 4 bytes.
[16:36:16] <RikusW> 0x8000 is for 16 bit
[16:36:30] <RikusW> no ffff
[16:36:40] <nuxil> so you take 1/2of its range and or it
[16:36:41] <RikusW> 0x00 is 8 bit
[16:37:43] <RikusW> a rotata can be done with a shift right and taking the lsb to the msb side
[16:37:58] <RikusW> which is what ---> x = x >> 1 | x & 1 ? 0x8000 : 0; does
[16:38:19] <RikusW> x & 1 ? 0x8000 : 0 checks the lsb
[16:38:37] <RikusW> x = x >> 1 | (x & 1 ? 0x8000 : 0); might be safer
[16:39:19] <nuxil> thanks
[16:39:31] <RikusW> without () the compiler might not understand ;)
[16:50:47] <nuxil> awesome, worked like a charm. thanks alot RikusW :D
[16:51:30] <RikusW> :)
[16:52:06] <nuxil> got a "LED propeller" spinning around in my infinity mirror ;D
[16:52:42] <RikusW> x = x << 1 | (x & 0x8000 ? 1 : 0); // rotate left
[16:52:51] <RikusW> nice
[16:53:16] <nuxil> working on making misc effects on it. :)
[16:53:22] <RikusW> ah
[16:53:37] <nuxil> so thanks for that rol :D
[16:54:36] <JesseG_Work> It was a very important rol :D
[16:55:00] <nuxil> hehe
[16:55:42] <RikusW> iirc here are some bitshifting tutorials http://tom-itx.no-ip.biz:81/~webpage/index.php
[16:56:10] <RikusW> You should really get to know & | &= |= when working on AVR
[16:56:19] <RikusW> >> << as well
[16:56:35] <RikusW> it is used a lot
[16:56:37] <JesseG_Work> yeah bitwise logic is amazingly powerful!
[16:56:50] <RikusW> and hex
[16:57:12] <nuxil> JesseG_Work, and amazingly confusing aswell :p
[16:57:37] <RikusW> nuxil: do you know hex (hexadecimal) ?
[16:57:42] <nuxil> ofc
[16:58:27] <JesseG_Work> nuxil, It could seem that way at first, but it's pretty understandable since there's just a few simple operations and they all relate directly to the actual physical state of real bits in memory.
[16:58:30] <RikusW> 0100 = 0100 & 0101
[16:58:31] <nuxil> a=10 b=11.. f=15 , 10 = 16
[16:58:36] <nuxil> and so on
[16:59:17] <RikusW> 1101 = 0100 | 1001
[16:59:39] <RikusW> use binary to better understand & | (and or)
[16:59:43] <nuxil> 1000 = 0111 ^ 0111 ?
[16:59:51] <RikusW> that is xor
[16:59:52] <JesseG_Work> nuxil, the neat thing about hex is that each digit represents exactly 4 bits
[16:59:58] <nuxil> yes but is it correct ?
[17:00:06] <RikusW> answer would be 0
[17:00:31] <RikusW> 1010 = 1100 ^ 0110
[17:00:41] <JesseG_Work> nuxil, with exclusive or, the two input have to be different to produce a 1 as an output. If they are the same, the output is 0.
[17:00:45] <RikusW> 1^1=0
[17:00:49] <nuxil> ah ofc. i mix em up
[17:00:55] <JesseG_Work> It's a OR b, but not both and not neither, hence the exclusivity part.
[17:01:25] <JesseG_Work> Plain or (|) is a OR b, or both.
[17:02:13] <nuxil> JesseG_Work, yea i know about the basics. but never remember which does what. and. nand, or . nor/xord so on.
[17:02:22] <JesseG_Work> ahh
[17:02:36] <RikusW> 1010 = ~0101
[17:02:53] <nuxil> yea that i know.. inverse :D
[17:03:03] <RikusW> 1 = !0 and 0 = !1010
[17:03:59] <nuxil> i should really get a book about C.
[17:04:09] <nuxil> anyone you guys would reccomend?
[17:04:13] <RikusW> && || is boolean not bitwise
[17:04:25] <RikusW> as is !
[17:05:35] <JesseG_Work> nuxil, there are lots of free tutorials that would probably work fine, like this I just googled: http://beginnersbook.com/2014/01/c-program-structure/
[17:06:07] <nuxil> well. i do like free stuff.
[17:06:10] <RikusW> http://www.gnu.org/s/gnu-c-manual/gnu-c-manual.html
[17:06:14] <nuxil> but i also like a good book to read
[17:06:22] <RikusW> though that is a reference
[17:06:45] <nuxil> bookmarked
[17:07:01] <RikusW> http://www.google.com/search?q=c+reference
[17:07:29] <JesseG_Work> nuxil, I learned from a book, before I had internet. It was something like "ANSI C" and it showed a chess set on it, or something. Don't remember exactly. Someone gave it to me. I've passed it on to some friend's kids who are playing with computers now :D
[17:08:02] <nuxil> is ansi C the same as C89/90 ?
[17:08:20] <JesseG_Work> for beginners it is
[17:09:41] <JesseG_Work> some features are added or removed over the years, so C89 may have a very slightly different feature set than C99
[17:10:09] <JesseG_Work> ANSI is probably whatever the currently accepted standard is from among the evolution of the Cxx series :P
[17:12:08] <nuxil> i only been doing C for some months :p altho i done some python scripting in the past. its like a hole different world to code in :p
[17:13:01] <JesseG_Work> for example, in C99, you can divide a floating point number by a zero and get a result of the special value infinity, which is actually a valid input for some functions like atan or whatever, which is really nice for geometry programs. C89 does not support that.
[17:13:44] <JesseG_Work> well it looks like you're doing pretty well! I agree, it is a whole different world.