#avr Logs

Sep 17 2017

#avr Calendar

12:07 AM * rue_shop3 yells some jibberish and throws a cat at Cracki
02:34 AM polprog: im going shopping for stuff... should i get an strlink v2 or v3?
02:34 AM polprog: stlink*
02:34 AM polprog: i wanna use it with the blue pill
02:55 AM sabor: dgriffi2: sorry, i was on a trip, do you still need help?
02:58 AM dgriffi2: yes, please
02:58 AM sabor: how can i help?
02:59 AM dgriffi2: I've made a bit of progress... learning that the android dtmf detector apps are crap
02:59 AM sabor: hehe
02:59 AM dgriffi2: they can't deal with rapid tones
03:00 AM dgriffi2: I will be building a dtmf decoder arduino shueld to investigste further
03:01 AM dgriffi2: I'm left with 1) 7-bits aren't good enough and 2) the low-pass filter's cutoff is too low.
03:01 AM dgriffi2: maybe both
03:02 AM sabor: 7-bit ADC or DAC?
03:02 AM dgriffi2: the shield will use an mt8870 dtmf decoder chip
03:02 AM dgriffi2: dac
03:02 AM dgriffi2: the sine table is 7-bit, 0 to 127
03:02 AM sabor: i'd expect a 7-bit DAC to be good enough
03:03 AM sabor: aah, yeah, 2 times 7bit signal added -> 8-bit
03:03 AM dgriffi2: two tones added up fit into 8 bits, but it's still 7-bit quality
03:03 AM sabor: yes
03:04 AM dgriffi2: then I found I had the 0v midpoint wrong
03:04 AM sabor: but i assume phones used only square waves to generate the tones to save money for a DAC
03:04 AM dgriffi2: dudn;t make much diffetence
03:04 AM dgriffi2: no. they were always sines
03:05 AM sabor: wow, kk
03:05 AM dgriffi2: afk a bit
03:05 AM sabor: did you measure your signals?
03:19 AM Emil: polprog: no such thing as stlink-v3
03:20 AM Emil: polprog: here's the list of official stm debug hardware: http://www.st.com/en/development-tools/debug-hardware-for-stm32-mcus.html?querycriteria=productId=LN1117
03:21 AM Emil: As you can see, ST-LINK/V2 is the latest
03:21 AM Emil: polprog: I hope you didn't already fall to the ruse :D
03:21 AM Emil: That ebay sellers present you with
03:25 AM polprog: Emil: havent bought anything yet
03:32 AM dgriffi2: sabor: I don't have a 'scope
03:34 AM polprog: ok, since te linux channel im in is ded, maybe you can help me
03:35 AM polprog: i have a script that back up the whole / and pipes tar output to standard out. I run this script over ssh which's output is written to a local .tgz file. I need to run that script remotely as root. How do i do it?
04:05 AM sabor: dgriffi2: since it is audio you could measure that signal with your sound card
04:10 AM polprog: ik, i got that sorted
04:20 AM dgriffi2: sabor: can you suggest a program for doing the analysis? Audacity?
04:21 AM polprog: audacity would be good for DTMF
04:21 AM polprog: it has spectral analysis functions
04:21 AM polprog: and can show a spectrogram
04:22 AM antto: i have a dirty spectrograph standalone app for win32 ;P~
04:34 AM mmfood: How high impedance is enough to not interfere with icsp programming pins? Would a 10k pullup resistor for a button be enough?
04:35 AM polprog: yeah, i think
04:48 AM Emil: polprog: but yeah, there's no stlinkv3
04:48 AM polprog: yeah
04:48 AM polprog: i mistaken it for pickit 3
04:48 AM Emil: mistook*
04:49 AM Emil: polprog: also why not use rsync?
04:50 AM polprog: Emil: i need to try rsync
04:50 AM polprog: also, i wanna keep the backups small so i used tar
06:12 AM mmfood: "You just need spi clk and mosi from the avr, and one output to rclk on the 595" am I right to assume spi clk = sck, and rclk = storage register clock input, on the 595?
06:13 AM polprog: doing 595 i see
06:14 AM polprog: i wrote a 595 handler in software
06:14 AM polprog: in c and assembly
06:18 AM polprog: you clock in the data to DS and the clock to SHCP, then send a pulse to STCP to copy the shift register to storage register
06:18 AM polprog: see the datasheet for waveforms :P
06:19 AM polprog: you shouldn't need delays since 595 can go up to 40MHz (at least the NXP version does)
06:20 AM Emil: Ah a sipo
06:20 AM polprog: so SCK goes to SHCP and MOSI to DS
06:20 AM polprog: and you have to wiggle the STCP in software
06:22 AM Emil: Dat function table makes no sense
06:22 AM Emil: https://emil.fi/jako/kuvat/2017-09-17_13-51-29_QzboinNm.png
06:22 AM Emil: This table is impossible
06:22 AM Emil: Unless x means high impedance
06:22 AM Emil: instead of don't care
06:23 AM polprog: is this the TI datashet?
06:23 AM polprog: it makes sense
06:23 AM polprog: OE' is output enable
06:24 AM Emil: Ah yeah I didn't read enough
06:32 AM mmfood: polprog: yes sck -> shcp, and mosi -> DS, and then any port as latch -> stcp?
06:32 AM polprog: 1any pin a stcp
06:32 AM polprog: any*
06:32 AM mmfood: yes, pin, not port
06:32 AM polprog: i sugest a pin close to SPI port, it will be easier to route the connections
06:33 AM polprog: btw, what avr are you using
06:33 AM polprog: ?
06:34 AM mmfood: atmega 328 atm, but my goal is to use a attiny85 and 2x 595 to drive the 4 digit 7 segment leds
06:35 AM polprog: check if you can fit in your code to a tiny 85.
06:35 AM polprog: see avr-size
06:36 AM polprog: i dont remember how much flash or ram does a t85 have but it's not much :P
06:36 AM dgriffi2: 8k
06:36 AM dgriffi2: my current oroject uses it
06:36 AM polprog: should be enough :P
06:37 AM dgriffi2: mmfood: what are you doing with it besides driving 4 7-segment displays?
06:38 AM Emil: mmfood: don't. say. 328. if. you. mean. 328p.
06:38 AM mmfood: actually the pins might be too few on the attiny, I need 3 for the spi, and then on button to enter som kind of set mode for the time and then 2x buttons or an encoder for inc/dec time
06:38 AM mmfood: it is a countdown timer
06:39 AM Emil: achsuahly
06:39 AM dgriffi2: there are 14(?) pin attiny variants that might suit you
06:39 AM Emil: mmfood: can you quickly list the functionality you want?
06:41 AM polprog: try tiny4313 or tiny2313
06:41 AM mmfood: 1. countdown time in mm:ss format. 2. reset on button press 3. a "set mode" to set a new time with buttons / encoder
06:41 AM mmfood: Emil:
06:41 AM Emil: mmfood: whatcha use for display?
06:41 AM mmfood: 4x 7 segment leds
06:42 AM mmfood: with one 595 for the segments and another for the cathodes (CC)
06:43 AM dgriffi2: you can do all the buttons with one pin and a resistor ladder
06:44 AM Emil: that's one way
06:45 AM Emil: and you absolutely want to use 595?
06:46 AM mmfood: how would that work? I guess each button would give different voltages when pressed. But how would the pin read work?
06:46 AM polprog: mmfood: use the ADC to read the voltage
06:46 AM mmfood: Emil: not necessarily
06:48 AM mmfood: Emil: what would you suggest?
06:48 AM Emil: Well I would just use an atmega328p standalone prolly
06:48 AM polprog: Emil does eerything on a mega328p
06:48 AM polprog: kek
06:48 AM Emil: polprog: :D
06:48 AM polprog: i would use a mega16 or mega8
06:48 AM Emil: polprog: not my fault it's agile
06:49 AM Emil: polprog: now that's horrible
06:49 AM Emil: mmfood: but
06:49 AM polprog: Emil: wha did you say
06:49 AM Emil: mmfood: yeah you can do it on an tiny
06:49 AM Emil: t85
06:49 AM Emil: polprog: you heard me
06:49 AM polprog: t55
06:49 AM Emil: polprog: I'll smack that with some cocktails
06:50 AM polprog: you and your filthy 328p
06:50 AM polprog: besides, i also use t4313
06:51 AM Emil: polprog: 328pb <3
06:51 AM polprog: what's wrong with m16 or m8
06:52 AM Emil: wasnt that 4313 the microchip monster that was like mega but tiny amounts of storage
06:52 AM polprog: i'm not sure
06:52 AM polprog: there was some microchip monster but that wasnt 4313
06:58 AM Emil: polprog: what's the purpose of the stcp
06:58 AM mmfood: Yeah, i guess 328p might be the easiest solution. about the same price as attiny85 and 2x 595
06:59 AM mmfood: and already have the code for it :P
07:01 AM Emil: So if I'm reading this right
07:01 AM Emil: you really only need two pins to control any number of 595s
07:01 AM mmfood: I think 3?
07:02 AM Emil: DIN, CLK and what else?
07:02 AM mmfood: latch
07:02 AM Emil: There's no latch?
07:02 AM mmfood: stcp?
07:02 AM Emil: You can tie them together
07:02 AM Emil: It's not latch but another clock
07:02 AM Emil: If I'm not wrong
07:03 AM mmfood: hmm, ok
07:04 AM Emil: But
07:04 AM Emil: it has issues
07:04 AM mmfood: https://www.arduino.cc/en/Tutorial/ShiftOut
07:04 AM Emil: Like you always need to know what data to send next because shift register is always one pulse ahead of storage register
07:04 AM Emil: Wait
07:04 AM Emil: no
07:04 AM Emil: it's fine
07:04 AM Emil: yeah
07:05 AM Emil: you only need 2
07:06 AM Emil: https://emil.fi/jako/kuvat/2017-09-17_14-34-55_aDPW5c5u.png
07:07 AM Emil: So 2 pins to control the 4 7-segment displays. You have 3 remaining for buttons but you realy only need 1 :D
07:07 AM Emil: But with 3 you could attach a rotary encoder with a button
07:09 AM Emil: or just a rotary encoder and a normal button could be better
07:10 AM Emil: This whole thing fits into a tiny just fine
07:10 AM Emil: But yeah I would still prolly use an m328p because you don't need the 595s and you can do things a lot easier :D
07:11 AM mmfood: Emil: yeah
07:12 AM mmfood: what do I have to do to declare a variable in the header file but initialize it in the program file?
07:12 AM Emil: just declare the global var and then use it in program?
07:12 AM Emil: in header: type asdf;
07:12 AM Emil: in program: asdf=asdfgasdfadsf;
07:14 AM mmfood: https://paste.debian.net/986468/
07:15 AM Emil: How accurate does this countdown need to be btw?
07:17 AM mmfood: I get a warning that F_CPU is not defined, and when in the .c file II to cycle_time = 20*60; I get data definition has no type or storage class and type defaults to int in declaration of cycle_time
07:17 AM mmfood: Emil: not more than fraktions of a second / 1 hour
07:17 AM Emil: lol
07:18 AM Emil: mmfood: you do realise that the internal RC-clock is like 1-5% accurate?
07:18 AM mmfood: Emil: yes, the plan is to add an external crystal
07:19 AM Emil: mmfood: wellthen you can't use a tiny
07:19 AM Emil: t85 that is
07:19 AM Emil: the bigger ones like t84 work
07:19 AM mmfood: oh ok
07:19 AM Emil: But atmega328p works just fine
07:20 AM mmfood: Emil: yes, and it seems cheaper
07:21 AM Emil: What is this for btw?
07:22 AM mmfood: a countdown timer
07:23 AM mmfood: a good project to get started, I thought
07:23 AM Emil: It is
07:23 AM mmfood: with pure C as opposed to arduino
07:23 AM Emil: yeah don't use arduino :D
07:23 AM Emil: You can use the arduino boards, though (or at least the ones that have avrs in them)
07:24 AM Emil: but code them using pure c
07:24 AM Emil: a simple get started is https://emil.fi/avr
07:24 AM mmfood: ok, why would you say that?
07:24 AM Emil: say what?
07:24 AM mmfood: or what is your issues with arduino?
07:24 AM mmfood: just curious
07:24 AM Emil: the hal is shit?
07:24 AM Emil: the codebase is cancer
07:24 AM mmfood: hal?
07:24 AM Emil: the performance is horrendously hilarious
07:25 AM Emil: mmfood: hardware abstration layer
07:25 AM mmfood: ok ")
07:25 AM Emil: mostly because the codebase is shit and the performance is super lolz
07:26 AM Emil: C is kawaii
07:27 AM mmfood: https://paste.debian.net/986474/ compare this to https://paste.debian.net/986468/ I don't get why it is complaining about F_CPU and cycle_time
07:30 AM Emil: You need to define F_CPU before including delay
07:30 AM mmfood: ok
07:31 AM mmfood: fixed the cycle_time issue with putting type before the initialisation as well. Guess that is the way it should be ")
07:33 AM Emil: check that cycle_time is not a reserved thing
07:33 AM Emil: It shouldn't be but dunno
07:33 AM Emil: >putting type before the initialisation
07:33 AM Emil: You are just declaring it again
07:35 AM Emil: also remove the fucking nop
07:36 AM Emil: I would also just print the time in the main loop
07:36 AM mmfood: Emil: use delay us instead?
07:36 AM Emil: You don't need a delay
07:36 AM Emil: if you do it like I do :D
07:37 AM mmfood: Emil: you mean not use a function for printing?
07:39 AM Emil: I would use a timer interrupt probably to update the display
07:40 AM Emil: say every 1ms loop through them
07:40 AM Emil: It gives better and brighter result than pulsing all the characters at once
07:40 AM polprog: Emil: a high state on STCP copies the shift register to the storage register
07:41 AM Emil: polprog: it's a clock
07:41 AM polprog: wait
07:41 AM polprog: STCP, SHCP
07:41 AM polprog: ill have to check
07:41 AM Emil: https://emil.fi/jako/kuvat/2017-09-17_15-10-48_VUFBHqok.png
07:42 AM Emil: polprog: there's no direct latch
07:42 AM Emil: that transfers the whole register at once
07:42 AM Emil: https://assets.nexperia.com/documents/data-sheet/74HC_HCT595.pdf
07:42 AM Emil: At least on the documentation that I can find
07:43 AM polprog: what? im sure there is a pin you have to wiggle to copy shift to storage
07:43 AM Emil: polprog: yes, wiggle=clock
07:43 AM Emil: stcp
07:43 AM Emil: see the timing diagram linked
07:43 AM antto: while SHCP is down (iirc) - you can shift bits without affecting the output pins
07:44 AM Emil: antto: shcp is for shift in. stcp is for when you want to update the output
07:44 AM antto: if SHCP is in the other position - shifting bits also affects the output pins immediately
07:44 AM antto: ehm i meant STCP
07:44 AM Emil: antto: the timing diagram linked is clear :D
07:44 AM polprog: Emil: https://puu.sh/xBQVV/b50da6d4ce.png
07:45 AM antto: there's also the output enable pin btw
07:45 AM Emil: polprog: yes, see how there's a rising edge
07:45 AM antto: i mean, there's a pin that can set all output pins to hi-Z
07:46 AM Emil: antto: there is yes
07:46 AM polprog: im looking at my 595 code an it pulses shcp at the end, once
07:46 AM Emil: But we are trying to minimise pin usage :D
07:46 AM polprog: MR' and OE' can be tied to VCC
07:46 AM Emil: yeah
07:46 AM polprog: i have my asm routine and im trying to find the C routine
07:50 AM polprog: damnit, it's on the old laptop
07:51 AM polprog: whatever, ill show you the asm routine, it's all commented
07:52 AM polprog: https://puu.sh/xBRac/99c2f05284.png
07:55 AM Emil: polprog: wait
07:55 AM Emil: what's the difference between eor and com
07:55 AM polprog: and in that datasheet it says that when STCP goes high, the whole shift register gets copied to the storage register and the output stage
07:55 AM polprog: eor = xor, com = not
07:55 AM polprog: or maybe com = twos complement
07:55 AM Emil: com is one's complement
07:55 AM LeoNerd: Is this a 595 on an SPI port?
07:56 AM polprog: my code? it's 595 handler in software
07:57 AM LeoNerd: The shift clock is SCK, the latch clock is SS
07:57 AM LeoNerd: It's that simple
07:58 AM Emil: ah eor takes only registers
08:18 AM mmfood: is it a bad idea to set the fuse to NOT divide clock by 8?
08:22 AM Emil: no
08:22 AM Emil: it's what I do
08:22 AM Emil: to all my avrs
08:22 AM Emil: it speeds up your programming by a factor of 8, also :D
08:23 AM Emil: some say that you can change the prescaler to 1 in software when executing your own code
08:23 AM Emil: But I've yet to verify that
08:23 AM Emil: not to mention that you have to remember to do it
08:44 AM Lambda_Aurigae: the div/8 fuse just presets the prescaler.
08:44 AM Lambda_Aurigae: you can change it in code on the fly.
08:45 AM mmfood: hmm ok so does it "add" to the prescaler?
08:46 AM mmfood: meaning do I have to take that div/8 into account when calculating the prescaler and timer compare values?
08:47 AM Emil: Just disable the fuse
08:47 AM Emil: There's no point in having the divide by 8 on
08:47 AM mmfood: Emil: that's what I thought
08:49 AM Lambda_Aurigae: The CKDIV8 Fuse determines the initial value of the CLKPS bits. If CKDIV8 is unprogrammed,
08:49 AM Lambda_Aurigae: the CLKPS bits will be reset to “0000”. If CKDIV8 is programmed, CLKPS bits are reset to
08:49 AM Lambda_Aurigae: “0011”, giving a division factor of 8 at start up. This feature should be used if the selected clock
08:49 AM Lambda_Aurigae: source has a higher frequency than the maximum frequency of the device at the present operat-
08:49 AM Lambda_Aurigae: ing conditions. Note that any value can be written to the CLKPS bits regardless of the CKDIV8
08:49 AM Lambda_Aurigae: Fuse setting.
08:50 AM Lambda_Aurigae: right from the atmega1284p datasheet.
08:53 AM Lambda_Aurigae: I can see it if,,,say, you could be running at different voltages....start up at lower speed then check voltage and if you are at 5V then kick up to 16MHz, otherwise keep the speed lower to match the operating voltage
08:54 AM Lambda_Aurigae: in the datasheet they claim it is on by default for programmer compatibility....problem is, it causes compatibility issues with usbasp programmers with default firmware...but, that's not atmel's fault I suppose.
08:56 AM Lambda_Aurigae: it is also possible to turn that on then run the chip from a 32MHz crystal.
09:02 AM mmfood: allright, adjusted the prescaler and the fuse and it works great
09:03 AM mmfood: on to create another timer to let the ISR update the display
09:13 AM polprog: reminds me of a vid where somebody diped an arduino in liquid nitrogen an i think he ran it at 60MHz before it crashed :P
09:13 AM polprog: and i think*
09:25 AM Emil: 96MHz+Dma+1MB flash that you can use like eeprom +32 bit+128kB ram
09:25 AM Emil: avr
09:25 AM Emil: give me that
09:26 AM Emil: "Use an ARM"
09:27 AM Emil: Also io crossbarr
09:31 AM polprog: do you want a northbridge too?
09:34 AM Emil: lol
09:35 AM Emil: But it's a reasonable list!
09:35 AM Emil: Well
09:35 AM Emil: actually I'm content with just avr-like documentation and avr style coding
09:36 AM polprog: now that i think about it, would it be possible to use a SuperIO chip with avr?
09:36 AM polprog: :PP
09:41 AM mmfood: Emil: would it be better to create a second timer for updating the display or simply decrease the timer value to 1ms and update the display every interrupt but updating the value every 1000th interupt
09:50 AM Lambda_Aurigae: I get my 50MHz with crossbar and execute from ram on pic32.
09:50 AM Lambda_Aurigae: mmfood, do the update in the main loop.
09:50 AM Lambda_Aurigae: just let it loop and update.
09:50 AM Lambda_Aurigae: no need for extra timer or interrupt.
09:52 AM mmfood: https://paste.debian.net/986488/ like I am doing now?
09:57 AM Lambda_Aurigae: sure
09:57 AM Lambda_Aurigae: if your timer interrupt is small enough then it shouldn't interfere with the screen update.
09:58 AM mmfood: meaning the time it takes to perform the instructions in the ISR?
09:58 AM Lambda_Aurigae: yes
09:58 AM Lambda_Aurigae: which, it looks like it should be fine I would think...
09:59 AM Lambda_Aurigae: what's your max for minutes and seconds ?
10:00 AM mmfood: I would hope so, it doesn't get much shorter than that, surely?
10:00 AM Lambda_Aurigae: use uint8_t instead of unsigned int...cuts it down to a single 8bit unsigned integer rather than 16bit.
10:00 AM mmfood: 60 min
10:00 AM Lambda_Aurigae: oh, I could make the interrupt smaller.
10:01 AM Lambda_Aurigae: using a uint8_t...only decrement the variable in the interrupt..in the main loop do a check and compare and reset..if it is 255 then reset to 0.
10:01 AM Lambda_Aurigae: but, that compare isn't too large so I wouldn't worry about it how it is now.
10:02 AM Lambda_Aurigae: considering the interrupt entry is larger than what you are actually doing in the interrupt.
10:02 AM JanC_ is now known as JanC
10:03 AM Lambda_Aurigae: check out naked isr
10:03 AM Lambda_Aurigae: http://www.avrfreaks.net/forum/isr-naked-question
10:05 AM Lambda_Aurigae: remember that int data type is 16bits unless you use -mint8 in the compiler options.
10:05 AM Lambda_Aurigae: uint8_t gives you a nice unsigned 8 bit integer that you know will always be that.
10:06 AM mmfood: ok
10:07 AM mmfood: do you know why I would get type errors when using "uint8_t cycle_time;" in the header and cycle_time = 20*60; in the .c file?
10:07 AM polprog: mmfood: how much is 20*60
10:07 AM Lambda_Aurigae: also, where are you declaring current_time?
10:08 AM polprog: mmfood: and how much can an 8 bit value hold
10:08 AM Lambda_Aurigae: well, uint8_t is 0-255...20*60 is much larger than 255.
10:08 AM polprog: exactly
10:08 AM Lambda_Aurigae: for that you need full 16bit int
10:08 AM Lambda_Aurigae: polprog, sorry...I'm being too helpful today...I must have huffed solder fumes too much yesterday.
10:09 AM Lambda_Aurigae: I don't see current_time declared anywhere so that should throw errors too.
10:09 AM Lambda_Aurigae: anyhow..gotta go shopping wif da wifey
10:11 AM mmfood: Lambda_Aurigae: declaration is in a header file included at the top
10:12 AM mmfood: lol, of course...
10:17 AM mmfood: changing to uint16_t doesn't make the compiler shut up about missing storage class or type though
10:18 AM mmfood: unsigned doesn't work either but simple int does
10:27 AM * antto gives Lambda_Aurigae bonus points for writing "wif" >:)
10:50 AM polprog: lol
10:58 AM mmfood: doesn't every PCINTxx port on the atmega have an interrupt?
11:52 AM Cracki: rue_shop3, I'll keep that cat, tyvm
12:07 PM Cracki: iirc PCINTs are grouped into interrupts
12:07 PM Cracki: so you can get an interrupt on all pcint-capable pins, but you only get a few ISRs for them, and then you'd have to figure out which pin triggered it
12:08 PM Cracki: but don't take my word for it
12:08 PM mmfood: yup, managed to get it half working
12:09 PM polprog: huh, i have an ISR set on usart receive and all it does is sets the UDR back to what it was.. it sends the same bit but with the MSB set (so 0b01010101 sends back 0b11010101)
12:11 PM mmfood: https://paste.debian.net/986505/
12:12 PM mmfood: this is kind of working, I've been fiddeling with the inputs to make them pull-ups but that part isn't working yet.
12:13 PM mmfood: maybe some bitwise operation guru can see what I am doing wrong ")
12:14 PM polprog: your button/whatever is connected between gtound and the avr right?
12:14 PM polprog: ground*
12:14 PM mmfood: jupp
12:14 PM mmfood: with a resistor from the avr side to vcc
12:15 PM polprog: so you have the internal pullups and external pullups?
12:15 PM mmfood: apparently, lol
12:15 PM polprog: comment line 11
12:15 PM polprog: and give it a try
12:18 PM mmfood: it is not setting different values depending on PINB in the ISR it always enter the else block
12:19 PM polprog: what value is the pullup resistor
12:19 PM mmfood: 10k
12:19 PM polprog: that's good
12:19 PM polprog: hmm
12:20 PM polprog: try PCICR = 0xFF;
12:20 PM polprog: because your line 15 writes all 0's to PCICR
12:21 PM polprog: and it says "enable". im not sure if that means 0 or 1
12:23 PM mmfood: is that how it works? wouldn't (1 << 0) shift the one to the 0 position?
12:24 PM polprog: no, you'd have to OR it with the rest of 1's
12:24 PM polprog: basically...
12:24 PM polprog: if you make something like REG = (1<<2) then you zero all bits except 2
12:25 PM polprog: so you get 00000100
12:25 PM mmfood: ok
12:25 PM mmfood: so REG |= (1 << 2) would only change the 2nd bit?
12:25 PM polprog: exaclty
12:25 PM mmfood: right
12:26 PM polprog: leavign the rest of the bits unchanged
12:26 PM polprog: leaving*
12:26 PM mmfood: yep
12:27 PM mmfood: but so line 14 is, ok? it doesn't need the |= ?
12:28 PM polprog: that depends if you want to 0 the rest of bits
12:29 PM polprog: damnit, why the hell does my uart mess the MSB only!!!
12:35 PM mmfood: is it that PINB are all pullups so if PB0 is pressed ie LOW and I do PINB & (0 << 0) the pin B is still 00000110 and thus not 0
12:36 PM polprog: i send you mean portb?
12:36 PM polprog: brrr
12:36 PM polprog: nvm
12:37 PM polprog: i think the problem is that you are and'ing with all zeros, so that's the problem. anything AND 0x00 always gives 0
12:37 PM polprog: (i just noticed that 0<<0 in line 45
12:38 PM polprog: you need to check if the bit is zero.
12:39 PM Cracki: I'll make this simple
12:39 PM mmfood: I think I got it
12:39 PM Cracki: for setting bits, always write |= (1 << index)
12:39 PM Cracki: for clearing bits, always &= ~(1 << index)
12:40 PM polprog: so that's setting and clearing. but now we need checking :P
12:40 PM Cracki: reg & (1 << index)
12:40 PM Cracki: if you need it to be 0/1: (reg >> index) & 1
12:40 PM Cracki: those are the idioms
12:41 PM Cracki: anything else is just weird
12:42 PM polprog: so that will tell you if the bit is 1. if it's not, Cracki's (reg >> index) & 0x01 will return 0
12:42 PM Cracki: lines 10,11 are ok, but be aware that you set the whole register atonce
12:43 PM polprog: so your if would look like if ( !((reg >> idx) & 0x01) ) { ... };
12:43 PM Cracki: 14,15 are ok, but I advise to use controller-specific defines for the bit indices
12:43 PM Cracki: no semicolon there
12:44 PM Cracki: 45,47 are wrong. you could write (PINB & (1<<index) == 0) perhaps
12:45 PM Cracki: avr libs offer the _BV(index) macro, which is equal to (1 << (index)) more or less
12:45 PM mmfood: Cracki: 10,11: Ok, but I guess that is good, make sure the rest of the bits are cleared. 14,15: you mean PD0, PD1 etc...?
12:45 PM polprog: wow. so i need to add a crystal to my build becasue the internal OSC juust gives up at uarting at a speed higher than 4800
12:45 PM Cracki: not sure what the defines for 14 and 15 are named, but named constants are better than numbers :)
12:45 PM polprog: can eve do 9600. eww
12:45 PM Cracki: polprog, wat
12:46 PM Cracki: that's impossible
12:46 PM polprog: i have no bloody idea
12:46 PM Cracki: perhaps you compute the UBRR wrong
12:46 PM Cracki: deviations of a few percent are enough to get any uart in trouble
12:46 PM polprog: at 9600 it flips bits, the ISR is as simple as {char x = UDR; UDR = x;}
12:46 PM polprog: maybe
12:46 PM Cracki: wat
12:47 PM Cracki: DO NOT read and write from UDR like that
12:47 PM polprog: what
12:47 PM Cracki: oh nvm
12:47 PM Cracki: what is that supposed to accomplish? echo back? hm
12:47 PM polprog: it's a test
12:47 PM polprog: uart test
12:47 PM Cracki: ok, how do you see it's flipping bits? what's it attached to?
12:47 PM Cracki: is the wiring sketchy?
12:47 PM polprog: an usb-uart converter and a scope
12:48 PM Cracki: what does the scope say?
12:48 PM polprog: the wiring might be a problem, it's all airwires
12:48 PM Cracki: does the output look good and valid on the scope?
12:48 PM polprog: the scope clearly shows that the returned bits are flipped, theres terrible crosstalk at RXD and TXD lines though
12:49 PM Cracki: ok what is going on
12:49 PM polprog: i can show you the printscreen
12:49 PM Cracki: bad power supply?
12:49 PM Cracki: plz do show
12:49 PM Cracki: sounds like elctrical problems.
12:49 PM polprog: the psu is good, it's a linear lab one
12:49 PM polprog: one moment
12:51 PM polprog: Cracki: https://puu.sh/xC1sW/a66e052a3a.png
12:51 PM mmfood: _BV stands for bit value?
12:51 PM Cracki: oh lol
12:52 PM Cracki: looks like something is loading these lines
12:52 PM Cracki: what is blue?
12:52 PM Cracki: what is magenta?
12:52 PM polprog: yellow is TX (from avr), blue is RX (from terminal)
12:53 PM polprog: magenta is a test pin wiggle that was used to check if the ISR is firing
12:53 PM Cracki: k
12:53 PM Cracki: check if the rx/tx pins are configured properly
12:53 PM polprog: meaning DDRs and PORTs?
12:53 PM Cracki: yes
12:53 PM Cracki: and whatevers attached...
12:53 PM polprog: neve thought about that
12:53 PM polprog: ill try
12:55 PM Cracki: hm I don't configure rx/tx ddr/port either, so that is probably not it...
12:55 PM Cracki: I'd say it's something attached to the pins...
12:56 PM polprog: they go straight to the header
12:57 PM Cracki: does the blue still show the depression if you attach the yellow ONLY to the scope?
12:57 PM Cracki: i.e. not to the hostside uart
12:57 PM Cracki: perhaps the hostside uart is faulty
12:57 PM polprog: no, crosstalk disappeared
12:57 PM polprog: but the data's still garbled
12:58 PM Cracki: hm
12:58 PM Cracki: crosstalk gone is good
12:58 PM Cracki: garbled how? I'd measure the bit times on the scope
12:58 PM Cracki: send an 0x55 or AA or something
12:59 PM polprog: they are a little bit different, AVR sends bits about 10 us
12:59 PM Cracki: 0x55 is U
12:59 PM polprog: shorter
12:59 PM Cracki: exact times
12:59 PM polprog: just a moment
12:59 PM Cracki: 10 us is 100kbaud
12:59 PM Cracki: on that screenshot, 500us/div and I'd say I see a ~250 us bit, so that makes ~4 kbaud
12:59 PM polprog: ah great i had the scope still set to 4800...
01:00 PM Cracki: perhaps less
01:00 PM polprog: ok, everything set properly to 9600
01:00 PM Cracki: the bit times on that screenshot do look close to 4800, but how many percent of deviation remains to be measured using cursors
01:00 PM Cracki: or a measurement function of the scope
01:01 PM polprog: okay, so AVR sends a 1 with a width of 96 us
01:01 PM Cracki: that's odd
01:01 PM Cracki: what's your ubrr
01:02 PM Cracki: 96us is 10.4kbaud
01:02 PM Cracki: chip freq and ubrr plz
01:02 PM polprog: chip freq is 1M (default) and Ubrr is calculated
01:02 PM Cracki: is it rounded right?
01:02 PM polprog: UBRRL = ((((F_CPU >> 4)/baudrate) - 1) & 0xFF); UBRRH = ((((F_CPU >> 4)/baudrate) - 1) >> 8 & 0xFF);
01:02 PM polprog: not sure
01:02 PM Cracki: or calced by the avr lib?
01:02 PM Cracki: hm good enough
01:02 PM polprog: ill try the lib's calculator
01:03 PM Cracki: check the data sheet
01:03 PM Cracki: at 1 mhz, you have enormous errors already at 9600 baud
01:03 PM polprog: yes, i remember...
01:03 PM Cracki: there are tables for 1 mhz and other fcpu
01:03 PM Cracki: as for this calculation, I'd recommend -0.5
01:03 PM Cracki: that and integer rounding gets you closer
01:04 PM Cracki: nvm it's all integers, won't do a thing
01:04 PM Cracki: perhaps use floats there just for the constant
01:04 PM polprog: ok, ill try to set U2X since at 1MHZ, U2X = 1, error is 0.2% with UBRR = 12 at 9600 baud
01:04 PM Cracki: or make baudrate a preprocessor define, and let the preprocessor handle it
01:04 PM Cracki: yeah try that, should be a lot closer
01:05 PM Cracki: 9615 baud
01:05 PM Cracki: 1e6 / 8 / (12+1)
01:05 PM Cracki: u2x=0 and you have ubrr = 5 or 6, which is 8928 or 10416 baud
01:05 PM Cracki: way off
01:06 PM Cracki: 7 and 8 percent
01:06 PM Cracki: if you don't have to, I'd recommend clearing the ckdiv8 fuse. 8 mhz is a lot better in general :P
01:07 PM polprog: well this thing will have to run at 1M or even slower... it's about energy saving
01:07 PM Cracki: atmegas can enter power saving modes
01:07 PM polprog: im trying the u2x trick
01:07 PM Cracki: and the uart can run independently
01:07 PM polprog: Cracki: i know :P
01:07 PM Cracki: "race to sleep" :D
01:07 PM polprog: it's not my first program :PP
01:08 PM Cracki: :P
01:08 PM Cracki: dat crosstalk tho
01:08 PM polprog: crappy converter
01:08 PM polprog: damn, it W O R K S
01:08 PM polprog: thanks very much
01:09 PM Cracki: *bows*
01:09 PM Cracki: I love scopes :D
01:09 PM polprog: me too
01:10 PM Cracki: someone in sigrok recently needed a shitty scope. told him to run his atmega ADC at full speed and pipe the bytes out through uart
01:10 PM polprog: i love sigrok
01:10 PM Cracki: that could have gotten him 86.8 khz sampling
01:10 PM polprog: that's twice as fast than a sound card scope
01:10 PM Cracki: then I looked around for arm based fuckery. stm32 can do almost 1 Mhz sampling
01:11 PM Cracki: sound cards might do 96 khz
01:11 PM Cracki: maybe
01:11 PM polprog: if you have a good one
01:11 PM Cracki: oh heh sound card scope, gotta try that with my laptop...
01:11 PM polprog: there's a ton of software for that
01:11 PM polprog: for electronic amateurs
01:11 PM polprog: i'd suggest a ton of clamping, protection and stuff
01:12 PM polprog: you dont wanna blow you card :P
01:12 PM Cracki: I've got stm32 "arduino-style" boards flying around. getting them to be 1 MHz cheapass scopes would be nice sometimes.
01:12 PM Cracki: yeah clamping, don't wanna kill my good electronics
01:12 PM polprog: you do AVRs and electronics for a long time?
01:12 PM Cracki: a few years
01:13 PM Cracki: been meaning to "graduate" to cortex m for a while. cheaper and allaround faster than avrs.
01:13 PM Cracki: but the tooling...
01:13 PM Cracki: however cortex m are awesome because with the right dongles, you can trace execution
01:14 PM Cracki: call instrumentation for low effort, instruction level tracing with good equipment
01:14 PM polprog: wow
01:14 PM Cracki: especially if you deal with control applications, you can't just break and singlestep
01:14 PM Cracki: what the ARM does is it pipes out that data as uart
01:14 PM Cracki: 8 mhz for the simple stuff
01:15 PM Cracki: the ones with a floating point unit or even DSP blocks are nice too...
01:16 PM Cracki: for a stepper motor control application, I had to implement something using square root tables (there's an app... note for that)
01:16 PM Cracki: works, but omg not straightforward
01:18 PM polprog: damnit
01:18 PM Cracki: I wish i'd find the time to get into stm32... it's said they have one of the best software ecosystem (hal/libs)
01:19 PM polprog: im thinking about stm32
01:22 PM rue_bed: I been playing with stm32
01:22 PM rue_bed: did a number of things with the systems
01:22 PM rue_bed: didn't go near the HAL stuff, I think hardware abstraction is stupid
01:23 PM rue_bed: its a single purpose system..
01:24 PM Cracki: aye
01:25 PM rue_bed: the stm32 has a dma,so, with the right adc, you could go over 1Mhz if you want
01:27 PM rue_bed: they say it had like 7dma, but its not like that, each channel is tied to one of a few systms
01:27 PM rue_bed: so, timer1 can only use dma x
01:27 PM Cracki: the builtin adc at least...
01:28 PM rue_bed: timer 2 can only use dma y
01:28 PM rue_bed: do you have an stm32?
01:30 PM Cracki: I have some stm32f1 flying around on maple mini boards
01:31 PM Cracki: (china clones)
01:31 PM rue_bed: the hardest part is setting up the makefile and environment
01:31 PM Cracki: i have a discoboard
01:31 PM rue_bed: http://ruemohr.org/%7Eircjunk/software/stm32.tgz
01:31 PM Cracki: hah true
01:31 PM rue_bed: there are my system exxamples
01:31 PM rue_bed: all set up and everything
01:31 PM rue_bed: adc, timers, serial...
01:31 PM rue_bed: simple examples of everyone
01:31 PM rue_bed: with a makefile that took me 3 days
01:31 PM rue_bed: or so
01:32 PM rue_bed: make; make install
01:32 PM rue_bed: it was a lot of work, it could save you a lot of work, check it out
01:32 PM Cracki: I'll squirrel it away in my downloads dir
01:33 PM Cracki: ah opencm3
01:33 PM Cracki: people seem to recommend it more and more
01:34 PM Cracki: I'm glad ARM decided to be officially behind the arm gcc project
01:34 PM Cracki: they've pulled the stuff from launchpad and made their own subdomain at arm
01:34 PM Cracki: so at least the compiler stuff has official support
01:35 PM Cracki: people say "use openocd" but perhaps I should look into that keil IDE... maybe it supports the jlink clone I got from aliexpress
01:37 PM polprog: damnit im tired
01:37 PM polprog: and sick
01:37 PM polprog: and at work...
01:38 PM polprog: i spent 30 mins checking why my cross-file variable (a flag) is not working... it was not set a volatile.
01:38 PM polprog: finally.
01:38 PM polprog: DONE
01:38 PM rue_shop3: yea
01:39 PM rue_shop3: unsigned static volatile?
01:39 PM rue_shop3: :)
01:39 PM polprog: volatile extern uint8_t process_cmd_flag
01:44 PM Cracki: btw avr-readelf -a foo.elf | awk "{ if ($7 == 1 || $7 == 3) print }" | cut -c 17-
01:44 PM polprog: what does that do?
01:44 PM Cracki: if you ever needed to know what variables waste your sram
01:44 PM polprog: hmm
01:44 PM Cracki: __file__.1234 means string constant, most likely from an assertion
01:44 PM Cracki: *__func__
01:45 PM Cracki: 1 and 3 were the section numbers for .bss and .data
01:45 PM Cracki: my readelf doesn't filter those on its own
01:46 PM Cracki: other methods of inspecting the elf either didn't report the size of something, or just gave me whole sections
01:47 PM polprog: og man
01:48 PM polprog: it went so quiet, after i shut down the scope and the PSU...
01:48 PM polprog: finally done for today
01:49 PM Lambda_Aurigae: just prepped dindin.
01:49 PM Lambda_Aurigae: stuffed bell peppers.
01:50 PM Lambda_Aurigae: all in the pan and ready to bake.
01:50 PM polprog: mmm
01:51 PM Cracki: food
01:51 PM Cracki: good idea
01:51 PM Lambda_Aurigae: maybe a channel called #openarm ?
01:51 PM Lambda_Aurigae: because the #arm people just don't seem to like anything open source.
01:52 PM Cracki: try ##stm32, based ppl
01:52 PM Lambda_Aurigae: that's the one I meant
01:52 PM Lambda_Aurigae: the stm32 channel.
01:52 PM Cracki: #arm looks ded, not a dozen ppl in there
01:52 PM Lambda_Aurigae: yeah...it has some occasional chat.
01:53 PM Lambda_Aurigae: not much..usually very esoteric stuff.
01:53 PM Lambda_Aurigae: would love to get it going properly.
01:53 PM Cracki: stm32 is good, they're properly incorrect
01:53 PM Cracki: there's libopencm3
01:53 PM Lambda_Aurigae: stm32 people go zonkers when you start talking about open source software.
01:53 PM Cracki: eh, they're just trolling
01:54 PM Cracki: it's their way of keeping fundamentalists at bay
01:54 PM Cracki: if there's shop talk, they don't interfere
01:58 PM Lambda_Aurigae: they did when I was there.
05:10 PM enh: hi
05:11 PM Tom_itx: lo
05:13 PM enh: the laser i bought for the cnc passed by customs without taxes. :)
05:13 PM enh: 15W 450nm.
05:15 PM enh: Is it possible to cut through the PCB copper layer with this power?
05:24 PM Cracki: do you want copper flying around?
05:25 PM Cracki: you can expose some UV resist on PCBs
05:25 PM Cracki: but burning the copper away, maybe not
05:25 PM Cracki: you'd need high intensity for a short time
05:25 PM enh: copper needs a lot of power to evaporate
05:25 PM Cracki: i.e. pulsed laser
05:25 PM enh: probbaly that is not enough
05:25 PM enh: short pulses
05:26 PM Cracki: you don't want continuous energy application
05:26 PM Cracki: that'd just dissipate everywhere
05:26 PM enh: nope.
05:26 PM enh: yep
05:26 PM Cracki: ablation is the keyword
05:26 PM enh: yep
05:26 PM enh: physicist?
05:26 PM Cracki: no, googled it before :P
05:26 PM Cracki: dissected a laser printer for its rotating prism
05:27 PM Cracki: considered making a laser exposer that scans the raster graphics on the resist
05:27 PM Cracki: some people use their cnc + laser as plotters on the resist
05:27 PM enh: I used black ink
05:27 PM enh: http://gabuleu.blogspot.com.br
05:27 PM Cracki: uh, ink?
05:27 PM enh: and a very cheap 808nm laser
05:28 PM enh: 0.5W
05:28 PM Cracki: like laser toner? or actual ink
05:28 PM enh: black spray
05:28 PM Cracki: ic
05:28 PM Cracki: and IR to harden?
05:28 PM Cracki: or to absorb?
05:28 PM enh: ir to evaoprate
05:28 PM Cracki: hm
05:29 PM enh: works, but only for two layer pcbs
05:29 PM Cracki: fascinating
05:29 PM enh: then I tried laser cutting some materials, thin ones, and discovered my options were very few
05:30 PM enh: After that I found on ebay a 15W laser module for like $180
05:30 PM enh: which should arrive soon.
05:31 PM enh: But it will not be a toy laser any more. 15W is pretty dangerous.
05:31 PM cehteh: already applied for a guide dog? :)
05:31 PM enh: nope.
05:31 PM enh: I have some laser experience.
05:32 PM enh: expect not to need a dog
05:33 PM Cracki: ya don't need eyes to know where the beam is. just feel it :P
05:33 PM enh: I 'll probably need to build a box around the cnc with an interlock to the laser power supply
05:33 PM Cracki: anything comes back crispy the dog can have it
05:33 PM enh: problem is that you feel it only once in each place
05:36 PM enh: You guys who know everything... Is there any magic to do bitwise operations on int32_t?
05:37 PM enh: This code https://pastebin.com/ASYTy77g is reporting bit 17 as bit 15
05:37 PM thardin: they don't work like any other int?
05:37 PM enh: apparently not
05:38 PM thardin: does the compiler complain?
05:39 PM enh: no complaints
05:41 PM enh: This code runs before that one: https://pastebin.com/GTvu3hMT
05:41 PM thardin: check the generated asm
05:41 PM enh: ok
05:42 PM thardin: wouldn't uint32_t need 1ULL ?
05:43 PM enh: I believe 1ULL is for unsigned long long, 64bit
05:43 PM enh: long in avr is int32_t, if not too wrong
05:45 PM enh: Fixed it.
05:46 PM enh: https://pastebin.com/mCAmZ3PS
05:46 PM enh: every ter of the shift oeration must be of the same type
05:47 PM enh: term
05:48 PM cehteh: for what is the volatile there?
05:49 PM thardin: weird, does using uint8_t downgrade the shift to 8-bit then?
05:49 PM thardin: that almost sounds like a compiler bug
05:49 PM cehteh: actually ... answer: remove that volatile its useles only makes the code slower
05:50 PM enh: you are right. removed
05:51 PM cehteh: what is NUM_SLOTS as max?
05:51 PM enh: because I have only NUM_SLOTS in the backplane
05:52 PM cehteh: well its not 4Billion something
05:52 PM cehteh: so no int32 required
05:52 PM enh: the possible capacities are 32
05:53 PM cehteh: uint8 would suffice
05:53 PM enh: As I code them as bits in a long
05:53 PM cehteh: but you may cast it at some math operations
05:53 PM enh: COM module calls slots and asks for a capacity code. a long comes.
05:54 PM cehteh: is that ReadLongViaSPI buffered?
05:54 PM enh: i do not know if i understand the word buffered well nenough to answer
05:55 PM cehteh: well nevermind doesnt matter (prolly not just looks odd)
05:56 PM cehteh: still looks a bit odd lots of nested fors to set some bits on a bitfield
05:56 PM enh: https://bitbucket.org/enhering/yauvc/src/f06a727ce023bbe953bc0d36451f4008e4192232/firmware/src/classes/protocols/?at=default
05:57 PM enh: I have 32 possible capacities installed in 6 possible slots
05:57 PM enh: I need two fors to iterate through these
05:57 PM cehteh: thats at least one too much :D
05:58 PM enh: can you do it with one for only? You can with 6 ifs
05:59 PM cehteh: i'd start with some code abstracting the bitfield (actually C++ std::vector is defined for bitfields, but i dont use C++)
06:00 PM enh: can be done, but isn't it too much?
06:00 PM cehteh: anyway something to define a bitfield of n (at least, rounded up by 8) bits
06:01 PM enh: I mean, I only want to know which capacities are in which slots
06:01 PM enh: like which slots have accelerometers
06:01 PM cehteh: and then get_bit(bitfield,bitn) setbit(bitfield,bitn) clearbit(...) functions or something like that
06:01 PM enh: like the ones for the registers
06:01 PM cehteh: with capacities you actually mean capabilities? :)
06:02 PM enh: I asked that question some time ago
06:02 PM enh: found this answer: https://www.quora.com/What-is-the-difference-between-capacity-and-capability
06:02 PM enh: I believe capacity is a better word
06:03 PM enh: based on the answer
06:03 PM cehteh: capacity is rather 'volume' or 'amount of' not just 'existence'
06:04 PM enh: "Capacity is the ability that exists at present and capability refers to the higher level of ability that an individual can achieve or improve to"
06:04 PM enh: From the link
06:04 PM cehteh: a bucket has a capacity of holding 10 liters of water, but all buckets have the capability to hold some water
06:04 PM enh: i thought that way too, until i read the definition
06:05 PM cehteh: i havent read it but i believe its wrong that way, while i am not native english speaker it still disturbs me
06:05 PM enh: I quted it above
06:05 PM enh: disturbs me a little too
06:06 PM cehteh: just forget that explanation :D
06:06 PM enh: I would glad tchange the vairble name to a better word
06:06 PM enh: I should glue the keys of my keyboard. They keep changing places
06:06 PM cehteh: anyway how many different capabilities do you have, are these dynamic or static? free form (as in loadable modules wich add more) or predefined?
06:08 PM cehteh: like when you plug a humidty sensor in, should your software recognize that even if it was agnostic what humidty is before?
06:09 PM enh: Should recognize. The list is here: https://pastebin.com/FLZgdSQD
06:10 PM cehteh: either way, you can (and prolly should) use different datastructures here, one to index slots only by some capability (accel is on 1, 6 and 7, ... )
06:10 PM enh: The list is set for a vehicle controller, and is still very basic. Plenty of place to improve
06:10 PM cehteh: that allows fast access to the capabilities
06:10 PM enh: That is what that code does
06:10 PM cehteh: nah *fast*
06:11 PM enh: it transposes the matrix
06:11 PM cehteh: as in having a liist/array wich only hold uint8_t {1,6,7}
06:11 PM enh: this takes memory. I coded it in bits of the value
06:11 PM cehteh: the other maybe you want a matrix yes, but such a matrix is not fast to iterate and its not simple to add things on the fly
06:12 PM enh: the first for queries the slots to get the capability codes. One code for each slot. Each code has 32 bits settable. Each bit represents a capability
06:12 PM enh: The nested fors transpose the matrix, setting the slots for each capabilty as bits of the value
06:12 PM cehteh: yes it may take memory, but when access becomes constant instead iterating and filtering a matrix it may (or may not, depends where you need it) give big performance improvements
06:13 PM cehteh: but reading those bits will need another loop
06:13 PM enh: yep
06:13 PM cehteh: dunno if its important to access this things fast, but i bet it is
06:13 PM enh: if you have two accelerometers in the system, one in each slot
06:14 PM cehteh: in programming you often trade memory for speed
06:14 PM enh: you have to read one, than the other, fusing the values
06:14 PM cehteh: or vice versa, depends on what you need
06:15 PM cehteh: so you want to do something like for a in all_accelerormeters() do fuse_to_result(a) end
06:15 PM enh: yep
06:16 PM enh: more like https://pastebin.com/6rakLqch
06:16 PM cehteh: where access to 'all_accelerometers' should be as fast as possible, not doing nested for loops which filter out 3 results from 32 or more potentional places
06:16 PM cehteh: i am only speaking generally, not in C
06:17 PM enh: 6 potential places.
06:17 PM enh: The slots
06:17 PM cehteh: still lots of bit operations and tests
06:17 PM enh: The transposed matrix is indexed by capacity
06:18 PM enh: I can reduce the number of iterations if I keep in memory the slot list per capacity and the size of the list
06:18 PM enh: but that adds complexity
06:18 PM cehteh: i'd just create an index for each kind of sensor
06:19 PM enh: this is what the code does
06:19 PM enh: but instead of a list of slots it holds a bit per slot
06:19 PM cehteh: that certainly needs more memory but is magnitudes faster (as in 'instant' .. constant access) no loops
06:19 PM enh: you still need a loop to iterate thorugh your list, don't you?
06:20 PM cehteh: you need one lof for the 'for all accelerometers' thing yes, thats what you need to do anyway, but with 3 accels thats 3 constant accesses
06:22 PM enh: but how do I know what will be plugged in which slot? it should be plug and pray
06:22 PM cehteh: when you want to do some bit-fiddleing you can squeeze such indices into the least bits possible, or nibbles, 4 bits .. that has some overhead but at least not the loops
06:23 PM cehteh: at startup you do some initialization building these indices
06:23 PM cehteh: (or do you want hotplugging? even then this should be posible, but much more complicated)
06:23 PM enh: that is what is done
06:24 PM enh: i do it for hot plugging
06:24 PM cehteh: for initialization it is ok to query stuff in the slow way, iterate an filter etc
06:24 PM enh: https://pastebin.com/TAdA5hMg
06:24 PM cehteh: *but* you need to keep an eye in how you want to handle the data later, then searching values in a bit matrix will be expensive
06:25 PM enh: look at the CustomLoop fmethod
06:26 PM cehteh: yes instead if a matrix i'd choose indices .. or maybe create that matrix initially, and later build indices from that (well for what do you need the matrix? :))
06:27 PM cehteh: its just there for no purpose only to make querying later more slow
06:28 PM enh: i do not see how i would deal with an arbitrary module set without a matirx. I tried other solutions but they required a lot of complexity
06:28 PM cehteh: momet i type/pastebin what i mean
06:28 PM enh: ok
06:37 PM cehteh: https://pastebin.com/nyiKFxwz
06:37 PM cehteh: just example
06:37 PM cehteh: non working, non optimized
06:40 PM enh: this is almost the same as what i have, cehteh
06:40 PM enh: look:
06:43 PM enh: if (m_anSlotListPerCapacity[nCapacityBit] & (1UL << nSlot)) {
06:43 PM enh: BIT09_ACCELEROMETER 9 is a capacity bit
06:43 PM enh: so
06:43 PM cehteh: cimpile yours and compile mine, look at the generated asm
06:44 PM enh: if (m_anSlotListPerCapacity[BIT09_ACCELEROMETER] & (1UL << nSlot)) {
06:44 PM cehteh: and profile it, yours has nested loops, mine doesnt
06:44 PM enh: I only loop it through the slots
06:44 PM enh: the nested are only for generating the capacity matrix
06:44 PM cehteh: 1UL << nSlot is some hidden loop already
06:45 PM enh: ah
06:45 PM enh: ok
06:45 PM cehteh: avr can only shift one position
06:45 PM enh: hum
06:45 PM cehteh: to shift a dynamic number of positions it has to call the shift instruction multiple times
06:45 PM cehteh: and the worse you use uint32 while AVR's only handle 8 bit
06:45 PM enh: understood
06:46 PM LeoNerd: Or even, to shift a static constant number of positions, it still has to invoke it lots of times
06:46 PM cehteh: for static it can do some optimizations
06:46 PM cehteh: but for dynamic optimizations are hard
06:47 PM LeoNerd: Hrmmreally? What optimisations?
06:47 PM LeoNerd: E.g. to shift up 4 places.. I don't know of a better way
06:47 PM cehteh: any shift by 8 on a 32bit value can be a move
06:47 PM LeoNerd: Sure
06:48 PM cehteh: then only shift the difference to sans 8
06:48 PM enh: understood, but optimizing this code cannot be done now. I have to fly this thing before starting another round of coding
06:48 PM LeoNerd: And e.g. up by 7 is up 8, then down 1; so move then down 1
06:48 PM LeoNerd: But something like 4. I don't know a nicer way
06:48 PM cehteh: some AVR's have hardware multiply or?
06:48 PM cehteh: again few shifts can be optimized to hardware mult
06:48 PM LeoNerd: Oh huh.. I suppose those do
06:48 PM cehteh: many dont
06:49 PM LeoNerd: I believe generally megas have MUL, tinies do not
06:49 PM cehteh: maybe, forgotten the details
06:49 PM cehteh: anyway shifting by a variable should be avoided
06:50 PM cehteh: and shifting things bigger than 8 bits too
06:50 PM enh: 32 capacities * 6 slots = 192 bytes
06:50 PM cehteh: enh: yes the memory can be optimized
06:50 PM cehteh: like you have one maste controller, which has no sensors
06:50 PM enh: plus list size per capacity
06:50 PM Cracki: hm, good point, mul is single-cycle, but shifts larger than 1 are multiple instructions or multiple cycles
06:50 PM cehteh: so 5 slots only per capability
06:51 PM cehteh: anyway i tihnk in your case it is ok to use 200valuable bytes just to make sensor access *much* faster
06:51 PM enh: i have 6 working slots now. Maximum system config needs 8.
06:51 PM cehteh: one could optimize the code in many ways
06:52 PM enh: I 'll think about that
06:52 PM cehteh: like put everything in one array then you only allow a max number of sensors
06:52 PM cehteh: just makes initialization more complicated, which shouldnt be a problem sans bugs
06:52 PM enh: anything less than max requires a list size
06:53 PM cehteh: while maintaining constant access to the indexed sensors
06:53 PM cehteh: implement spans on that master array
06:54 PM cehteh: uint8_t sensors[64]; // 64 sensors of any kind supported
06:54 PM cehteh: uint8_t accl_start,accl_end;
06:54 PM enh: understood
06:54 PM cehteh: uint8_t gyro_start,gyro_end;
06:54 PM cehteh: etc
06:55 PM enh: just to elucidate, capacities are not only sensors
06:55 PM cehteh: doesnt matter
06:55 PM cehteh: and these are capabilities .. or?
06:55 PM cehteh: LeoNerd: you are native english speaker right? :)
06:55 PM enh: they include navigation, control, possibly kalman, etc
06:56 PM cehteh: the more you manage there the more efficient do you want the access to it
06:56 PM enh: anything that a module can do/have to work for the system
06:56 PM enh: https://pastebin.com/FLZgdSQD
06:57 PM cehteh: you can do that completely dynamic, thats no problem, the key concept i wanted to show you is that you have an index which exactly points to the things
06:57 PM enh: understood
06:57 PM cehteh: no operations to filter out
06:57 PM enh: i thought bitwise operations were the fastest possible way
06:57 PM enh: my bad
06:58 PM cehteh: later you can bound these capabilities to C++ classes directly which implement common or extended interfaces .. if you really want the C++ bloat :D
06:58 PM enh: i do
06:58 PM cehteh: single bitwise operations are fast (1 cycle)
06:58 PM enh: even though, bitwise or not, i'm getting a ghost module in the matrix
06:59 PM cehteh: but when you do many of them AND wrap them in nested for loops AND do them on 32bit values then its magnitudes slower than what i've shown
06:59 PM enh: ok
06:59 PM enh: I'll think about changing it soon, then
06:59 PM enh: question: would an array of structs work well in the avr?
07:00 PM cehteh: i bet you *must* do so, performance of your stuff will be pretty poor is what my gut feeling says
07:00 PM enh: structs like the one you pastebinned?
07:00 PM cehteh: doesnt matter, for the compiler its just pointers and distances
07:01 PM cehteh: if these become to big it may needs slightly more expensive asm instructions
07:01 PM enh: That would be easier to deal with for me
07:01 PM cehteh: but thats still linear/constant and much better than your code :D
07:04 PM enh: Ok.
07:04 PM enh: I'll do it
07:04 PM enh: Thanks
07:04 PM enh: You do help a lot
07:05 PM cehteh: np
07:06 PM enh: I want to design a STM32 module for the system. But just thinking about all the learning of a new IC and implementing the basic macros makes me tremble
07:23 PM enh: cehteh: Better word for capacities? Competences?
07:23 PM cehteh: capabilities
07:23 PM cehteh: ask some native english speaker here
07:23 PM enh: from the definition it should not be the right word
07:23 PM enh: Tom_itx: ?
07:24 PM enh: rue_bed: ?
07:24 PM enh: Lambda_Aurigae: ?
07:24 PM cehteh: https://en.wikipedia.org/wiki/Capability
07:24 PM Lambda_Aurigae: huh?
07:24 PM Lambda_Aurigae: wha?
07:24 PM cehteh: https://en.wikipedia.org/wiki/Capability_(systems_engineering)
07:24 PM Lambda_Aurigae: capability or capabilities(plural)
07:25 PM cehteh: A Capability, in the systems engineering sense, is defined as the ability to execute a specified course of action.
07:25 PM cehteh: is exactly what you want right?
07:25 PM enh: right, but what about that definition above from quora?
07:25 PM enh: that capabilities can be improved
07:26 PM cehteh: i shim quora :D
07:26 PM cehteh: better q: whats the difference between capability and ability?
07:26 PM enh: qoogling
07:26 PM Lambda_Aurigae: not much.
07:27 PM cehteh: either way, you either use some common word which is used for the thing you do
07:27 PM enh: ability to sense acceleration?
07:27 PM Lambda_Aurigae: By definition, capability is usually defined as the feature of being capable of something. In short, it is practical ability. This is probably where the confusion sets in because the definition of the word capability makes use of the word ability. Conversely, ability is a word that pertains to being able.
07:27 PM cehteh: or you invent something on your own, call the modules capatain, navigator, helmsman, machinist
07:28 PM enh: capability then
07:28 PM cehteh: but using something confusing just because its unique would be bad
07:28 PM Lambda_Aurigae: In common practice, ability is much nearer to describe talents of people whereas capability is more applicable in reflecting the worth of being capable of an organization, group or company, and not humans.
07:28 PM Lambda_Aurigae: Read more: Difference Between Ability and Capability | Difference Between http://www.differencebetween.net/language/difference-between-ability-and-capability/#ixzz4sz3FnAQD
07:29 PM cehteh: well the initial question was more about the differrence between capacity and capability
07:29 PM enh: It was more between https://www.quora.com/What-is-the-difference-between-capacity-and-capability
07:29 PM cehteh: in sense of 'services a module provides'
07:29 PM cehteh: and capacity is outright wrong there
07:29 PM cehteh: imo
07:29 PM Lambda_Aurigae: capacity is a quantity measurement of capability or ability,,,kindasorta.
07:29 PM cehteh: thats what i saied
07:30 PM Lambda_Aurigae: the jar is capable of holding water...the quantity of water the jar can hold is 1 liter.
07:30 PM Lambda_Aurigae: english is rather confusing.
07:30 PM Lambda_Aurigae: my grandmother was a high school english teacher.
07:30 PM Lambda_Aurigae: I HAD to learn it.
07:30 PM enh: try portuguese...
07:30 PM cehteh: you can say the module has the capability 'accelerometer' .. and then the accelerometer has the capacity of 3 axis (but because the axis there are not the same thats already wrong)
07:31 PM cehteh: a battery has some capacity in how much charge it holds
07:31 PM Lambda_Aurigae: portugese is like stoned spanish isn't it?
07:31 PM cehteh: mAh or so
07:31 PM Lambda_Aurigae: [:
07:31 PM cehteh: capacitors have capacity because they are capacitors :)
07:31 PM enh: portuguese is hell. Lots of exceptions. Like french.
07:32 PM cehteh: makes sense? :)
07:32 PM enh: Changed all to capability(ies)
07:34 PM enh: Somebody whould question that quora definition
07:34 PM enh: should
07:55 PM enh: cehteh: https://pastebin.com/CNttQuWw
08:01 PM enh: https://pastebin.com/LL75HDRZ
08:05 PM cehteh: things take shape
08:06 PM cehteh: use uint8_t for the counter too, and old optimization trick is to count down to 0 instead up, dunno if its true for AVR but many CPU's can execute such loops more efficiently
08:07 PM enh: really?
08:07 PM cehteh: (while you do so much other stuff in that loop that the execution time of the loop commands itself would hardly matter)
08:07 PM thardin: enh: yes, decreasing the index to zero or negative sets the appropriate flag in many cases
08:08 PM thardin: so you don't need a comparison
08:08 PM thardin: like a DEX/BPL loop on 6502
08:08 PM cehteh: where comparsion is usually substraction which just drops the result
08:09 PM cehteh: anyway would be unmasureable because that save only few cycles
08:09 PM cehteh: while your fuse function calls each prolly need hundreds of cycles
08:09 PM enh: could be a do..while loop instead of a for
08:10 PM thardin: only optimize where your profiler tells you there's a bottleneck
08:10 PM cehteh: that shouldnt matter
08:10 PM thardin: avr-gcc is pretty awful I must say. typically inner loops require hand written assembly
08:10 PM cehteh: depends
08:11 PM thardin: of course
08:11 PM cehteh: calling a heavy lifting functiuon three times there will outweight anything
08:11 PM cehteh: and lesson one is not to have inner loops :D
08:11 PM enh: https://pastebin.com/5KQmfj5Y
08:12 PM thardin: that depends on what you do. I poked around with IQ demodulation of 24-bit sample data
08:12 PM thardin: that took a pretty heft chuck of the available CPU time
08:16 PM thardin: luckily I don't have to do that any more. just poop adc data over usart instead, to be handled elsewhere
08:17 PM cehteh: you could make this fuse loop a function, would be slightly slower but save program space
08:20 PM cehteh: seeing almost identical code lines repeating is often (but not always) a red light
08:23 PM enh: yep. A function fits there
08:24 PM enh: maybe
08:25 PM enh: The data selectors would have to refer to 3d values. But not all values are 3d, so I would have to have two classes of selectors: vectors and scalars.
08:25 PM enh: I'll save it for later
08:26 PM cehteh: eh barometer has no 3 axis :)
08:27 PM enh: altitude, temperature and pressure
08:27 PM enh: the sensor gives all three
08:27 PM cehteh: well ok thats 3 sensors i say
08:27 PM cehteh: https://pastebin.com/APRqcQ3k
08:27 PM enh: 3 scalars
08:27 PM cehteh: along such, again non working only showing the concept
08:28 PM enh: gut
08:28 PM cehteh: would rely on inlining or macros
08:29 PM enh: The main change is the select list, which is the same in all modules: https://pastebin.com/JYUchBT9
08:29 PM cehteh: one rule is that i try to minimize the code i write (not as in trying to write as smart/unreadable/compact code as possible)
08:30 PM cehteh: but all code you write may have some bugs, the more you repeat similar things the more you have to fix eventually
08:30 PM enh: This is where is hits the SPI protocol. Each module has two structures like these: https://pastebin.com/dHZhyQw5
08:31 PM cehteh: this may expand into lots more code by macros or inlined functions, but keep the places of maintenace small
08:31 PM cehteh: when there is a bug, fix that one place, then everything (similar now generalised to one thing) works
08:32 PM cehteh: use enums for that
08:33 PM enh: the modules answer SPI by interrupt. The interrupt calls a SPI manager, which does the signaling and the data transfer. During these calls to SPI, it reaches a moment in which the Output selector is called to see how the module will respond to the call, and with which size.
08:33 PM enh: only one value is passed, whatever its size, per protocol call.
08:34 PM enh: so the module selects have to be indexed by value
08:34 PM enh: i.e., accelx is a call, accel.y is another etc
08:34 PM cehteh: but nothing ansync yet, i see problems .. but that on another day :D
08:35 PM enh: the select indexes cannot refer to a 3d value using this model
08:35 PM enh: ok
09:28 PM enh: flashing...
09:32 PM enh: performance increased a lot.
10:04 PM enh: cehteh: I cannot see the telemetry led flashing any more. It seems to be on continuously.
10:06 PM cehteh: hah
10:06 PM cehteh: flashes too fast for you :D
10:06 PM cehteh: you have it free spinning? not some constant time loop?
10:07 PM cehteh: that wiil harm your PID
10:08 PM cehteh: unless you account for time in PID, but thats also ugly in some ways
10:10 PM enh: PID is in the servo module. This is the communications one.
10:10 PM enh: Free spinning.
10:11 PM enh: > 1kHz
10:11 PM enh: amazing
10:13 PM cehteh: heh
10:13 PM cehteh: guess you have a lot to learn :D
10:13 PM enh: sure i do
10:13 PM cehteh: for comm you want some constant time too
10:14 PM cehteh: maybe different frequency than control loop but timebases help
10:14 PM cehteh: even if you make that dynamic (once telemetry packets get too big it backs off and sends them in slower intervals)
10:15 PM enh: with servo, sensor and flight control modules plugged I get around 1 telemetry every two seconds. COM sends telemetry every 300 cycles.
10:16 PM cehteh: i still think there will be performance bottlenecks, esp in the control loop
10:16 PM cehteh: but you'll see
10:16 PM enh: I hope to get there soon.
10:17 PM enh: I'm still seeing ghosts in the capability list: 02(2 2 )03(2 2 )04(2 2 )09(4 4 4 )10(4 4 4 )11(4 4 4 )12(4 4 4 )17(1 )
10:17 PM cehteh: where possible you want some asynchronity esp when things run on other hardware then you dont want to do the whole turnaround and latency
10:17 PM enh: CapabiityBit(SlotList)
10:17 PM cehteh: query something via spi and wait for an answer
10:18 PM cehteh: thats your bug :D dunno what you talking about but sounds like you have to fix it
10:18 PM cehteh: off by one errors, buffer overflows, etc
10:19 PM enh: I'll catch it soon
10:20 PM enh: This is an old overview of the system. Written long ago: https://cdn.hackaday.io/files/11724501599616/general_info.pdf
10:22 PM enh: This was meant to be another draft: https://cdn.hackaday.io/files/11724501599616/YAUVC-SystemDocument-draft-19Feb2017.pdf
10:22 PM enh: I must do all this again. Seriously better.
10:23 PM cehteh: haha yes
10:23 PM enh: But it gives an idea as it is now
10:24 PM * cehteh goes to sleep
10:25 PM enh: sleep well
11:36 PM day__ is now known as daey