#avr Logs

May 15 2017

#avr Calendar

12:32 AM ibanezmatt13: Morning all! We've been trying desperately most of the night to get a simple arduino serial thing working for our UAV project for later today
12:35 AM ibanezmatt13: We have a 16MHz AVR sending ~46 characters over 57600 baud hardware serial to a 8MHz AVR that's trying to receive it
12:35 AM ibanezmatt13: We've had this baud rate working at certain times, and lower ones working, and then not working properly, and we know we have a timing issue
12:35 AM ibanezmatt13: Sometimes we can get exact copies through, other times bits of one string are in the wrong place etc. We feel like we don't properly understand how the uart is working and how our code should be written to make this work
12:35 AM ibanezmatt13: It's almost like the sender is overwriting the data in the other chip's rx buffer before it can be read, i.e. some kind of timing mismatch, but we're not sure how to fix it
12:35 AM ibanezmatt13: Any ideas are most welcomed! :) We thought somehow we could only allow the sender to send its data when the rx buffer of the other chip was empty but not sure if that;s right
12:35 AM Casper: ibanezmatt13: avr to avr or pc to avr?
12:36 AM ibanezmatt13: avr to avr, atmel 328p both of them
12:36 AM Casper: both using a crystal or internal RC?
12:36 AM ibanezmatt13: both external crystals
12:36 AM ibanezmatt13: here is code: https://pastebin.com/iPwZcYRX
12:36 AM ibanezmatt13: that code is on the receiver end
12:37 AM ibanezmatt13: you can see the serial part of this in the loop
12:37 AM Casper: pc-avr, it won't work right with a 8MHz crystal, avr-avr will be fine
12:38 AM Casper: actually
12:38 AM ibanezmatt13: ah ok, yes we've had it working well before, it's just when we continue to modify our code with more processing etc, it stops working properly
12:38 AM ibanezmatt13: https://pastebin.com/RRh0eKfz
12:38 AM Casper: you said 16 vs 8?
12:38 AM ibanezmatt13: sender code ^
12:38 AM ibanezmatt13: yes
12:38 AM Casper: incompatible
12:38 AM ibanezmatt13: it can't be, they work just fine
12:38 AM ibanezmatt13: or have done at least :P
12:38 AM Casper: the error rate is too high
12:39 AM Casper: it will work unreliably
12:39 AM ibanezmatt13: But through the level shifter it's fine, it is reliable enough from what we've seen
12:39 AM Casper: 8MHz = -3.5%, 16MHz = +2.1%, total of 5.6% error
12:39 AM Casper: Do expect issue
12:40 AM Casper: try to set the x2 mode on the 8MHz
12:40 AM ibanezmatt13: we're not sure how to set that
12:40 AM Casper: 38400 work fine
12:40 AM Casper: http://wormfood.net/avrbaudcalc.php
12:49 AM ibanezmatt13: 38400 on both, it still reads in a sprious character at the end
12:49 AM ibanezmatt13: so our sender data ends with 45\n and our receiver has echoed out that it received exactly the same, but the ending is 456\n
12:50 AM ibanezmatt13: timing error? We don't think we're doing the right thing with the serial ports
12:58 AM Casper: at this state, a scope may be needed...
01:10 AM rue_bed: duh, transmitt a repeated U
01:10 AM rue_bed: its code is 0x55
01:10 AM rue_bed: so you can masure the freq
01:12 AM ibanezmatt13: we have a logic analyser
01:13 AM ibanezmatt13: the serial is fine, both are working at correct rate with minimal error. The issue is timing, our code is basically rubbish
01:13 AM rue_bed: back in 1994 people knew how to do auto baud detection with a serial port and software
01:13 AM rue_bed: (hah)
01:14 AM ibanezmatt13: We have 46 characters coming in over serial every so often. All we need to do is be able to read those 46 characters in, then read it again a while later the next time it comes, but at the right time, and we're not doing this :/
01:14 AM ibanezmatt13: yeah :P
01:14 AM ibanezmatt13: Is there a reliable way to do this with Arduino serial?
01:14 AM ibanezmatt13: lol we have approximately 1hr til we need to pack stuff up to head to our flight test :P
01:15 AM ibanezmatt13: Everything is there bar the way we're reading in serial
01:17 AM rue_bed: why... no, nothing arduino is reliable
01:17 AM rue_bed: those two words do not go togethor
01:18 AM rue_bed: all arduino libraries and piles of junk that only just barely work by loose definition and fluke
01:18 AM rue_bed: hardware is fine
01:18 AM rue_bed: oh, gee, 1hr, ike, good luck
01:30 AM ibanezmatt13: thanks
02:02 AM JanC_ is now known as JanC
03:08 AM eballetb` is now known as eballetbo
03:12 AM aczid_ is now known as aczid
05:35 AM daey_ is now known as daey
05:37 AM Emil: Casper: that's not how errors accumulate :D
05:38 AM Emil: ibanezmatt13: why arent you listening to Casper ?
05:39 AM Emil: "hey we need help with x" "do y and z because w" "nono w is not an issue it doesnt work pls halp"
05:41 AM Emil: Casper: actually you might be okay on those error rates
05:41 AM Emil: ibanezmatt13: use 250k with 2x speed for reliable comms
05:42 AM Emil: or any other non standard 0% error rate speed
06:11 AM ibanezmatt13: Yeah sorry for her ambiguity, we had very little sleep. Flight is postponed so we have one more day to get this right :P
06:11 AM ibanezmatt13: 250K?
06:14 AM theBear: funny how the people who can't make something they doing work are always the most sure about how other bits are perfect and not-related to the issue
06:15 AM Snert: it's called backing yourself into a corner with your own logic.
06:16 AM theBear: yeah ? i was under the impression it was called being a silly jackass <grin> but i admit your version does sound more sciencey
06:46 AM Lambda_Aurigae: is the ardweeny serial code as bloated as the digitalwrite?
06:57 AM skz81: Lambda_Aurigae, are you stating digitalWrite is bloated ? How can this be ? (I mean, there is few complexity and extensive field testing....)
06:58 AM skz81: never had real problems with Hardware Serial class. I mean, I had about the same with custom stdout and printf()
06:59 AM LiaoTao: skz81: digitalWrite is _slow_
07:11 AM Lambda_Aurigae: I haven't actually used arduino in years....I tried it, found it very lacking, and uninstalled it.
07:11 AM Emil: skz81: https://emil.fi/jako/koodi/overhead.cpp
07:11 AM Emil: ibanezmatt13: yes use 250k baudrate
07:11 AM Emil: you get 0% error
07:12 AM Emil: "0%"
07:12 AM Emil: you probably also have to enable 2x speed
07:13 AM Lambda_Aurigae: I believe it was stated earlier that they didn't know how to enable 2x
07:15 AM Emil: they can use a search engine
07:15 AM Lambda_Aurigae: ibanezmatt13, the serial communications library you are using, does it poll the serial port or is it interrupt driven?
07:16 AM Emil: if it's normal arduino shit it's polling
07:17 AM skz81: https://hastebin.com/kuturuqihi.cpp << haha that's why... Ok then...
07:17 AM skz81: NB : #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
07:19 AM Lambda_Aurigae: also, where is it that people are using arduino to control flying devices? I want to avoid that area by at least 100 miles.
07:19 AM skz81: Lambda_Aurigae, what do you mean "arduino" ? API ? Or PCBs ?
07:20 AM Lambda_Aurigae: API
07:20 AM Emil: HAL*
07:20 AM Lambda_Aurigae: Emil, shouldn't that be HDL? Hardware Distraction Layer
07:21 AM Emil: hmm, quite
07:22 AM Lambda_Aurigae: this flying with arduino thing with last minute "we can't get it to talk" is almost as bad as the guy on ##pic yesterday who was supposed to write a usb device library from scratch in a week,,,and not knowing how to read a schematic to know how the thing was powered so he could control the power...
07:23 AM skz81: Emil, right, but to me an HAL *is* an API. Kinda purpose specific, sure...
07:23 AM Lambda_Aurigae: after I explained his board to him(olimex pic32mx usb-otg board) he decided to make his own board...WTF??
07:23 AM skz81: And arduino does NOT ONLY abstract hardware, actually :p
07:23 AM skz81: Lambda_Aurigae, lol 2 HDL ^^
07:24 AM Lambda_Aurigae: this guy was using pinguino too....flippin pic32 arduino-ish crap.
07:27 AM skz81: Lambda_Aurigae, haha, and does he even think of porting that thinguino to his own board ?
07:27 AM Lambda_Aurigae: and there is no way to set the 2x mode in arduino's serial library that I can see...so they would have to,,umm,,,heaven forbid!,,,set bits in a register directly!
07:27 AM skz81: I guess this is not "automagical"
07:28 AM Lambda_Aurigae: skz81, no clue....
07:28 AM Lambda_Aurigae: I told him he needed to learn basic electronics first...that went right over his head.
07:28 AM Lambda_Aurigae: he read the usb spec and the part of the datasheet on the usb hardware and understood it all apparently and that's all he needs.
07:31 AM Lambda_Aurigae: ok...time to head to work and see what I can break.
07:31 AM Lambda_Aurigae: laters.
08:36 AM enhering: Morning!
09:04 AM Emil: And there it went another order to Oshpark for 108,3+46,0$ for super switf and quick shipping :D
09:05 AM LeoNerd: Wow, expensive. You must be in a rush for that...
09:07 AM Emil: Yeah :D
09:07 AM Emil: Now to order parts from Digikey/Mouser
09:53 AM ibanezmatt13: You should be able to write arduino code that references registers right like UCSRB ? I've included <avr/interrupt.h> but it seems it doesn't know what UCSRB is when I try to compile
09:53 AM Emil: it's in avr/io.h
09:53 AM Emil: All the registers are in avr/io.h
09:54 AM Emil: avr/interrupt.h provides the relevant data structures for declaring interrupts
09:54 AM ibanezmatt13: ahh ok, I have tried also avr/io.h but still same error, UCSRB not declared in scope
09:55 AM LeoNerd: What chip? Are you sure it /has/ a UCSRB?
09:55 AM ibanezmatt13: 328p
09:56 AM ibanezmatt13: think so
09:56 AM LeoNerd: That has a UCSR0B; the 0 is required
09:56 AM ibanezmatt13: ohh
09:56 AM LeoNerd: Even though there's only one UART in said chip. :)
09:56 AM ibanezmatt13: sorry I should check the datasheet more clearly
09:57 AM LeoNerd: Sometimes if there's only one unit of something, there's no identifying digit in its register names. Sometimes there is
09:57 AM LeoNerd: Maybe someone at Atmel^WMicrochip knows the reason why
09:58 AM Emil: LeoNerd: welllll, has anyone ever opened the chip?
09:58 AM Emil: LeoNerd: given that m328pb has two
09:58 AM Emil: (though it is a newer one)
09:58 AM LeoNerd: Oh I'm aware the PB has two
09:58 AM Emil: I'd like to know what secrets are hidden inside avrs
09:58 AM LeoNerd: So it makes sense for the PB to have a UCSR0A vs UCSR1A
09:58 AM Emil: if there are undocumented features
09:59 AM LeoNerd: But why would the 328P need to distinguish it? Maybe just for portability?
09:59 AM Emil: probably
09:59 AM LeoNerd: E.g. things like the clock prescaler or USB module never get ID numbers. Perhaps because Atmel imagine there'd never be a chip with multiple such unit?
10:08 AM Lambda_Aurigae: ibanezmatt13, does that chip have dual usarts?
10:09 AM Lambda_Aurigae: oh, nevermind....
10:09 AM ibanezmatt13: no just the one I think, we've sorted it now it was that naming with 0
10:09 AM Lambda_Aurigae: read the documentation.
10:10 AM Emil: Lambda_Aurigae: it's hard when you are getting started
10:10 AM Lambda_Aurigae: or when you are using arduino and not reading real datasheets.
03:49 PM daey_ is now known as daey
04:24 PM daey_ is now known as daey
04:53 PM JanC_ is now known as JanC
04:58 PM hetii: Hi :)
04:59 PM hetii: I have very odd issue or I do something wrong: here is my code: http://paste.ubuntu.com/24583112/ and result http://paste.ubuntu.com/24583114/
05:00 PM hetii: so the issue is to get value of ledt table by using index
05:01 PM hetii: eg, for index 26 I get lut == 0 0_o
05:10 PM cehteh: no time to calculate the pwm value?
05:11 PM cehteh: just looking at the higher bits of the value squared gives ok'ish results, but needs a multiplication
05:12 PM hetii: probably I will have time to do this in fly, but wonder whats wrong with my table..
05:12 PM hetii: hmm
05:12 PM hetii: Program: 7734 bytes (94.4% Full)
05:12 PM hetii: (.text + .data + .bootloader)
05:12 PM hetii: Data: 1074 bytes (104.9% Full)
05:12 PM hetii: (.data + .bss + .noinit)
05:14 PM cehteh: you commented the PROGMEM out
05:16 PM hetii: yep,
05:16 PM cehteh: which chip? .. stack crashing into heap?
05:17 PM hetii: atmega8
05:17 PM Tom_L: last i checked something that was 104.9% full was running over
05:18 PM cehteh: how much sram has the mega8 .. iirc very little
05:18 PM cehteh: oh 1k
05:19 PM Tom_L: i'm wondering when that chip will just go away finally
05:19 PM cehteh: yep
05:19 PM cehteh: but as long people still use it
05:19 PM cehteh: hetii: copy that debug stuff reporting the values to the start of main
05:20 PM cehteh: try to figure out when/if your table gets trashed
05:23 PM hetii: ok now I try this: http://paste.ubuntu.com/24583209/ with result: http://paste.ubuntu.com/24583215/
05:23 PM hetii: ahh read_word...
05:23 PM hetii: need to change it
05:25 PM hetii: ok result looks better: http://paste.ubuntu.com/24583229/
05:25 PM cehteh: http://paste.debian.net/932626/ .. look no table
05:36 PM hetii: ok but values are differ.
05:36 PM cehteh: yes
05:37 PM cehteh: slightly
05:37 PM cehteh: some tweakes ...
05:37 PM cehteh: uint8_t sq(uint16_t n)
05:37 PM cehteh: {
05:37 PM cehteh: ++n;
05:37 PM cehteh: n *= n;
05:37 PM cehteh: return (n-1)>>8;
05:37 PM cehteh: }
05:37 PM cehteh: should be good enough or?
05:37 PM cehteh: output range is from 0 to 255
05:38 PM cehteh: i used that for leds with good enough results
05:38 PM hetii: I see, ok will test it and decide what to use :)
05:38 PM cehteh: you dont want to drive color calibrated leds, only counter human perception right?
05:39 PM hetii: yes
05:39 PM cehteh: mine clearly takes a lot more cycles, but saves a lot memory, so either one can be favorable
05:40 PM cehteh: you can also RLE compress the table, leave out close values
05:40 PM cehteh: down to a table of 16 values or so
05:42 PM hetii: yep, that also possible and probably I will try this, cause don`t need have 256 steps,
05:43 PM hetii: 146 uniqe values for my array
05:45 PM cehteh: for the higher values the small differences are almost indistinguishable
05:48 PM hetii: true