#avr Logs

Oct 03 2020

#avr Calendar

09:50 AM vmt: --
10:38 AM Igloo: I must be doing something silly; can anyone see why https://pastebin.com/sDbrrdjH doesn't turn the LED off please?
10:48 AM cehteh_: set the prescaler as very last, because that starts the timer
10:48 AM cehteh_: try w/o sleep
10:52 AM cehteh_: sleeping needs bit more preparations .. set_sleep_mode / sleep_enable power control registers etc
10:54 AM rue_bed2: Igloo,
10:54 AM rue_bed2: use proper tested macros for turning bits on and off, it will save you a lot of trouble
10:55 AM Igloo: It doesn't work if I while(1) { } instead of sleeping, and set TCCR0B last
10:55 AM Igloo: What sort of macros do you mean, rue_bed2?
10:57 AM rue_bed2: a macro for explicity turning a bit on or off, that is named as such and tested
10:57 AM Igloo: Oh, you mean I should define my own macros?
10:57 AM rue_bed2: if you like, sure
10:58 AM Igloo: Well, I can do that, but it's not going to make this work
10:58 AM rue_bed2: but dont use a pile of logic operators as people usually screw them up and take 2 days trying to debug them
10:58 AM vmt: that's bull
10:59 AM rue_bed2: you would say that
10:59 AM vmt: i would know that
11:00 AM vmt: or to set, and to clear, xor to toggle. you can use BV to make a mask if you want, but it's still just
11:00 AM cehteh_: the _BV macros are avr-libc the work
11:00 AM cehteh_: like it or not
11:00 AM rue_bed2: have you not been here the last 18 years, helping people who screwed up logic operators for seting/clearing bits of ports and memory
11:00 AM vmt: as far as i know it's `#define _BV(x) (1 << (x))`
11:00 AM vmt: i.e. not really needed
11:01 AM cehteh_: well i havent looked at the details of his code yet
11:01 AM cehteh_: yeah lots people dislike _BV
11:01 AM vmt: rue_bed2: no i think it's not really the problem
11:01 AM cehteh_: either way, themself _BV isnt the source of the error, its application may be
11:02 AM cehteh_: but using a constant like 5 there might be the problem
11:02 AM rue_bed2: maybe its cause sei() isn't called?
11:02 AM vmt: REG |= (1 << x); set bit x, REG &= ~(1 << x); clear bit x, REG ^= (1 << x) toggle bit x
11:02 AM cehteh_: haha
11:03 AM Igloo: Aha, I think my problem is that interrupts aren't enabled by default, and I need to sei()
11:03 AM cehteh_: ack missed that
11:03 AM cehteh_: but thats iirc still the wrong pin
11:03 AM rue_bed2: B5 sounds right
11:04 AM Igloo: Told you I was doing someting silly :-)
11:04 AM cehteh_: b5 is right but 1<<5 = 0b100000
11:04 AM rue_bed2: you should also name macros so its clear what your up to , it will save you time
11:05 AM Igloo: Thanks for the help, all
11:05 AM rue_bed2: mhm
11:05 AM cehteh_: use the offical constants, not magic numbers
11:05 AM rue_bed2: well, another morning
11:06 AM vmt: you need some magic in your life
11:06 AM cehteh_: _BV(5) == 6th bit
11:06 AM rue_bed2: I thin I'm going to have some fruit loops for breakfas
11:06 AM cehteh_: counting starts at zero
11:07 AM rue_bed2: #define SetBit(BIT, PORT) (PORT |= (1<<BIT))
11:07 AM rue_bed2: #define ClearBit(BIT, PORT) (PORT &= ~(1<<BIT))
11:07 AM rue_bed2: #define IsHigh(BIT, PORT) (PORT & (1<<BIT)) != 0
11:07 AM rue_bed2: #define IsLow(BIT, PORT) (PORT & (1<<BIT)) == 0
11:07 AM rue_bed2: #define NOP() asm volatile ("nop"::)
11:07 AM rue_bed2: #define ABS(a) ((a) < 0 ? -(a) : (a))
11:07 AM rue_bed2: tell me all about how much you dont like those
11:07 AM rue_bed2: and how stupid they are
11:08 AM cehteh_: nah would be nice if they are libc
11:08 AM vmt: lol. wtf for do you need a nop macro fi you're writing C to begin with?
11:08 AM vmt: fi=if
11:08 AM rue_bed2: for (i = 0; i < 70; i++);
11:08 AM rue_bed2: how many times does that loop?
11:08 AM rue_bed2: +-1
11:08 AM rue_bed2: cmon
11:08 AM cehteh_: but usually i hide thos pin modification somewhere already i can do bit fiddling in these things hiding them already
11:08 AM rue_bed2: how many times
11:08 AM vmt: 70 times
11:08 AM rue_bed2: nope
11:09 AM vmt: ok?
11:09 AM rue_bed2: the compiler optimizes it out
11:09 AM rue_bed2: 0 times
11:09 AM vmt: but for what do you need that
11:09 AM rue_bed2: for (i = 0; i < 70; i++) NOP():
11:09 AM rue_bed2: for (i = 0; i < 70; i++) NOP();
11:09 AM rue_bed2: delay
11:09 AM cehteh_: sux
11:09 AM vmt: isn't there a delay in avr libc?
11:09 AM rue_bed2: what if you just need to delay a few cycles
11:09 AM cehteh_: while (time()<destination_time);
11:10 AM rue_bed2: a few cycles
11:10 AM rue_bed2: your delay takes more than a few cycles just to set up
11:10 AM cehteh_: well yes then i use the delay from the libc
11:10 AM vmt: when do you want cycle-precise control when you're writing c to begin with?
11:10 AM vmt: just throw me a bone here
11:10 AM rue_bed2: sometimes you need a cyclce or two for an input to stabalize
11:10 AM rue_bed2: or an output
11:11 AM cehteh_: when i really want ony few cycles then i do NOP; NOP; NOP; unrolled .. thats 100% exact
11:11 AM rue_bed2: I mean, 1 or 2 cycles and you just stick in the nop directly
11:11 AM rue_bed2: but
11:11 AM cehteh_: and as soon its more than a handful of cycles i am doing something wrong anyway
11:11 AM vmt: when have you last used this
11:11 AM rue_bed2: I'v had too many libraries change things on me, so I use my own
11:11 AM cehteh_: nop in a *counting* loop isnt pretty good
11:12 AM cehteh_: also for (volatile int i = 0; i < 70; i++); ... wont be optimized out iirc
11:12 AM rue_bed2: I used it for a delay after starting the ADC to give the interrupt time to sweep all the channels
11:12 AM vmt: also i mean, compiler optimization is a thing you don't need to do
11:12 AM rue_bed2: makes a pretty good diff
11:12 AM vmt: if you want increment + jump
11:13 AM rue_bed2: I actually count down, its faster :/
11:13 AM cehteh_: depends on the arch
11:13 AM vmt: i don't really care, but whether the loop executes once or 0, is really dependent on what you compile it with
11:13 AM cehteh_: yeah
11:13 AM vmt: i mean 70 times or 0 times.
11:14 AM rue_bed2: void longDelay( uint32_t d) { for (;d;d--) NOP(); }
11:14 AM cehteh_: either dedicated NOP's unrolled, not in a loop ... or while() on timer
11:14 AM rue_bed2: if you put nothing in a for loop, gcc removes it for you
11:14 AM vmt: #include <util/delay.h>
11:15 AM cehteh_: and any longer delay is really malpractice, besides it could be interrupted and/or you dont want to block interrupts for long times anyway
11:15 AM vmt: rue_bed2: your NIH is stronger than i thought
11:15 AM rue_bed2: sure, and if they change the library call you get to rewrite all your code
11:15 AM vmt: duuuuuuuuuuuuuuude
11:15 AM cehteh_: avr-libc also defines nop
11:15 AM rue_bed2: you know how many times ncurses has changed the arguments to their functions?
11:15 AM rue_bed2: LOTS
11:15 AM vmt: you're treating your avr code like it's some 10 M loc codebase
11:16 AM cehteh_: and updated constantly :D
11:16 AM vmt: also, i'm pretty sure the delay function sigs have never changed ever since they were originally published
11:16 AM rue_bed2: same with QT, they LOVE to change the arguments to functions
11:16 AM vmt: dude it's fucking avr-libc vs a full-blown gui (well everything + kitchen sink) toolkit
11:16 AM vmt: for god knows how many platforms
11:16 AM vmt: they simply do not compare.
11:17 AM rue_bed2: I also come form a say before gcc-avr supported binary number formats
11:17 AM vmt: in any way, shape or form
11:17 AM cehteh_: even if .. .when you have some old rusty code/project you may just stick it to an old libc version *or* port it to a newer one if there are really changes that are problematic
11:17 AM vmt: rue_bed2: your NIH is really hitting unprecedented levels
11:17 AM cehteh_: :)
11:17 AM rue_bed2: I'v hit my head on a few of the changes to GCC too
11:18 AM vmt: ...
11:18 AM vmt: avr-gcc != gcc
11:18 AM cehteh_: i am constantly changing the api's of muos, eventually i am coming to a point where i am satisfied and its stable, but i am not there yet
11:18 AM vmt: i figure next up you're going to roll your own silicon just because maybe they'll also change pinouts for the fuck of it for your precious tinys and megas
11:19 AM cehteh_: and changing firmware to the changed api's is usually not so much work, most often it makes things easier, beause that was the point of the api changfe
11:19 AM rue_bed2: I need to move some code from a t13 to something larger soon....
11:19 AM rue_bed2: oh vmt because I do my own libaries I can port stuff to stm32 easier too
11:19 AM vmt: but then you also need to roll your own chip fab because what if the fab of your choice performs some changes which render you unable to produce your silicon design
11:19 AM rue_bed2: with no abstraction layers
11:19 AM cehteh_: FPGA fab!
11:20 AM vmt: rue_bed2: incorrect. the only thing which is non-trivial to port is the cortex clock and periphreal setup
11:20 AM cehteh_: i mean yes you need to make fpga's ... but these with a rigid design not changing anything
11:20 AM vmt: everything else is trivial.
11:20 AM rue_bed2: I'll have to one day, hopefully i have a few hundred years before I need to
11:20 AM vmt: your delay macro isn't going to make the porting any easier (nor harder, for that matter...)
11:20 AM vmt: well, function...
11:20 AM rue_bed2: its good, I have NOP() defined for the other platform
11:21 AM rue_bed2: it worked like a charm
11:21 AM vmt: sure. but that's trivial. read that twice, for good measure
11:21 AM rue_bed2: actually, I dont even recall if I had to change the definition...
11:21 AM vmt: the only NON-TRIVIAL thing to port, is THAT OF THE CLOCK AND PERIPHERAL SETUP. I CANNOT EMPHASIZE THIS ENOUGH
11:22 AM rue_bed2: yea, thats big going to stm32
11:22 AM vmt: there is LITERALLY ZERO COMPATIBILITY IN initializing avr peripherals and cortex-m ones
11:22 AM rue_bed2: tho, porting the software i2c library wasn't a killer
11:22 AM rue_bed2: I do all the init in main usually, makes a mess
11:22 AM vmt: the business logic stays the same. once you set the peripherals up, the changes are NOT A BIG DEAL
11:23 AM vmt: unless, you want dma. and you know what? then your crappy avr code flies out the window
11:23 AM vmt: because avrs still, to date, don't even have dma capability. rofl
11:23 AM rue_bed2: I should use stm32 more, but I still want to save them for stuff that needs the extra kick
11:23 AM vmt: well, tiny/mega series
11:24 AM vmt: perhaps there's some super obscure ones that do, i may be corrected
11:24 AM rue_bed2: if I could get a working C library for using the onboard usb as a serial I/F I'd probably cave on a few projects
11:25 AM rue_bed2: there was a statement by microchip that they are really really really trying to make sure they dont drop anything from the product line
11:25 AM rue_bed2: and that anything they did was because there was no upstream supply available anymore
11:26 AM rue_bed2: which actually made it sound a lot like they dont to their own silicon
11:26 AM rue_bed2: and I'z pretty sure they do
11:27 AM vmt: don't trust them!
11:28 AM vmt: also don't trust avr-gcc mcp might fuck it up too
11:28 AM rue_bed2: in 2005, a buddy of mine wrote a program for the jukebox in c++
11:28 AM rue_bed2: a simple little utility
11:29 AM rue_bed2: it doesn't compile anymore because of multiple changes that have been made to g++
11:29 AM rue_bed2: it wasn't worth fixing
11:29 AM rue_bed2: but I was surprised at how short the code life was
11:30 AM rue_bed2: most of the changes to gcc have been about the libraries it auto-includes
11:30 AM vmt: c++ in general goes through a lot of changes because the committee consists of namely retards
11:30 AM rue_bed2: well, you never know what the retards will control next
11:30 AM vmt: but, they need to get paid and perpetuate the language with the adage of if it isn't broken, break it
11:31 AM rue_bed2: there is a lot of work to lower the entry barrier to things
11:31 AM vmt: you can still pull an old version of g++ or whatever compiler to compile it
11:31 AM rue_bed2: like the US presidnecy
11:31 AM vmt: c is far more stable than c++
11:31 AM rue_bed2: yea
11:31 AM vmt: though, i think there are people who sit in both committees
11:32 AM vmt: and therefore c is becoming more convoluted as well. but there's no need to use the latest compiler
11:32 AM rue_bed2: I was up till 3am
11:32 AM rue_bed2: its 9:31
11:32 AM rue_bed2: am
11:32 AM rue_bed2: aparently I'm awake tho
11:33 AM rue_bed2: suppose I should just start my day
11:33 AM rue_bed2: vmt, what kinda projects do you use avrs in?
11:33 AM rue_bed2: what were my last few...
11:33 AM vmt: i haven't done any mcu stuff in oh about 5 years
11:34 AM vmt: or maybe 4. hard to keep track of the years as you get older
11:34 AM rue_bed2: a tone generator, a resistor decade box, a power supply....
11:35 AM rue_bed2: oh the plasma bar controller
11:35 AM rue_bed2: the led bar array
11:35 AM rue_bed2: on the coil winder
11:35 AM vmt: last thing i probably made completely myself was hooking up a vlsi (the finnish company) mp3 decoder to a 1284 for a music player. i had one of those laying around and probably around 8 or so years ago i got free samples for various chips from vlsi
11:36 AM rue_bed2: I did a vfd controller recently... oh a silly little audio event thing
11:36 AM vmt: that was a thing where i could have used dma. streaming spi to spi. but it was just a project out of curiosity
11:36 AM rue_bed2: there is the water dispencer I did this year
11:37 AM rue_bed2: I switched the filter profiler to stm32
11:37 AM rue_bed2: avr couldn't do capture on enough channels at once
11:38 AM rue_bed2: oh I did the encoder DAC interface thing, and a product for a customer, a door alarm with some special behaviour
11:38 AM rue_bed2: huh, there have been a lot of projects this year
11:39 AM rue_bed2: heh, I did some code to vector draw an R on scope XY
11:40 AM rue_bed2: ? oh, it was this year, I made a LM3914 setup, but using charlieplexing to make a 12 element led bar graph via analog input
11:40 AM rue_bed2: so much smaller than a 3914 :)
11:41 AM rue_bed2: huh, no tiny26 projects this year
11:42 AM cehteh_: btw .. i ma just brainfarting how to get most of the range from a LDR
11:42 AM cehteh_: http://tinyurl.com/y62fwt8c
11:42 AM rue_bed2: t13, m88, m8, m328
11:42 AM rue_bed2: cehteh_, 200 ohms to 22+Mohms not enough?
11:43 AM cehteh_: the ones i ordered are 5k to 500k
11:43 AM cehteh_: with range i mean the ADC range
11:43 AM rue_bed2: why is that capacitor charging?
11:44 AM cehteh_: just get rid of noise and have a stable upper point
11:44 AM rue_bed2: k....
11:44 AM cehteh_: and at output its internal 1v1 VREF
11:44 AM rue_bed2: cehteh_, have you seen the ldr modules I did?
11:44 AM cehteh_: no
11:45 AM rue_bed2: the "straw hat" leds work great with them
11:45 AM rue_bed2: k
11:45 AM rue_bed2: I.... suppose I should have made a page
11:45 AM Igloo: While I'm asking stupid questions, I don't suppose anyone knows anything about Rigol DSOs? I can't figure out why I'm not seeing a trace in the main display in delayed-sweep mode: http://the.earth.li/~igloo/tmp/scope.jpg
11:45 AM rue_bed2: I'll tyr to collect it later today for ya
11:46 AM rue_bed2: does the blue mark the trigger point?
11:47 AM rue_bed2: my tek has to be running to do some operations
11:47 AM rue_bed2: cant be in stop
11:47 AM Igloo: The bottom half should be showing the non-blue region of the top half
11:48 AM rue_bed2: thats a nice scope
11:48 AM rue_bed2: funny how the specs on my 20 year old tek 754c are better.....
11:48 AM rue_bed2: thing must have been a million dollars in its day
11:49 AM rue_bed2: Igloo, does it come up if you have a capture running?
11:49 AM Igloo: The Internet pretty much unanimously recommend this one for a cheap DSO
11:49 AM Igloo: Nope
11:49 AM rue_bed2: interesting
11:50 AM rue_bed2: the tek was $1k, I'm super feaked out it might die
11:50 AM rue_bed2: but it hasn't
11:50 AM rue_bed2: I'v had it a year now :)
11:50 AM rue_bed2: but I love it
11:51 AM rue_bed2: Igloo, I cant see anything then
11:51 AM Igloo: Hmm, I pressed auto, reset time/volts, and now it works
11:52 AM Igloo: I wish I knew what setting it had changed
11:52 AM rue_bed2: it was just a time zoom, right?
11:52 AM rue_bed2: looked like it
11:53 AM Igloo: Yeah; the point is you can capture say 0.1s worth, but be looking at it zoomed in, so you can see what it's actually doing
11:53 AM Igloo: Normally, if you do a single capture when zoomed in, it only saves a screen's width
11:56 AM rue_mohr: I'd had a few digital buffer dissapointments with my tek
11:57 AM rue_mohr: like "oh cmon, its in the memory buffer, do the thing!"
04:40 PM cehteh: are there any ill side effects when one underclocks the ADC, freerunning at rather high prescaler.
04:40 PM cehteh: like the sample&hold becomes inprecise or such
11:45 PM day_ is now known as day