#avr | Logs for 2016-05-10

Back
[07:59:24] <vpcd> I have a chip with 16 MHz internal RC oscillator selected as a clock source and CKSEL8 fuse set. I want to run it at full speed but am not sure if it is OK to do it with a USBtiny programmer with only 12 MHz clock. will i be able to program it if the chip is clocked higher than the programmer?
[07:59:57] <vpcd> that is using ISP method of programming
[08:00:44] <themba> I don't think programming speed is influenced by the clockspeed of the programmer or the device as long as both are high enough
[08:00:50] <liwakura> yeah
[08:01:14] <liwakura> also, i used an 12Mhz usbasp with an 16Mhz Arduini Nano board
[08:01:28] <liwakura> no issues
[08:04:07] <vpcd> yeah, i thought that too because the programming will happen at SPI speed. but just wanted to make sure because i recall reading somewhere about "bricking" the chip and only being able to program it using high voltage programmer, but not sure how that happend.
[08:07:09] <twnqx> that only happens if you remove the reset pin by fuse to get another gpio
[08:07:13] <theBear> there's something about needing a clock if you got no crystal and fuse it to want one as i recall, i WANNA say that's still spi mode, tom will know
[08:07:36] <theBear> a programmer with a clock that is, unless you wanna setup a clock on the target board
[08:19:24] <mohsen_> Is PORTx = value, the only way to set a pin high?
[08:19:59] <mohsen_> Isn't there anyway to only set the required pin high?
[08:20:06] <vpcd> there is also PORTx_struct
[08:20:51] <Lambda_Aurigae> vpcd, what chip runs at 16MHz internal oscillator?
[08:20:51] <mohsen_> I mean directly set the desired pin and not bothering the others.
[08:21:02] <theBear> in real terms the whole byte has to be written to that ports byte worth of data/io space, so anything hiding that is just doing the binary operator stuff to change only one bit in the background anyway
[08:21:32] <Lambda_Aurigae> and your programming speed needs to be 1/4 or less of the clock speed...but the programmer cpu clock means nothing as far as this goes.
[08:21:44] <theBear> if you inspect the asm the compiler generates, and i spose check the whole available list of asm commands, you'll see this is the way it is
[08:22:23] <Jartza> Lambda_Aurigae: my programming speed is reversibly relative to clock ;)
[08:22:32] <Jartza> the later it is, the more productive I am
[08:22:46] <Lambda_Aurigae> I'm better at earlier clock times myself.
[08:23:06] <Lambda_Aurigae> if I get up at 3am then around 4am is when my mind is working best for the whole day..
[08:24:15] <liwakura> vpcd: also, tell me pls where the PORTx_struct are defined
[08:24:18] <liwakura> i cant find them..
[08:24:25] <Jartza> Lambda_Aurigae: then we're almost opposite :)
[08:24:30] <Jartza> I usually get to bed around 3am
[08:24:38] <Lambda_Aurigae> Jartza, well, you do live in the old country.
[08:24:44] <Jartza> and in the morning, I'm only useful for drinking coffee
[08:25:07] <Jartza> after I've consumed half-a-pot of liquid caffeine, I'm up to something else
[08:25:10] <vpcd> Lambda_Aurigae, 256RFR2, I guess. internal 16 MHz RC osc. is selected as a clock source and a /8 fuse is programmed by default, so i assume if I defuse this then it will run at 16 MHz?
[08:25:39] <mohsen_> So for any change to any pin of the port the whole byte should be rewritten?
[08:25:43] <Lambda_Aurigae> vpcd, aahh, yes. I didn't realize those had a 16MHz RC oscillator. I thought the max was 8.
[08:25:47] <Jartza> Lambda_Aurigae: BTW, I got octapentaveega hooked up to my 3D printer :)
[08:25:58] <Jartza> now I have 19" VGA monitor where I can follow the status of print
[08:26:28] <Lambda_Aurigae> kewl.
[08:26:56] <Jartza> needed some modification to the 3D printer firmware, but I'm currently using Marlin as firmware
[08:28:21] <vpcd> liwakura: tbh i am not sure about PORTx_struct existing at all but in avr/ioxxxx.h there is a bitfield struct defined for many (or all) registers availiable through usual bit operations.
[08:28:56] <mohsen_> And another question, when should I use hex, when should I use binary and when should I use base 10 when I want to write a to a port?
[08:29:06] <Lambda_Aurigae> doesn't matter
[08:29:17] <Lambda_Aurigae> it is all in how you want it to be human readable.
[08:29:39] <mohsen_> I think binary is the most readable.
[08:29:47] <Lambda_Aurigae> 0b00000010 is the same as 0x02 is the same as 2
[08:29:51] <mohsen_> Since each bit corresponds to a specific pin
[08:30:03] <Lambda_Aurigae> they all compile to the same thing
[08:30:14] <Lambda_Aurigae> it is mostly programmer preference.
[08:30:25] <Lambda_Aurigae> I use different bases depending on what I'm doing.
[08:30:29] <theBear> yeah, i use hex/bin when it works easier for my head (in this context)
[08:30:54] <Lambda_Aurigae> you could do everything in binary throughout the program if you wanted..including for loop variables and constants if you wanted.
[08:31:14] <Jartza> I hate people who use hex in loops :)
[08:31:23] <Lambda_Aurigae> heck, you could do everything in octal if you really wanted.
[08:31:30] <Jartza> for(uint8_t i=0; i<0xD7; i++) ...
[08:31:36] <Lambda_Aurigae> Jartza, I love doing it in binary,,,just because I love binary countdown.
[08:31:44] <theBear> for example 0x0F is easier to type than 0x00001111 but 0x00000100 is easier than working out oh heh, 0x04, but assume i was more outta practice and that was a tricker conversion
[08:32:05] <liwakura> vpcd: just found that there are indeed some struct in some i*.h's
[08:32:06] <vpcd> i checked and PORTx_struct doesn't actually exist. there are still such structures for registers of things like timers, spi, etc.
[08:32:09] <liwakura> but not in mine
[08:32:13] <theBear> Lambda_Aurigae, i never watched that one.. is that on bbc2 late or ? <grin>
[08:32:40] <mohsen_> What's the type of a hex number?
[08:32:43] <mohsen_> in C
[08:32:47] <Lambda_Aurigae> theBear, it's on the Arcturus system channel #466Gamma7
[08:32:53] <theBear> a single hex digit is 4 bits wide
[08:32:55] <Lambda_Aurigae> type?
[08:33:00] <mohsen_> int, float, double...
[08:33:04] <theBear> and numbers don't have types, variables do
[08:33:07] <Lambda_Aurigae> it can be whatever.
[08:33:24] <Lambda_Aurigae> 0x45 is an uint8_t basically.
[08:33:30] <Lambda_Aurigae> 0x4576 is a 16 bit integer
[08:33:35] <theBear> and "high" level languages like c convert magically at compile time so you can pick whatever like we been saying
[08:33:47] <Lambda_Aurigae> writing floats in hex would be,,,,not good.
[08:33:55] <Jartza> Lambda_Aurigae: heh. how to count to ten and confuse people? for(uint32_t i=0b1000000000;i;i>>=1);
[08:33:58] <Lambda_Aurigae> doable, I think..never tried it.
[08:34:01] <theBear> atleast they do if you sane with your variable vs numbers-you-make-them stuff
[08:34:19] <vpcd> liwakura, I am using avr-libc and at least for the AVR i am now experimenting with there are quite a plenty of those in it's ioxxx.h
[08:34:24] <Lambda_Aurigae> Jartza, yeah..I love how the for loop lets you do complex math like that.
[08:34:29] <liwakura> vpcd: what avr?
[08:34:40] <vpcd> 256rfr2
[08:34:41] <Jartza> Lambda_Aurigae: there's so many ways to "misuse" for-loop...
[08:34:46] <Lambda_Aurigae> of course.
[08:34:48] <theBear> i wonder .... been a while.... re: signed and what you can type in your code and expect to land sensibly
[08:34:50] <theBear> or literally
[08:34:52] <mohsen_> Does that also apply to binary?
[08:35:01] <Lambda_Aurigae> mohsen_, yup.
[08:35:15] <mohsen_> So if I ever wanted to store a binary or a hex value into a variable, the type of the variable is irrelevant?
[08:35:26] <theBear> speaking of abuse, i remember a golden age of innocence before gosub had been imagined up
[08:35:44] <mohsen_> I feel pointless.
[08:35:53] <mohsen_> well, kinda.
[08:35:58] <theBear> the value you type is just a value, 0b11110000 is exactly the same as 0xf0
[08:36:29] <theBear> sorry i did a bin earlier 0xbinnumbr by mistake, forgive me :)
[08:36:38] <Lambda_Aurigae> mohsen_, yes...usually your binary and hex values are going to be integers of some length...unless you are really feeling masochistic and want to work with floating point stuff.
[08:37:20] <Lambda_Aurigae> https://en.wikipedia.org/wiki/Decimal32_floating-point_format
[08:37:33] <Lambda_Aurigae> it IS possible to represent a floating point number in hex or binary
[08:37:37] <liwakura> vpcd: yeah, your avr is one of those which have that structs
[08:37:52] <mohsen_> Lambda_Aurigae: Why bother, when it's not recommended?
[08:37:59] <theBear> hmm, i spose going with what i just said, if you got a signed 7bit int, 0xff is 0b111111111 and 0x7f is 0b01111111 ?
[08:38:07] <Lambda_Aurigae> mohsen_, I said possible..not for the sane to work with though.
[08:38:24] <Lambda_Aurigae> and I do floating point on avr all the time...nothing wrong with it other than the floating point libs are huge and slow.
[08:38:25] <theBear> which is to say, literal not converting actual written values (i spose you can't write negative number in hex/bin)
[08:38:41] <Lambda_Aurigae> theBear, you can if you use signed int.
[08:38:41] <theBear> err, which is to say, that was sposed to be a question
[08:38:54] <Lambda_Aurigae> using the upper bit as the sign.
[08:39:09] <Lambda_Aurigae> where an 8bit value becomes -127 to 128
[08:39:16] <theBear> yeah, but i mean i can't write 0x-7f
[08:39:40] <Lambda_Aurigae> yeah..it gets more difficult...I've never tried -0x72 before.
[08:39:48] <Lambda_Aurigae> should play with that and see what it converts to.
[08:39:57] <theBear> therefore, my musings/as-described was right, oh we both don't know, makes me feel better abouthow outta practice i am :)
[08:40:11] <theBear> ok, off to the other room, do some useful :)
[08:40:13] <theBear> bbl
[08:40:14] <Lambda_Aurigae> it's just not something I ever bothered to use.
[08:41:12] <Lambda_Aurigae> looks like it converts to a similar -0b value
[08:41:28] <Lambda_Aurigae> but to store it in a variable would require a signed int or float.
[08:41:54] <Lambda_Aurigae> storing any negative number to an unsigned int will cause,,,interesting results.
[09:05:00] <mohsen_> Is there any limitation on the number of #defines declared?
[09:11:32] <GeneralStupid> mohsen_: if your hard disc cannot save another 8 bytes
[09:11:39] <GeneralStupid> thats the limitation
[09:11:51] <mohsen_> I see
[09:16:57] <cehteh> with terrabytes or more hardisk space, maybe bit earlier, but not to worry about, i once ran performance tests for the cpp using millions of defines w/o problems
[09:39:28] <liwakura> weird idea: running an AVR simulator on a Teeny
[09:39:31] <liwakura> *Teensy
[09:41:38] <liwakura> otherwise i have no idea what i could use that teensy for
[09:53:25] <mohsen_> cehteh: I mean on avrs, they are limited in resources?
[10:05:05] <cehteh> mohsen_: #defines are a text processor/macros evaluated by the C preprocess. even before compiling C code
[11:14:27] <Lambda_Aurigae> the #define generates no actual code that goes in the program..only when using something that you defined do you actually add code to the program.
[12:07:33] <CasperAtWork> (not knowing the previous convos)
[12:08:01] <CasperAtWork> don't forget that even unused piece of code, as in unreachable, will be removed at compile time
[12:08:08] <CasperAtWork> and won,t appear in the final binary
[12:09:29] <CasperAtWork> so does redundant stuff.... foo=123; foo=123; foo=123 <=== this would be reduced to a single one.... this is also why adding many NOP sometime fail, as it (used to be) optimised out: it serve no purpose
[12:25:57] <Madsy_> I'm using the Atmel CDC module for serial via USB on an ATSAM4E16E. Anyone knows why only scanf and printf works, while fgets and all the FILE-flavors of functions from stdio.h fails?
[13:08:42] <Lambda_Aurigae> CasperAtWork, yes, depending on your optimization level. I think there is a way to keep all that in which would be disasterous for some people.
[13:09:11] <CasperAtWork> yup, but I think they fixed it now for nop
[13:09:26] <Lambda_Aurigae> Madsy_, that's all in the code on the ATSAM chip. It should have nothing to do with the usb/cdc connection.
[13:09:46] <Lambda_Aurigae> Madsy_, or, by module, do you mean a software module?
[13:10:26] <Lambda_Aurigae> Madsy_, as this is not an AVR chip, I'm guessing few people in here will know much about it.
[13:34:49] <Lambda_Aurigae> on the earlier discussion on setting individual bits in the PORTx registers and such...yes, you can do so with SBI and CBI commands so long as those registers are in the first 32 system registers, which on the datasheets I just checked, they are.
[13:35:09] <Lambda_Aurigae> those aren't really C friendly but doable as inline assembly.
[13:35:16] <LeoNerd> Huh?
[13:35:25] <LeoNerd> gcc will turn PORTB |= 1 into a SBI instruction
[13:35:28] <cehteh> gcc optimizes |= ....
[13:35:44] <Lambda_Aurigae> ok...someone earlier said it would read the register, do the math then write the whole thing back.
[13:36:26] <LeoNerd> Shouldn't do. Possibly /very/ old copies of avr-gcc might
[13:36:46] <cehteh> maybe when setting multiple bits at once
[13:37:03] <Lambda_Aurigae> and it will have to if it is higher than register 0x1F but for ports SBI and CBI should work and the compiler should, I suppose, be smart enough.
[13:45:21] <CasperAtWork> LeoNerd: why shouln't it optimise it to SBI?
[13:51:40] <theBear> i kinda assumed, making an ass outta you AND me, and nobody makes an ass outta me
[13:52:33] <theBear> did old 90sXXXX series have those commands ? i woulda thought i'd remember, then again, i forgot a lot since then
[14:43:21] <CasperAtWork> theBear: SBI? I'ld say yes, but dunnot, I'm pretty sure a pic16 does...
[14:51:51] <theBear> hmmm, howbout that.. that must be tricky at a low internal-circuit/watchacallit level
[17:47:03] <Lambda_Aurigae> yeah...it only works with the first 32 registers theBear
[22:00:18] <inflex> My Tiny10 adapter board for using the common ISP programmer works *yay* http://ctpc.biz/t10adp.jpg
[22:51:16] <anton02> i need to power some apple earbuds from an output stage. they're 20ma and 4 ohms. how big will my BJT need to be in terms of heat dissipation
[22:51:18] <anton02> 20mA max that is
[22:53:13] <Casper> 2 wrong data and few missing ones, go back to your homeworks (aka: get the right data)
[22:56:59] <Xark> anton02: Not much power needed for earbuds at all...
[22:57:25] <Xark> anton02: That is similar to an LED (i.e., may not even need a transistor). :)
[22:57:40] <anton02> yer, but it needs to be stable af
[22:57:53] <anton02> you cant have distortions in the signal
[22:58:07] <Xark> anton02: I doubt it matters.
[22:59:32] <Casper> anton02: the earphones are most likelly 16 or 32 ohms
[22:59:47] <Casper> and the power rating is normally in mW, not in current
[23:00:32] <Xark> Hmm, Google says between 40 and 45 mA...
[23:00:59] <Xark> Er, ohms
[23:02:05] <Xark> Hmm, or 23 ohms... :)
[23:02:42] <Xark> anton02: At any rate, I suspect a GPIO pin has plenty of "power".
[23:03:20] <anton02> im making an analogue amplifier. The output stage is the final stage of the whole system.
[23:03:47] <Xark> anton02: Okay. Then that is #electronics Q not avr, I guess. :)