#avr Logs

Oct 26 2019

#avr Calendar

12:26 AM day__ is now known as day
08:50 AM mouseghost: i found sd card ref!!
08:55 AM mouseghost: also, how can i keep time with avr?
08:56 AM mouseghost: lets say i can receive time somehow and then, how do i keep the measure of it?
08:56 AM mouseghost: can i like measure time or something
09:06 AM plouf: there are external ic RTC
09:06 AM plouf: like ds1341
09:07 AM cehteh: some avr's allow to connect a clock crystal and run a hardware timer from that
09:08 AM cehteh: what exactly do you want to do, what precision, timespans etc do you need?
09:09 AM cehteh: for realtime some clock signal receivers (dcf77 in europe) or gps are also an option
09:24 AM mouseghost: cehteh, i just want to log time, down to seconds
09:25 AM mouseghost: or...
09:25 AM mouseghost: every second run something and then also get a time
09:25 AM mouseghost: yes, that latter thing
09:25 AM twnqx: you'll want an external chip for that i guess
09:25 AM cehteh: for how long? and how exact? you know that there are multiple timers in hardware already
09:26 AM cehteh: which can be used for timekeeping as well, depending on the quality of the oscillator you use
09:26 AM mouseghost: yeah ive just learned that
09:26 AM mouseghost: cehteh, a month? or something? i mean, 1 or 2 seconds off dont make that much of a difference
09:26 AM cehteh: the avr-libc has some functionality to keep a wall clock
09:28 AM cehteh: usually you run an internal timer for timekeeping and have some external clocksource for syncronization
09:28 AM cehteh: as plouf saied, ds3141, or gps, dcf or anything else where you can derrive a clock signal from
09:29 AM cehteh: in europe (until recently) the mains frequency was a okish source as well
09:31 AM mouseghost: cehteh, why until recently?
09:32 AM mouseghost: renewables or something?
09:32 AM cehteh: yep
09:32 AM cehteh: well and mismanagement+
09:32 AM mouseghost: damn you renewables
09:32 AM cehteh: lol
09:32 AM mouseghost: cehteh, i would get some german time cus we import some german electricity
09:32 AM cehteh: where are you?
09:32 AM mouseghost: cehteh, poland
09:34 AM cehteh: anyway does your application have some connection to the outside world which you can use to sync/set the clock would it have GPS reception?, would more like 2-3 seconds off be a problem?
09:34 AM mouseghost: nah, these are okay
09:34 AM cehteh: i usualyl just use the internal timers which is often good enough to me
09:34 AM mouseghost: cehteh, i plan on using serial to sync time
09:35 AM cehteh: (unless internal osc which is quite bad)
09:35 AM cehteh: how frequent can you sync and would jitter matter?
09:35 AM mouseghost: well i would sync every now and then i guess..
09:35 AM mouseghost: as i said, 1-3 seconds a month loss is okay
09:35 AM mouseghost: so, syncs every month?
09:36 AM mouseghost: that radio time seems very promisisng though, i could sync like everyday
09:36 AM cehteh: i tohught more like once per second, or minite or maybe every couple minutes
09:36 AM mouseghost: oh
09:36 AM mouseghost: well, not that often, no
09:37 AM mouseghost: unless it will be automatic, then i could sync like every minute or something
09:37 AM mouseghost: or 5 minutes
09:37 AM mouseghost: meh i dont know
09:37 AM cehteh: of course automatic
09:38 AM cehteh: well you need to think about this, in the simplest case you just use an internal timer no extra hardware required
09:38 AM mouseghost: yeah but that rises a problem of syncing it too :E
09:38 AM cehteh: but depending on the oscillator/clock crystal you use that needs more or less frequent sync/calibration
09:39 AM mouseghost: im not sure yet
09:39 AM mouseghost: so many unanswered answers ;w;
09:39 AM mouseghost: questions -w-
09:40 AM cehteh: i run timers for up to few days from normal crystal, havnet measured yet how exact that is btu i wont mind there when it looses 1 minute over 2 days
09:40 AM mouseghost: thats too much for me
09:41 AM mouseghost: way too many seconds
09:41 AM cehteh: depening on how much money and efforts you thow onto it it can be ultra precise as well :D
09:42 AM mouseghost: cehteh, OCRing a watch running in a box
09:42 AM mouseghost: :p
09:42 AM mouseghost: though, thats more like arduino
09:43 AM mouseghost: cehteh, i need to figure out how to sleep too
09:43 AM cehteh: rtc chips can be programmed for example to give a 1hz signal on a pin which you can use to sync via interrupt/input capture
09:43 AM mouseghost: hm i might actually mess up internal clock
09:43 AM mouseghost: this sounds cool
09:43 AM mouseghost: cehteh, do you think sleep mode will mess up internal timer?
09:43 AM cehteh: read datasheet, depending on sleep mode timers go to sleep as well
09:44 AM mouseghost: ah
09:44 AM cehteh: usually only one timer is able to run in deepest sleep
09:44 AM mouseghost: let me finish ulysses first :E
09:44 AM cehteh: glhf
09:44 AM mouseghost: oh come on these refsheets look like it too
09:44 AM mouseghost: n-no?
09:44 AM cehteh: no AVR datasheets are extremely simple usually around 400-500 pages only
09:45 AM mouseghost: i dont even know what mcu will i use...
09:45 AM cehteh: lol
09:45 AM cehteh: there are mcu's with internal RTC too
09:45 AM mouseghost: is going to sleep for most of the second a good idea
09:46 AM cehteh: battery oeprated?
09:46 AM mouseghost: i could also shut off peripherals but im not sure if this wont damage them more
09:46 AM mouseghost: cehteh, yep
09:46 AM mouseghost: im making a temperature logger *grins*
09:46 AM cehteh: then sleeping is very important .. but other things as well
09:46 AM cehteh: liek tun off any external stuff that draws current
09:47 AM mouseghost: ..or internal too, right
09:47 AM cehteh: sleep does that for internal stuff
09:47 AM mouseghost: ah right well i couldve guessed
09:47 AM cehteh: (plus other powermanagement control, depending on mcu you use)
09:47 AM mouseghost: though, how do i wake up from sleep cehteh
09:47 AM cehteh: by interrupt
09:48 AM cehteh: you want to log temperature once per second?
09:48 AM mouseghost: yes
09:48 AM mouseghost: so 1hz crystal?
09:48 AM cehteh: ok so you program an rtc to give a interrupt once a second
09:49 AM mouseghost: are there things like I2C programmers and such?
09:49 AM cehteh: wake up by that interrupt, query temperature, query time, write time into a buffer (if preserved in deep sleep) .. go back to sleep
09:49 AM cehteh: once the buffer is full you write it to the SD card .. lets say you have a buffer for 60 values .. so you write once per minute
09:49 AM mouseghost: wake up, turn off alarm clock, go back to sleep
09:50 AM mouseghost: ah, thats a good idea
09:50 AM cehteh: if possible you want to batch work that can be delayed together
09:51 AM mouseghost: thanks for great help
09:51 AM mouseghost: now i need to learn how to use interrupts :D
09:51 AM cehteh: readign time abive can be optimized out as well . .you only need to query time from the rtc at boot, then count seconds, and lets say once a hour or so you query it again in case sometihng changed
09:51 AM cehteh: such a temperature logger can prolly be done with an attiny
09:52 AM mouseghost: cehteh, im not sure how will i manage the sd card
09:52 AM mouseghost: i personally would use petitfatfs probably, buuut then im not really sure how do i interface with an sdcard
09:52 AM mouseghost: and to my surprise, theres the 'arduino' library and what more?
09:53 AM cehteh: dunno, i dont use arduino
09:53 AM mouseghost: cehteh, did you use sdcard ever? how did u use it?
09:53 AM mouseghost: ok so apparently petit version doesnt require this ctrl_sync thing, i think
09:54 AM mouseghost: cause i had no luck finding sd card library other than arduino's
09:54 AM cehteh: no i havnet used sd cards yet, but usually (by standard) sdcards have an SPI mode which is easy to use form AVR's just being very slow
09:55 AM cehteh: possibly i would just do raw writing without filesystem, and write some software to read and parse that in, that saves a lot pain
09:55 AM mouseghost: i knooow but im not sure whether windows will acknowledge a binary sd card
09:55 AM cehteh: i dont use windows :D
09:55 AM LeoNerd: I've done SD cards from AVR before
09:55 AM mouseghost: and about spi, is there some kind of ready done library, or is it that easy that i dont need one
09:56 AM mouseghost: LeoNerd, what did you use?
09:56 AM LeoNerd: Maintaining a simple FAT16 filesystem and a single CSV file, say, is easy enough on a datalogger
09:56 AM LeoNerd: 328P
09:56 AM cehteh: there are multiple libs on varying levels and quality
09:56 AM LeoNerd: Oh, in terms of software I just wrote it myself
09:56 AM LeoNerd: I needed to keep two files up in the air at once and I coudlnt
09:56 AM cehteh: yeah fat and single file may work prety well
09:56 AM LeoNerd: I needed to keep two files up in the air at once and I couldn't find a library that lets you open more than one file. So I wrote one
09:56 AM mouseghost: oh
09:56 AM mouseghost: wow
09:57 AM flip214: I write AVR assembler and compile via gcc-avr. Is there a way to have gdb "open up" a macro so that the individual opcodes are visible when showing the source?
09:57 AM mouseghost: ive stopped at reading fat headers
09:57 AM LeoNerd: FAT16 + CSV really isn't very hard
09:57 AM LeoNerd: FAT32 is a little trickier, but if you stick to smaller SD cards you don't need it
09:57 AM mouseghost: hm
09:57 AM cehteh: bootloader from sdcard would be handy .. put a firmware.hex on it and it flashes it
09:57 AM LeoNerd: Yeah I've seen SD card bootloaders as well
09:58 AM cehteh: and instead csv you may use some record based file structure
09:58 AM LeoNerd: Mine needed to be compatible with windows-using non-techies at a conference
09:58 AM LeoNerd: who could justabout cope with opening a CSV in Excel
09:59 AM cehteh: no lentgth/offest calculation and reading the file first, just poke data at the correct place and done
10:00 AM cehteh: you could CSV fixed record sizes as well, i guessthe SD card had enough space anyway
10:00 AM LeoNerd: CSV is still append-only so it's not that hard. No need for fixed record sizes
10:00 AM LeoNerd: Especially in a data logger which isn't going to need to read back its own data, it can just append
10:00 AM cehteh: <16chartimestamp>, <8char temperature>\n
10:01 AM cehteh: something like that
10:07 AM mouseghost: uh i think the hardest part for me is FAT in here
10:08 AM mouseghost: idk if i find 2GB sdcard though
10:08 AM mouseghost: wow these new colors are very cool
10:12 AM mouseghost: oh so i can basically get 8GB sd card and make 1 2GB volume on it and FAT16 will fit? LeoNerd
10:13 AM LeoNerd: Yeah you could also do that
10:14 AM LeoNerd: Though beware, that bigger than a certain physical size and SD cards become a different IO protocol than the smaller ones
10:14 AM LeoNerd: I -think- it's 64GB though I can't quite remember
10:15 AM mouseghost: well i wont go that big
10:15 AM mouseghost: its just kinda hard and expensive to get 2GBs :/
10:16 AM mouseghost: though, i guess ill just put petitfs there, im still scared of implementing that
10:20 AM mouseghost: thanks .w.
10:27 AM _abc_: is serdisplib ported to avr? http://serdisplib.sourceforge.net/
10:31 AM mouseghost: i wonder if its a bad idea to set block length and then read block in accordance with offset and count of function or to read whole 512 bytes and then loop over them to get whats my point of interest?
10:40 AM cehteh: 512bytes is already 1/4 of the memory you have :D
10:40 AM cehteh: depending on mcu
10:40 AM cehteh: some have even less
10:47 AM mouseghost: cehteh, im thinking of getting a ATtiny1634 :P
10:47 AM mouseghost: so 1/2 :D
10:47 AM LeoNerd: The 1634 is not a great chip
10:48 AM LeoNerd: It has two UARTs so if you need that, then great; but that aside it doesn't have much going for it. It's not one of the new 1-series chips, it also doesn't run that fast,...
10:48 AM mouseghost: ah
10:49 AM mouseghost: wrr they should mkae 3 chips like 1 - nobody likes it 2 - low power 3 - gaming
10:49 AM LeoNerd: I prettymuch just pick the new 1-series chips for anything new I design now
10:49 AM cehteh: check tiny85 or tiny84 .. or go with atmega328p
10:50 AM LeoNerd: tiny84 is also kinda terrible... at least the 841 is basically a bit nicer than that
10:50 AM mouseghost: cehteh, isnt the ram on that a bit too samll?
10:50 AM LeoNerd: But honestly, just use a new one :)
10:50 AM cehteh: the tinys are prolly too small when you dont know yet how to do it
10:51 AM LeoNerd: Prettymuch the only thing the new ones can't do that the older ones can, is fCPU directly from a crystal. And actually I find that's fairly rare that it matters
10:51 AM mouseghost: s/small/tiny/
10:51 AM cehteh: i'd possibly leave avr lad anyway going for risc-v
10:51 AM mouseghost: :o
10:51 AM mouseghost: how does that work
10:51 AM mouseghost: LeoNerd, is there a trick to telling if its a new one or not or do you just know?
10:52 AM LeoNerd: The new ones are totally different. They're called "1-series". They program over UPDI and not SPI
10:52 AM cehteh: 328p is just extremely common, i could recommend you as beginner to use that, has a lot support and lots of tihngs you can tinker with without worrying to run out of resources too early
10:52 AM LeoNerd: They have timers called TCA, TCB, ... not TIM0, TIM1, ...
10:52 AM LeoNerd: They have unified memory,... loads of really huge differences
10:53 AM cehteh: for myself i havent looked at the new 1-series .. they have nice features but support on the free toolchains isnt such widespread yet
10:53 AM LeoNerd: I use them just fine from avc-gcc + avr-libc in debian
10:53 AM cehteh: and still they are 8 bit avrs with all their benefits and downsides
10:53 AM cehteh: https://www.seeedstudio.com/Sipeed-Longan-Nano-RISC-V-GD32VF103CBT6-Development-Board-p-4205.html some of those should be in the post soon
10:54 AM cehteh: AVR's == easy to program, electrically robust, quite forgiving ...
10:54 AM cehteh: but rather low performance and pricy for what they do
10:54 AM LeoNerd: Oh the new chips are also a good bit cheaper than the older ones as well
10:56 AM mouseghost: LeoNerd, idk how do you program these new chips
10:56 AM mouseghost: are there programmers for that or what?
10:56 AM cehteh: maybe but i doubt they can complete with the simpler 32biters when you consider performance as well .. but if you only need little processing power they surely shine
10:56 AM LeoNerd: Any UART can write them by just adding a resistor. But also I make/sell dedicated cables with that already built on
10:57 AM mouseghost: i have problems with connecting a programmer so...
10:57 AM LeoNerd: ?
10:57 AM mouseghost: i think ive friend 1/2 atmegas ive had
10:57 AM mouseghost: lol
10:57 AM mouseghost: or i just cant connect them
10:59 AM cehteh: be more careful
10:59 AM cehteh: double check what you are doing
10:59 AM cehteh: and READ THE DATASHEETS
11:00 AM _abc_: Are silabs micros off topic? :) busy bees etc?
11:01 AM mouseghost: i guess you are right cehteh, though its still a little bit enigmatic to me, as of how to program it and how does everything work
11:02 AM mouseghost: is using usbasp is laughable or not?
11:02 AM cehteh: usually irt works, so its ok
11:02 AM LeoNerd: They're not great, but they're cheap and easy to obtain and work fine enough for the older ISP chips yeah
11:03 AM mouseghost: what do you use?
11:03 AM cehteh: of course you need to make everythinf else right, power source, connections, settings/config
11:04 AM cehteh: i use/used usbasp .. on some chups i have usb bootloaders and now the polulu programmer which is really fast
11:04 AM cehteh: on LeoNerd's recommendation iirc
11:04 AM LeoNerd: Yah the polulu is nice :)
11:04 AM LeoNerd: I built mine into a fancy box
11:05 AM cehteh: but when you dont get the usbasp to basically work then you doing something wrong anyway
11:05 AM mouseghost: looks nice, isnt a lot more expensive too
11:06 AM LeoNerd: https://twitter.com/cpan_pevans/status/1043941566770008064
11:06 AM mouseghost: cehteh, hey it worked the second time
11:06 AM LeoNerd: ^-- power supply/control/monitoring
11:06 AM mouseghost: it looks really nice
11:06 AM mouseghost: whats that little board under the mcu LeoNerd?
11:06 AM mouseghost: what's it called
11:06 AM LeoNerd: 8 LEDs and a pin header
11:06 AM LeoNerd: Makes debug a lot easier :)
11:07 AM mouseghost: LeoNerd, i mean, the board you connect the big cable to
11:07 AM mouseghost: oh its like that
11:08 AM mouseghost: ah nvm i guess
11:08 AM LeoNerd: Oh, that's just a 14pin ATtiny dev board. One of these => https://www.tindie.com/products/bot_thoughts/attiny84-development-board/
11:10 AM cehteh: LeoNerd: btw do you know how the 328pb drives the crystal exactly? when i scope the crystal pin i get some noisy sine (thats ok)
11:10 AM cehteh: but once a while a higher voltage peak and pretty much distortions
11:10 AM LeoNerd: Ah I've not really looked into it
11:11 AM cehteh: checked that since i figured out that 18.43mhz is actually overclocking :D
11:11 AM cehteh: lemme take a pic
11:11 AM LeoNerd: Yeaahh...
11:12 AM mouseghost: i need some insight into why do i need a capacitor as well lol
11:12 AM mouseghost: but that goes into ##electronics i gue4ess
11:17 AM cehteh: LeoNerd: https://pbs.twimg.com/media/EH0SPJRWwAEN72V.jpg
11:19 AM cehteh: as you see i can reliably trigger on that peak
11:19 AM cehteh: no idea bout the caus
11:19 AM LeoNerd: cehteh: Hmm bit of a wobble there indeed
11:20 AM cehteh: itsn ot the wobble, its the peak on which i trigger in the center which looks odd
11:21 AM cehteh: wobble is maybe some harmonics in the osc, not nice either but anyway it works
11:48 AM _abc_: you likely have unclean ground and or ground bounce.
11:48 AM _abc_: use 1:10 scope probe setting.
11:48 AM _abc_: can also be resonance of the scope probe excited by the osc
12:18 PM cehteh: its a 1:10 probe, but yes i could imagine measuring artifacts as well
05:50 PM mouseghost: how can i treat chip select, miso etc..? like they have no load? so i can freely use a voltage divider?
05:51 PM djph: mouseghost: what?
05:51 PM mouseghost: like i knew .w.
05:53 PM djph: mouseghost: why would you want a voltage divider on CS, etc?
05:53 PM mouseghost: djph, connecting 5V MCU to a 3.somethingV sdcard
05:55 PM djph: voltage divider may work in a pinch; better to use a level shifter
05:56 PM mouseghost: ahm
05:57 PM mouseghost: djph, do i have to build it?
05:58 PM djph: build what?
05:59 PM mouseghost: level shifter
05:59 PM djph: oh, no, you can get them from e.g. sparkfun
05:59 PM djph: probably also ebay, etc.
06:00 PM mouseghost: expensivee
06:03 PM djph: oh? $4.50 for 5 of them on ebay
06:09 PM mouseghost: almost 4zł for 1 ! D: