#avr | Logs for 2015-11-15

Back
[03:33:39] * osteri feels guilty using malloc in AVR
[03:36:47] <osteri> couldn't find more elegant way of storing different sized strings in a queue
[03:53:46] <antto> u so naughty
[04:04:15] <|DM|> arent "ldi r24 0xFF ; out 0x11 r24" and "sbr 0x11 0xFF" equivalent?
[04:07:56] <Xark> |DM|: I don't think so, since SBR just takes R16-r31 (not 0x11).
[04:09:09] <Xark> |DM|: Hmm, it is just a synonym for ORI,
[04:24:34] <|DM|> Xark, but it says it can take any register?
[04:25:32] <|DM|> I have code that breaks if I try to replace the first two with a sbr
[04:25:44] <|DM|> and Ive tried inserting a "nop" just to make sure its not a timing issue
[05:02:04] <sebus> hiho
[05:03:39] <sebus> Gotta question - Just for fun i want to make a command line parser aka i put chars via terminal and it executes some instructions aka if i type "PORTB 0x80" it wil set 8th pin on uc
[05:08:34] <sebus> any ideas what i need to do it? I am thinking of array filled with valid commands and comparing them with another array from serial/keyboard buffer. If ascii command matches, it makes a call to exact function listed in array
[05:09:02] <cehteh> yes something like that
[05:09:18] <sebus> how to put in array a pointer to function and then use it to call it back? :D
[05:09:19] <cehteh> you can build a dispatcher with some preprocessor tricks
[05:09:33] <sebus> I dont want to use case/lots of if...
[05:09:44] <sebus> struct?
[05:10:06] <cehteh> moment i show you some code
[05:10:31] <cehteh> generates a lot of 'if's ... but i was just lazy, walking a table or some other lookup would be easy to do
[05:10:58] <sebus> lookuptable with ascii and address to jump
[05:11:40] <cehteh> http://git.pipapo.org/?p=dinoheat;a=blob;f=Dino.h;h=fc4aacbff27b7598cd3e0b275d14ad3293d397c3;hb=HEAD#l154 .. the trick is to define it all on one place
[05:12:38] <cehteh> http://git.pipapo.org/?p=dinoheat;a=blob;f=DinoCLI.ino;h=6c62b4457385aa6b094055dac6b433323d71d9a6;hb=HEAD .. and expand it in different ways, to generate tables, a help command listing them all, dispatch the functions etc
[05:13:55] <cehteh> looks a bit ugly with the preprocessing stuff, but you have only one place where you define the commands and need only one function to define any action on it
[05:17:54] <sebus> though it could be done easier... gosh
[05:18:45] <cehteh> thats not the simplest case :)
[05:19:11] <cehteh> but just this way #define CMDS CMD(foo) CMD(bar) ....
[05:19:45] <cehteh> and then expand CMDS to a table, dispatcher or whatever you need is reasonable simple
[05:22:56] <cehteh> struct dispatch { const char* name; void (*function)(void);} #define CMD(name) {#name, cmd_##name};
[05:23:29] <cehteh> struct dispatch table[] = { CMDS };
[05:25:18] <cehteh> (in fact and i just see that i forgotten that, one would put the strings and the table in flash memory, but anyway, same principle)
[05:26:18] <sebus> putting stuff in flash is easy
[05:26:32] <sebus> const char... progmem... ekhm.. also reading it back from
[05:26:37] <sebus> just to save ram
[05:26:42] <cehteh> well not for the table :)
[05:26:55] <cehteh> you can get some quite ugly hacks
[05:28:37] <sebus> cehteh http://pastebin.com/FqyYtrsZ i though about something like this
[05:30:12] <cehteh> you need to store the strings somewhere
[05:30:52] <cehteh> and my preprocessor example is only trick how you can generate your command table, finally it can look like that
[05:31:35] <cehteh> wtf is 'code' in that example?
[05:33:49] <cehteh> and generating an array of strings in flash is non trivial const char* array_of_strings PROGMEM = .{"foo","bar"}; would only put the array (pointers) in progmem not the strings themself
[05:35:27] <sebus> and what if I try with = {"COMMAND", command_function, ...<other stuff>...."", NULL}; ?
[05:35:30] <sebus> possible to make?
[05:36:40] <cehteh> thats what i shown above
[05:36:51] <cehteh> struct dispatch { const char* name; void (*function)(void);}
[05:37:23] <cehteh> struct dispatch table[] = { {"commandname",commandfunction}, ....};
[05:37:53] <cehteh> still not in flash here .. excercise left to the reader :D
[05:38:43] <sebus> hah, yep. Thanks :D
[05:39:03] <cehteh> there is some C++ template thing for arduino for putting strings in array into flash ... i dont like the c++ part, made my own in C
[05:39:03] <sebus> tricky stuff
[05:39:10] <cehteh> but it would hurt your eyes :)
[05:39:48] <cehteh> easy to use:
[05:40:02] <sebus> op-code list hurts way more than strings... :P
[05:40:14] <cehteh> PROGMEM_STRING_ARRAY(name, "foo", "bar", "baz");
[05:40:27] <cehteh> .. but here is the code: http://git.pipapo.org/?p=dinoheat;a=blob;f=progmem_string_array.h
[05:41:35] <cehteh> iteration in preprocessor is such a pita :)
[05:42:08] <sebus> yes, I see :D
[05:43:36] <cehteh> ah .. moment PROGMEM_STRING_ARRAY(name, L("foo"), L("bar"), L("baz")); was it
[07:04:04] <averowsky> it can be that my stepper motors are damaged thats way they are so hot very quick ?
[07:04:31] <averowsky> cause Im tryin everything, I tested on drv8825 on l298n. I reduce current on drv8825
[07:04:43] <averowsky> I tried with different voltage
[07:04:49] <averowsky> and Im out of idea
[07:05:37] <cehteh> how do you control them?
[07:05:54] <averowsky> cehteh: what do you exxactly mean ?
[07:08:08] <averowsky> I want to use them to stabilize my balancing robot
[07:09:13] <cehteh> mhm maybe overload? .. can the controller characteristic be programmed for the chopped mode?
[07:09:35] <cehteh> besides .. servos might be simpler
[07:11:56] <cehteh> if they overheat they may get damaged, but that would some serious overheat
[07:12:17] <cehteh> permanent magnets also fail then
[07:12:23] <cehteh> if they have any
[07:13:09] <cehteh> but that needs way more than 100°C
[07:13:48] <averowsky> I regulate current with PWM chopping
[07:15:12] * cehteh just reads the drv8825 datasheet .. look at its parameters, microstepping mode, decay etc
[07:15:40] <cehteh> also double check that your connections are correct
[07:16:26] <cehteh> do you ramp up/down speeds?
[07:19:09] <cehteh> do they get hot while spinning, or when stationary, or when you regulate this balancing robot (whatever that is)
[07:22:41] <averowsky> cehteh: I assume If all stepping modes works I mean 1/16 1/8 1/4 1/2 this means that connections are fine
[07:23:11] <averowsky> They get hot when is moving or when is in hold
[07:23:42] <cehteh> looks like too much current, did you measure it?
[07:24:02] <cehteh> i mean the will get somewhat hot, thats ok, but not excessive
[07:24:54] <cehteh> esp when they are 'holding' thats basically just the current you pums trough it whats heats em up
[07:25:27] <cehteh> if they get hotter while operating you may ramp them more gently
[07:27:35] <averowsky> I measured current it was not much smth like 0.25mA
[07:27:49] <cehteh> eh what?
[07:28:00] <averowsky> 250mA sorry
[07:28:05] <cehteh> :)
[07:28:43] <cehteh> thats somewhere in the 5W ballpark
[07:29:00] <cehteh> 18V
[07:35:31] <averowsky> Sorry I had a call
[07:36:05] <averowsky> so the current is not big
[07:36:53] <averowsky> more gently you mean full step ?
[07:41:29] <cehteh> doesnt matter if full step or microstep, when you spin a stepper you must accelerate/deaccelerate it within its mechanical limits
[07:42:37] <averowsky> in smaller steps higehr current is taken
[07:42:44] <averowsky> I saw this in datahseet
[07:42:55] <cehteh> you mean when microstepping?
[07:42:59] <averowsky> yes
[07:43:05] <cehteh> yes
[07:43:23] <averowsky> But I did simple program
[07:43:44] <cehteh> but thats irrelevant here, possibly you should try to get this working with full steps first for simplicits
[07:43:52] <averowsky> where Im making one step every 5ms
[07:43:59] <averowsky> and it gets hot too
[07:44:11] <cehteh> but you cant go from standstill to 100rpm in a instant for example
[07:45:00] <cehteh> i dunno the masses and mechanical limits you have there, 5ms sounds sane, but thats up to you to figure out
[07:45:10] <cehteh> else try reducing the current even more
[07:46:04] <cehteh> as i saied, with 250mA annd 18V you are around 5W ... which means almost 5W heat
[07:46:23] <averowsky> ok I will decrease it more on driver
[07:46:46] <cehteh> just the minimal working current + some safety marigin
[07:47:06] <cehteh> 5W could heat some not well cooled thing quite considerably
[07:55:21] <Lambda_Aurigae> averowsky, you really should run those steppers at their rated 24V to make them run more efficiently and produce less heat.
[08:39:04] <cehteh> maybe too small cap ...
[08:50:24] <Lambda_Aurigae> in my experience, steppers tend to run hot if you don't run them at their rated voltage.
[08:51:13] <cehteh> yes .. need more current then, means higher losses
[08:53:21] <averowsky> Im doing tests
[08:53:31] <averowsky> I dont have stronger power suply than 19V
[08:54:08] <Lambda_Aurigae> I have a bench supply made out of a copier power supply.
[08:54:19] <Lambda_Aurigae> gives me 3.3V, 5V, 12V, and 24V.
[08:54:23] <Lambda_Aurigae> with plenty of current.
[08:55:22] <averowsky> I dont have copier ;)
[08:55:39] <cehteh> averowsky: what capacitor did you put on the controller?
[08:55:54] <cehteh> if in doubt, make it bigger
[08:55:55] <Lambda_Aurigae> I don't have a copier either.
[08:56:02] <Lambda_Aurigae> but I fix them for a living.
[08:56:18] <Lambda_Aurigae> and sometimes can collect parts from dead ones.
[08:56:20] <averowsky> cehteh: 47uF
[08:56:33] <cehteh> sounds small to me
[08:56:40] <cehteh> what does the datasheet suggest?
[08:56:48] <averowsky> minimum 47uF
[08:56:56] <averowsky> it was on site where I bought it
[08:57:04] <averowsky> but I will check datahsteet also in a momment
[08:57:30] <averowsky> Lambda_Aurigae: Since I started playing with electronics I also collect everything
[08:57:40] <Lambda_Aurigae> hehe.
[08:57:41] <averowsky> this 19V is also collected :)
[08:57:47] <Lambda_Aurigae> I did that back in the day...
[08:57:50] <averowsky> from old laptop
[08:58:04] <cehteh> averowsky: make it biggier
[08:58:08] <sebus> averowsky build your own bench psu with current limiting :>
[08:58:32] <Lambda_Aurigae> once when we moved when I was a kid I had to leave 90% of my stuff behind...had a huge treehouse full of scavenged stuff.
[08:59:03] <averowsky> sebus: good idea I will try I think
[09:00:03] <sebus> averowsky http://obrazki.elektroda.pl/3556755400_1331419862.jpg i build mine from this schematics, modified a bit
[09:00:23] <sebus> all parts from garbage = $0
[09:01:05] <averowsky> Lambda_Aurigae: that hurts I guess
[09:01:17] <Lambda_Aurigae> happened a lot.
[09:01:27] <Lambda_Aurigae> we moved a lot so I had to leave lots of good "stuff"
[09:01:53] <averowsky> sebus: I added to bookmark, thanks
[09:01:55] <Lambda_Aurigae> last time I moved as an adult, 7 years ago, I had almost 2000 pounds of "stuff"
[09:02:15] <Lambda_Aurigae> amongst our 6500 pounds of household goods.
[09:02:47] <cehteh> averowsky: so bigger cap, maybe higher voltage range (less ESR), experiment with the different decay modes, reduce current and try to apply a higher voltage
[09:03:15] <averowsky> cehteh: 470uF?
[09:03:16] <cehteh> sounds like a plan? :)
[09:03:18] <cehteh> yeah
[09:03:27] <cehteh> if you have one
[09:03:32] <cehteh> 50V ...
[09:03:49] <cehteh> whatever you have laying around
[09:04:56] <Tom_itx> just not the cat
[09:05:08] <averowsky> you mean between plus and minus on motor supply pins yes ?
[09:05:14] <averowsky> on drv8825
[09:05:15] <Lambda_Aurigae> what is the voltage and capacitance rating of an average 10 pound cat anyhow?
[09:05:15] <cehteh> its not very citical as long the capacitance is high enough and voltage rating is ok (for a wet cap on a circruit with inductances, like the stepper you should rate the voltage twice the input voltage)
[09:05:21] <Lambda_Aurigae> time to get a grant to study that!
[10:09:19] <|DM|> why is there set bit in io reg, and set bits in r0-r32 reg, but no set bits in io reg ?
[10:17:39] <Lambda_Aurigae> umm..you might want to read and repost that.
[10:32:41] <|DM|> ?
[10:33:18] <DKordic> |DM|: Please elaborate.
[10:33:35] <|DM|> why is there "sbi" (set bit in io reg), and "sbr" (set bits in r0-r32 reg) , but no "sbr" that can operate on the io registers.
[10:37:21] <DKordic> |DM|: 'SBR' is just an ORI instruction. All instructions with immediate parameter operate on GPRs with 16<=index<=31.
[10:37:43] <DKordic> 'OUT' is what You are looking for.
[10:38:06] <|DM|> OUT immediate is what I wanted.
[10:38:17] <|DM|> So i guess it doesnt exist ?
[10:39:06] <DKordic> Why would it exist when it could be done with just 2 instructions ``ldi tmp ,C; out SFR ,tmp''.
[10:40:22] <|DM|> to save 1 cycle I guess.
[10:40:32] <DKordic> Or more likely ``in tmp ,SFR; ori tmp ,flags; out SFR ,tmp''.
[10:41:11] <DKordic> just call+ret are about 7 cycles.
[10:43:32] <|DM|> well, you can flatten code to remove those
[10:44:20] <DKordic> Or better use more appropriate uC :) .
[10:46:41] <|DM|> ?
[10:47:16] <DKordic> For example xmegas have SFRs to ``SFR {,|,&,^}= GPR'' for every PORT.
[10:48:03] <DKordic> |DM|: For example use uC with deeper instruction pipeline.
[10:50:01] <|DM|> Aha, ok
[10:50:03] <DKordic> Like ``PINn = GPR'' is effectively ``PORTn ^= GPR''.
[10:51:15] <DKordic> ( For recent PORT versions )
[11:06:53] <averowsky> cehteh: I reduce current to 200mA and it looks fine with temp
[11:08:01] <Lambda_Aurigae> watch your torque..with it cut down that low you won't get anywhere near max torque out of it...and top speed will be an issue as well.
[11:08:40] <cehteh> of course . .reduce it only to that it still operates safely
[11:09:08] <cehteh> but you saied 'balancing' robot .. loosing a few steps here and there might not be critical or?
[11:09:47] <averowsky> Torque is enough I think we will see if it will be no problem in future
[11:09:48] <cehteh> what kind of control loop are you using? PID?
[11:09:54] <averowsky> cehteh: yes
[11:10:06] <averowsky> I think I will use only PI
[11:10:19] <averowsky> I was using PID with DC motors
[11:10:34] <cehteh> i use PI for heating only too
[11:11:00] <cehteh> D is nice when you expect some external distortions, might be needed for a balancing thing
[11:11:01] <averowsky> with D it is shaking to much that I cannot stabilize it
[11:11:19] <cehteh> D usually needs to be very very small
[11:11:46] <cehteh> and a feedforward correction may improve the regulator too
[11:11:49] <averowsky> as far as I remember D response to speed of stabilization
[11:12:02] <averowsky> so it will response much faster
[11:12:30] <averowsky> but with steppers it doesnt work well, this is my first impression
[11:13:30] <cehteh> just play around
[11:14:25] <averowsky> yep
[11:28:43] <|DM|> So whats some cool things I should try with my lcd circuit before I take it apart ?
[11:29:12] <Lambda_Aurigae> ummm.
[11:29:15] <Lambda_Aurigae> display stuff.
[11:29:21] <Lambda_Aurigae> make a clock/bomb detonator!
[11:29:29] <|DM|> oooh, a clock.
[11:29:31] <|DM|> Good idea!
[11:29:51] <Lambda_Aurigae> combine clock with temp sensor.
[11:30:02] <|DM|> wut
[11:30:11] <Lambda_Aurigae> a clock and temperature display.
[11:30:28] <Lambda_Aurigae> depending on what kind of lcd you have, you might can display both at once.
[11:30:54] <|DM|> 2x16, there's enough space certainly.
[11:30:55] <Lambda_Aurigae> then add to that and make a programmable thermostat.
[11:31:09] <Lambda_Aurigae> then TAKE OVER THE WORLD!
[11:31:13] <|DM|> heh
[11:31:22] <|DM|> can't make a thermostat without a rtc module
[11:31:43] <Lambda_Aurigae> well, can't make an accurate clock without an rtc unit of some kind.
[11:31:49] <|DM|> true
[11:32:01] <|DM|> Ill still do it, it'll be fun
[11:32:02] <Lambda_Aurigae> many AVR chips allow you to put a 32KHz crystal on them to drive one of the timers.
[11:32:12] <|DM|> yeah
[11:32:16] <Lambda_Aurigae> I've stolen them out of dead watches before.
[11:32:28] <|DM|> I have some laying around
[11:32:56] <Lambda_Aurigae> I have also used maxim/dallas rtc chips for such projects.
[11:33:11] <Lambda_Aurigae> they still need the 32KHz crystal but offload a lot of the time processing from the AVR.
[11:33:41] <Lambda_Aurigae> ok..gotta go make sawdust..laters.
[11:34:35] <cehteh> i am going to make a lib which adjusts the internal clock based on some external signal
[11:35:11] <cehteh> OSCCAL ...
[11:36:03] <cehteh> the micronucleus bootloader does that already, syncing the internal clock with the usb clock, but anything else should be possible, dcf77, serial, ...
[12:17:12] <inkjetunito> good evening
[12:47:05] <Lambda_Aurigae> cehteh, I've adjusted internal RC oscillator to match rs232 data coming in.
[12:47:46] <cehteh> at startup or continously?
[12:48:07] <Lambda_Aurigae> at startup and on data comms loss.
[12:48:25] <cehteh> ah looks like a plan too
[12:48:39] <Lambda_Aurigae> used an external program on the pc that would watch for data packets returning and if it got bad data it would send UUUUUUUU and wait for next packet.
[12:48:49] <cehteh> yes
[12:49:13] <Lambda_Aurigae> on that particular project, data was always sent as 64bits,,,8 8bit characters.
[12:49:17] <cehteh> well i planned to regulary (but infrequently) readjust the osc
[12:49:50] <sebus> <Lambda_Aurigae> like in 90's programs on pc. U = 0x55?
[12:49:52] <Lambda_Aurigae> if the avr didn't get a valid packet then it would watch for the UUUUUUUU and adjust accordingly then resend.
[12:49:55] <Lambda_Aurigae> yup.
[12:50:27] <Lambda_Aurigae> used to use constant U characters on old 300 baud modems to insure we had good data.
[12:50:57] <sebus> I use now 485 + modbus rtu libs on anything
[12:52:36] <Lambda_Aurigae> I've written so much of my own stuff over the years that anybody looking at my current code would be scratching their heads and wondering where the c-64 is hiding.
[12:52:47] <sebus> 485 just because I managed that some stuff around me generate a lot of noise...
[12:53:12] <sebus> ahh, lovely 6502
[12:53:15] <sebus> :D
[12:53:17] <Lambda_Aurigae> yes.
[12:53:34] <Lambda_Aurigae> there is a newish 6502 extended processor that I would love to play with.
[12:53:57] <Lambda_Aurigae> and I've done some work with the 6502 emulator on AVR....not much but I did play with it.
[12:54:27] <Lambda_Aurigae> I gravitated to AVR over PIC years ago because AVR assembly reminded me so much of 6502 assembly.
[12:55:22] <Jartza> oh
[12:55:35] <Lambda_Aurigae> Jartza, did it hurt?
[12:55:35] <Jartza> I had the same reason for selectin avr isntead of pic :)
[12:55:43] <Jartza> instead, even
[12:56:06] <Lambda_Aurigae> Jartza, time to use an AVR to generate vic-20 text and graphics on VGA.
[13:00:30] <Lambda_Aurigae> create a vic-20 on a couple of AVR chips.
[13:00:37] <Jartza> :)
[13:00:59] <Lambda_Aurigae> I have a dead one here I can steal for case and keyboard.
[13:31:11] <ambro718> Hey, can someone please check, is this a correct implementation of isnan() for AVR, http://ideone.com/lS7AZZ
[13:31:35] <ambro718> it's supposed to mean: exponent is 0xFF and mantissa is nonzero
[13:32:08] <apo_> (u.b[3] & 0x7F) == 0x7F && (u.b[2] & 0x80) == 0x80
[13:32:16] <apo_> can be collapsed to &0xFF == 0xFF
[13:32:32] <apo_> er
[13:32:33] <apo_> never mind =P
[13:32:39] * apo_ needs coffee, stat
[13:32:55] <ambro718> yeah it sucks the exponent is not aligned nicely!
[13:33:42] <ambro718> I ask because the avr-libc isnan() is pretty inefficient, it compares a value with itself. Don't want that happening in an ISR.
[13:34:37] <apo_> but yeah, looks okay
[13:34:48] <ambro718> thanks
[13:35:04] <Jartza> Lambda_Aurigae: actually I was thinking one day of using a bigger chip... :P
[13:40:15] <inkjetunito> who has the biggest chip :o
[13:45:17] <Jartza> vic-20 graphics requires some more ram
[14:10:42] <Xark> I have an asm 6502 emulator that can run faster than 1Mhz 6502 on 16Mhz AVR - while bit banging NTSC. :) https://imgur.com/a/dIrLJ#0
[14:14:48] <cehteh> nice
[14:16:38] <Jartza> Never Twice Same Color
[14:19:44] <Xark> Less of an issue with black and white - and supports PAL (B&W) too. :)
[14:20:43] <Xark> Only "catch" is I never changed it to run from flash or RAM, so it is limited to RAM only. Not too much fun on 328, but fine on 1284 (16KB).
[14:21:06] <Xark> (the test for flash/ram slowed it down significantly)