#avr Logs

Dec 04 2017

#avr Calendar

12:53 AM rue_mohr: I have quadrature code, its the fastest, but nobody is interested
12:56 AM rue_mohr: nobody is ever interested
12:57 AM Casper: because your code suck! mouahahahahahahhahahahahahha
12:57 AM rue_mohr: its faster than yours
12:58 AM Casper: nope, mine is the fastest!
12:58 AM Casper: because mine take 0 bytes!
01:05 AM Evidlo[m]: How does this look? http://ix.io/CKY
01:05 AM Evidlo[m]: Not sure how fast it is, but its way simpler than their lookup table thing
01:07 AM cehteh: wtf?
01:07 AM Evidlo[m]: maybe those multiplications should be in #defines?
01:10 AM Evidlo[m]: does the processor take care of static multiplications?
01:10 AM Evidlo[m]: compiler*
01:10 AM cehteh: somewhat
01:11 AM cehteh: but AVR's only know single shifts (tiny) and no multiplication
01:11 AM Evidlo[m]: do I have to add const to my variable, or will gcc figure out that I never change "divider"?
01:11 AM cehteh: x*16 == x<<4 .. takes 4 clock cycles for example (plus loads etc)
01:12 AM cehteh: what are you trying to do? i just woke up :D
01:13 AM Evidlo[m]: I'm making a frequency divider for a quadrature encoder
01:13 AM cehteh: the above 0,1,0,1 .. in uint8_t table looks like a massive waste of time
01:13 AM Evidlo[m]: It's just a test of my algorithm
01:13 AM cehteh: err space
01:13 AM Evidlo[m]: that's what the inputs might look like
01:14 AM cehteh: divide by what?
01:14 AM cehteh: half? power of 2? generic?
01:14 AM Evidlo[m]: configurable hopefully
01:14 AM Evidlo[m]: this works for any divisor that evenly divides 256, which I'm ok with
01:19 AM cehteh: you can just have a 2nd counter (counter_divided) stash its value, compare it with the previous and move along a very small table for the outputs
01:19 AM cehteh: small table -> 8 bits
01:20 AM Evidlo[m]: that's what the link I posted earlier does
01:20 AM Evidlo[m]: https://emergent.unpythonic.net/projects/01149348342
01:20 AM cehteh: where is the code there? :)
01:21 AM cehteh: ah found it
01:21 AM Evidlo[m]: the .S
01:21 AM cehteh: nah that uses a bigger table
01:21 AM Evidlo[m]: you have to regenerate the tables if you want different widths
01:21 AM Evidlo[m]: they divide by 16
01:21 AM Evidlo[m]: mine only needs to run at a few KHz
01:22 AM cehteh: me thinks about something smaller
01:29 AM cehteh: http://paste.debian.net/998993/ .. rough sketch
01:51 AM Evidlo[m]: cehteh (IRC): what is line 2 supposed to be?
01:52 AM cehteh: just mockup for reading the encoder, whatever you use there (interrupt driven? polling? ..)
01:53 AM Evidlo[m]: interrupts, yeah
01:53 AM cehteh: also one can optimize the dividion out by adding a small overflowing counter (counting divided ticks)
01:54 AM Evidlo[m]: wont your code decrease the state when the counter is unchanged?
01:54 AM Evidlo[m]: ie when divided = divided_old?
01:56 AM cehteh: thats why there is a else if
01:56 AM cehteh: if nothing changed then nothing changes
01:57 AM cehteh: i just writen it into the pastebin, just as idea, there is some room for optimization
01:58 AM cehteh: actually thinking about it i have ideas how to make it even smaller/simpler
01:59 AM cehteh: counting only divided steps
02:06 AM cehteh: http://paste.debian.net/998998/ no division
02:09 AM Ameisen: I'm looking over this firmware, trying to figure out the best way to implement stepper motor pfm
02:15 AM cehteh: i once thought about using 2 PWM outputs phase shifted for that
02:27 AM rue_bed: I have code that generates code for fixed division or multiplication
02:29 AM rue_bed: I have some really good fast encoder code if anyone cares
02:33 AM Evidlo[m]: anyone here tried simavr?
02:39 AM cehteh: i tried once yes, worked somewhat but wasnt much use
06:29 AM polprog: jesus, what did i just create: https://puu.sh/yz9pZ/704c33fbd6.png
06:31 AM thardin: meme frog
10:34 AM anon432: Hi, what IDE do you use?
10:41 AM antto: Code::Blocks \o/
11:46 AM polprog: emacs or vim
12:18 PM Emil: >code:blocks
12:18 PM Emil: abort
12:19 PM Emil: polprog: that memelinux
12:19 PM Emil: beautiful
12:20 PM Emil: if you posted it to reddit you'd get loads of karma
12:20 PM Emil: polprog: what tutorial are you following?
12:26 PM polprog: none
12:26 PM polprog: blog posts arond the net
12:26 PM Emil: well, those then
12:27 PM polprog: today i managed to make a setup that mounts a partition and switches root dir, boited with SYSLINUX,
12:28 PM polprog: now im trying to flash what works in qemu on a usb key
12:28 PM polprog: later ill embed gcc and continue building
12:28 PM polprog: ;)
12:42 PM polprog: so far i tried dd'ing the disk image various ways, that didnt work at all
12:42 PM polprog: neither does installing syslinux on the pendrive itself and moving the files over
12:42 PM polprog: it says it cant find the config file
12:42 PM polprog: damnit
12:49 PM Jartza: hallo
12:50 PM Jartza: got the price for display and agreed with others that 6€ (incl.VAT) would be OK price :)
12:50 PM Jartza: plus shipping, of course, wherever they need to be shipped
12:51 PM Jartza: I just need to figure out our paypal account password to handle the orders :)
12:56 PM Emil: I wouldn't recommend Paypal
12:57 PM Emil: Jartza: Lulz
12:58 PM Emil: you are like right next to Otaniemi
12:59 PM Emil: Aaaniin
12:59 PM polprog: if i manage to make a pendrive that can boot polprog linux then i will be a happy camper
12:59 PM Emil: sama mesta ku viimeks
12:59 PM Jartza: well Tagsu already has paypal account, for me it's the easiest thing to charge money from people
12:59 PM Emil: ah
12:59 PM Emil: okay
12:59 PM Jartza: yes, our main office is in Kimmeltie, Tapiola
12:59 PM Emil: Well it's super easy, that's for sure
12:59 PM Jartza: there's CEO, marketing and sales :)
12:59 PM Jartza: rest of "us" are in the customer premises most of the time
01:00 PM polprog: "Chief Nerd"
01:00 PM Jartza: I visit the office like once a month or so
01:00 PM polprog: that's in the credits for Netstorm
01:00 PM Emil: Yeah I was at shutdown a year ago or something
01:00 PM Jartza: (y)
01:00 PM Emil: shutdown sauna*
01:00 PM Jartza: yeah, we have the shutdown sauna regularly
01:00 PM Jartza: most of the time I just miss it because it's on fridays
01:00 PM Emil: yeah
01:01 PM Jartza: and wife is in evening shift on fridays, so I have to take care of the kid
01:06 PM Emil: a[C[C[D[D[B[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3~[3[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C[C
01:06 PM polprog: agreed
01:07 PM Emil: sssddf[C[C[C[A[B[D[A[C[B[D[A[C[B[D[A[C[D[B[B[B[B[BThis is pretty strange
01:09 PM polprog: looks like escaped arrow keys to me
01:09 PM Emil_: Yeah
01:09 PM Emil_: But
01:09 PM Emil_: I mean
01:09 PM Emil_: It's some key combination and I think on screen
01:09 PM Emil_: that can cause escape sequences to be interpreted as literals
01:09 PM Emil_: instead of escape sequence
01:09 PM polprog: o.o
01:10 PM polprog: there are two emils
01:10 PM polprog: and i didnt drink today
01:10 PM Emil_: Heh
01:10 PM Emil: 6Testi
01:11 PM polprog: radio check
01:11 PM Emil: jhj[C[C[A[A[A[A[A[A[A[A[A[A[A[A[
01:12 PM Emil: Fine
01:17 PM * polprog reflashes emil
01:19 PM * Emil_ updating ...
01:19 PM fooman2011: Hello. I'm trying to do UART using an ATtiny2313A (http://www.atmel.com/images/doc8246.pdf). On ATTiny XTAL pins there is a 7.3728Mhz crystal. I'm trying to send the character 'A' using UART. The code is here https://pastebin.com/YVRGt9zF . It doesn't work whatever the baud rate, I receive a character but it's not an A. Could you please tell me what is wrong ?
01:19 PM * Emil_ CRITICAL ERROR
01:19 PM fooman2011: hey polprog :)
01:19 PM Emil_: fooman2011: have you set all the right bits?
01:19 PM fooman2011: which bits ?
01:19 PM polprog: hey
01:20 PM polprog: let me check my uart code
01:20 PM fooman2011: you mean 8bits, no stop bits etc...
01:20 PM Emil_: fooman2011: yeah
01:21 PM polprog: UBRR0L = ((((F_CPU >> 4) / BAUD) - 1) ) & 0xff;
01:21 PM polprog: UBRR0H = ((((F_CPU >> 4) / BAUD) - 1) >> 8) & 0xff;
01:21 PM polprog: this is what i have known working
01:21 PM polprog: BAUD is 9600 [macro]
01:23 PM fooman2011: Using this: http://wormfood.net/avrbaudcalc.php I can see that UBRR value should be 95 for 4800
01:23 PM polprog: is it then?
01:23 PM fooman2011: #define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
01:23 PM fooman2011: that gives 95
01:24 PM fooman2011: (7372800 / (4800 * 16)) - 1 = 95
01:24 PM polprog: you sure it runs from the crystal?
01:25 PM fooman2011: I'm trying to know but it's difficult to debug that
01:25 PM fooman2011: F_CPU is correctly set
01:25 PM fooman2011: I have tried to blink led each sec
01:25 PM fooman2011: it seems to work
01:25 PM fooman2011: It's enough to say 'it rund from the crystal" ?
01:26 PM polprog: check fusebytes
01:27 PM fooman2011: My fuse bytes are: low_fuses=0xC2 high_fuses=0x9F
01:28 PM fooman2011: C2 should be OK to use crytal
01:29 PM Emil_: UCSRA=0b00000010; /*(double speed best speed)*/ UCSRB=0b10011000; UCSRC=0b00000110; UBRR=7;
01:30 PM Emil_: that should give you 115200
01:30 PM Emil_: But
01:30 PM Emil_: really
01:30 PM polprog: fooman2011: try hardcoding the UBRR value for now
01:30 PM polprog: i bet the problem is somewhere else though
01:30 PM Emil_: just run 16MHz crystal and 250k, 500k or 1MBaud
01:31 PM polprog: there are UBRR values precalculated in the datasheet
01:31 PM polprog: uart is rather sensitive to clock precision
01:31 PM Emil_: yeah
01:31 PM Emil_: UCSRA0=0b00000010; /*(double speed best speed)*/ UCSRB0=0b10011000; UCSRC0=0b00000110; UBRR0=7;
01:32 PM polprog: although you can get a stable 9600 with builtin osc
01:33 PM fooman2011: in the datasheet page 123 they give the formula that i'm using
01:33 PM fooman2011: polprog, yep but i need to talk to a device that use 115200
01:34 PM fooman2011: ABout the fuses, on this page: http://www.engbedded.com/fusecalc/
01:34 PM fooman2011: it set the bit "Divide clock by 8" to 1. But I have removed this. Is it ok ?
01:35 PM polprog: ok
01:35 PM Emil_: fooman2011: wtf
01:36 PM Emil_: fooman2011: for 115200 and at 2x speed it's 7 that ubrr should be
01:36 PM Emil_: and like 3 for normal speed
01:38 PM Emil: Whii
01:38 PM Emil: Working now
01:42 PM fooman2011: ... I juste tried with lowfuse =0xF3
01:42 PM fooman2011: same problem
01:44 PM Emil: fooman2011: did you copy my example config from above?
01:44 PM Emil: (also include <avr/interrupt.h> and define the ISR
01:45 PM fooman2011: Emil_: i'm trying
01:47 PM fooman2011: I replace UBRR0 by UBRRL
01:47 PM Emil: you still need the
01:47 PM Emil: 0
01:47 PM fooman2011: And i remove the 0 after the other UCSR
01:47 PM Emil: UBRR0L
01:48 PM Emil: oh it doesn't want those?
01:48 PM Emil: okay
01:48 PM Emil: yeah if it complains about the zeroes just remove them
01:48 PM Emil: and you can use UBRR=something directly to assing a value
01:48 PM fooman2011: The speed seems ok
01:48 PM fooman2011: but the character is not OK
01:49 PM fooman2011: same problem as 4800
01:49 PM Emil: have you set the port as output?
01:49 PM Emil: dunno if that would help
01:50 PM fooman2011: nope, I try
01:56 PM fooman2011: same problem
01:57 PM fooman2011: by the way "UBRR = value" doesn't work
02:00 PM fooman2011: Interesting thing. I just remove the crystal and the AVR continu to send a wrong character throught UART
02:00 PM learath: fooman2011: is it using the crystal
02:00 PM fooman2011: that is the question
02:01 PM fooman2011: it should
02:01 PM fooman2011: but if I remove the crystal the while loop should stop. right ?
02:02 PM fooman2011: I mean there is a sleep inside
02:02 PM learath: sounds like it's running on the internal clock.
02:02 PM fooman2011: yeah
02:02 PM fooman2011: I'm using the arduino IDE
02:02 PM fooman2011: I have set values on boards
02:02 PM fooman2011: .txt
02:03 PM fooman2011: these values: https://pastebin.com/5EQsxbk9
02:08 PM fooman2011: is there a way to check the fuses values ?
02:10 PM Emil: lol
02:10 PM Emil: "are you sure it's running on the crystal?" "Yeah yeah I'm sure!"
02:11 PM fooman2011: i never say that... I saied that I have set the fuses values
02:11 PM fooman2011: but remember i'm a total noob :p
02:12 PM Emil: ...
02:13 PM Emil: Jartza: so
02:13 PM Emil: when can I come pick a few up? :D
02:14 PM fooman2011: I have set the lowfuse value to 0xF3. SO it should use the crystal
02:14 PM fooman2011: is there another thing to do ?
02:18 PM fooman2011: Question: There is a fast rising and a low rising mode. In which case someone will choose the low rising mode ?
02:18 PM fooman2011: "Slowly rising mode"
02:23 PM fooman2011: according to the datasheet the correct value for low_fuse seems to be 0xD2
02:24 PM fooman2011: I just tried with this value... I have a blink led program running. When I remove the crytal the led continue to blink.
02:24 PM fooman2011: So it seems that it doesn't use the crystal...
02:37 PM fooman2011: avrdude: safemode: Fuses OK (E:FF, H:9F, L:D2)
02:37 PM fooman2011: so the fuses are correct and correctly set
02:37 PM fooman2011: so why this f... AVR doesn't use the external clock ?
02:43 PM polprog: https://puu.sh/yzojL/9c08688211.jpg
02:45 PM polprog: eleven hours later
02:45 PM fooman2011: nice keyboard
02:45 PM polprog: thanks
02:47 PM fooman2011: Hey polprog. COuld you please tell me if set the fuses is the only thing to do to tell the attiny2313A to use an external clock ?
02:47 PM fooman2011: Because it seems to still use its internal clock
02:48 PM polprog: i think they are the ony thing
02:48 PM polprog: i never used external main clock though
02:50 PM fooman2011: ok another guys see something
02:51 PM fooman2011: my lowfuse value are inverted
02:56 PM day__ is now known as daey
03:04 PM fooman2011: Oh dude I don't know what I have done but now I have: avrdude: Yikes! Invalid device signature.
03:09 PM fooman2011: it seems that my attiny is dead :/
03:10 PM fooman2011: Damn I just kill my second attiny
03:11 PM fooman2011: When I burn the bootloader with low fuse value to 0x2D it kills my attiny ?
03:13 PM Jartza: *sigh*
03:13 PM Jartza: Emil: well, I'm not very often at office, but if you happen to be near Tammisto, then probably next week :)
03:13 PM Jartza: or maybe even this week, if I just have time to pick up the displays from office
03:14 PM Jartza: nobody remembers our paypal-password, I tried to reset it but the verification code email takes so long to arrive (around 15 minutes) that the verification code expires before I get it. darn
03:15 PM Jartza: fooman2011: what attiny?
03:15 PM fooman2011: 2313A
03:17 PM Jartza: so
03:17 PM Jartza: you have external oscillator connected?
03:18 PM Jartza: because lfuse 0x2d seems to set external oscillator 3..8Mhz and startup-time 14 clocks + 4.1ms
03:19 PM Jartza: it also sets clock divider /8, so even if you have external crystal oscillator 8MHz, it would still run at 1MHz
03:19 PM Jartza: also it sets clock output to PORTD2
03:20 PM Jartza: so. if you don't have external crystal oscillator connected, the chip doesn't get clock from anywhere and it "appears" dead
03:22 PM Jartza: fooman2011: ^
03:23 PM Jartza: http://farm9.staticflickr.com/8430/7881168384_9324100552.jpg
03:23 PM Jartza: you need to connect crystal like this
03:24 PM Jartza: caps probably in range of 10-20pF
03:24 PM fooman2011: Yeah It's ok. In fact I just want to configure it to use an external clock
03:24 PM fooman2011: it seems that it is a success.
03:24 PM fooman2011: but now to burn something into i need to add the clock
03:25 PM Jartza: "clock" is a bit misleading
03:25 PM fooman2011: Jartza: are you sure about the clock divider ?
03:25 PM fooman2011: it seems to be unset with 0x2D:
03:25 PM Jartza: usually in avr terms clock means "active oscillator" with single pin clock input
03:25 PM fooman2011: 00101101
03:27 PM Jartza: so do you have crystal, or oscillator module?
03:28 PM Jartza: do you also need clock output?
03:28 PM Jartza: you're clocking another chip from attiny?
03:30 PM Jartza: exactly *what* are you using to clock the chip?
03:30 PM fooman2011: I have to use UART at 115200
03:30 PM fooman2011: that is why I need an external crystal
03:31 PM fooman2011: Now it seems to work but the speed is strange
03:31 PM fooman2011: It seems that delay 50ms is a 4.5sec delay ...??!! :/
03:32 PM fooman2011: sorry 500ms => 4.5 sec
03:32 PM Jartza: what speed external crystal you are using?
03:32 PM fooman2011: 7.3728Mhz
03:32 PM Jartza: so your chip is running at 0.9216MHz now
03:33 PM Jartza: did you define the F_CPU correctly? :)
03:33 PM fooman2011: it should be F_CPU = 7372800
03:33 PM fooman2011: I check this
03:33 PM Jartza: http://eleccelerator.com/fusecalc/fusecalc.php?chip=attiny2313a&LOW=2D&HIGH=DF&EXTENDED=FF&LOCKBIT=FF
03:33 PM Jartza: you have clock output at D2
03:33 PM Jartza: and divide by 8
03:34 PM Jartza: so with those fuses you need F_CPU = 921600
03:35 PM fooman2011: I have to set a 1 to CKDIV8 to not divide ?
03:36 PM Jartza: ahh
03:36 PM Jartza: you need to remember fuses work "the wrong way"
03:36 PM Jartza: 0 = programmed / set. 1 = unprogrammed / clear
03:37 PM fooman2011: ok great
03:37 PM fooman2011: thanks very much for your help
03:37 PM Jartza: no prob
03:37 PM Jartza: that fuse calculator probably comes in handy :)
03:37 PM Jartza: you probably also don't want the clock output on D2, unless you are clocking another MCU from that pin
03:38 PM fooman2011: Yeah so it should be: 11101101
03:38 PM fooman2011: it's right ?
03:40 PM fooman2011: That's work perfectly now thanks
03:40 PM Jartza: sounds about right
03:40 PM Jartza: -U lfuse:w:0xED:m
03:40 PM Jartza: that's what fuse calc says
03:44 PM fooman2011: great
04:15 PM Emil: fooman2011: with fuses, 0 means programmed and 1 means unprogrammed
04:19 PM polprog: night
04:27 PM Emil: good night
10:24 PM Evidlo[m]: for the attiny85, am I correct in thinking that if I want 2 pins to trigger an interrupt, I need to set an interrupt on the entire port then check which pins changed state?
10:26 PM tpw_rules: yeah
10:26 PM tpw_rules: you'd enable the pin change interrupt for whichever port they're on, enable those two pins as triggering the interrupt, then when the interrupt fires, check their state
10:27 PM tpw_rules: alternately you could connect one to the hardware interrupt and the other to the pin change interrupt
10:31 PM Evidlo[m]: what does sei() do, and is it necessary here?
10:33 PM Tom_L: enables interrupts
10:33 PM Tom_L: yes it's necessary
10:35 PM Evidlo[m]: Is it just shorthand for a bunch of register configuration stuff?
10:35 PM Tom_L: it enables interrupts
10:35 PM Tom_L: without it they won't be bothered to answer your plea
10:37 PM Evidlo[m]: I mean why is it a function instead of just writing a bit to a register?
10:39 PM Tom_L: i didn't make the rules
11:20 PM day__ is now known as daey