#avr Logs

Jan 23 2019

#avr Calendar

01:51 AM davor_ is now known as davor
08:36 AM rue_bed: -
12:43 PM jancoow: cehteh: heyhey
12:43 PM cehteh: omg
12:44 PM polprog: hey
12:45 PM * cehteh busy searching bugs in his own code
12:45 PM jancoow: xD
12:46 PM * polprog found a bug in netbsd yesterday but hes chilling out today
12:46 PM polprog: oh wait
12:47 PM jancoow: dunno if you red my message 2 days ago
12:47 PM polprog: i have tat 4.4bsd iso ot test out
12:47 PM polprog: to*
12:47 PM jancoow: but it was indeed running at 1mhz
12:49 PM jancoow: But I'm not sure how I can change it
01:29 PM jancoow: cehteh: any clue? :D
01:30 PM cehteh: you use it on internal osc?
01:30 PM cehteh: https://git.pipapo.org/?p=battswitch.git;a=blob;f=src/battswitch.c;h=fc295f5d018cefcd325a24aaf903aed2345b1eae;hb=3b61d151623630cf010709df981ac1d31f74b2f1#l264
01:30 PM jancoow: yes I do
01:30 PM cehteh: set_clkdiv
01:31 PM cehteh: but read datasheet
01:31 PM jancoow: I set it to the intenal 16/20mhz oscilator
01:31 PM jancoow: and set the pre scaler devision to 2
01:31 PM cehteh: of the cpu? or timer
01:31 PM jancoow: cpu
01:32 PM cehteh: then it should run on the correct speed..
01:32 PM jancoow: yes but I'm checking it with the delay function
01:32 PM cehteh: does that tiny have a pll?
01:32 PM cehteh: forget about delay
01:32 PM jancoow: and it doesn't look like it's correct :P
01:33 PM jancoow: why, I can use it fine for testing not?
01:33 PM cehteh: because it sux
01:33 PM cehteh: make your timer blink at led at 1hz and stopwatch that
01:33 PM cehteh: better than delay which depends on moonphase and whatsnot :D
01:34 PM jancoow: but it should give me an indication
01:34 PM jancoow: not a 3 second of blink
01:35 PM cehteh: anyway read datasheet, you need to program the clocksource correctly, also correct fuses. but with wrong fuses you can fuck it up and brick the mcu .. so be very careful
01:35 PM jancoow: it looks like the prescaler doesn't change anything
01:35 PM cehteh: tinys are somewhat special some tinys have a PLL and can run at 16mhz from internal 8Mhz osc for example
01:35 PM jancoow: https://jancokock.me/f/094b1
01:35 PM cehteh: well then you do something wrong because you didnt read the datasheet carefully
01:36 PM jancoow: ah right
01:36 PM jancoow: it under configuration change protection
01:37 PM cehteh: some important registers require some special access patterns
01:37 PM jancoow: This peripheral has registers that are under Configuration Change Protection (CCP). In order to write to
01:37 PM jancoow: these, a certain key must be written to the CPU.CCP register first, followed by a write access to the
01:37 PM jancoow: protected bits within four CPU instructions
01:37 PM cehteh: see :)
01:37 PM jancoow: yea
01:37 PM jancoow: so I've to write that register right before writing the division register
01:38 PM cehteh: there should be some libc function for that ... like the one i used
01:38 PM cehteh: clock_prescale_set (clock_div_1);
01:38 PM cehteh: etc
01:41 PM jancoow: which .h file do I need to include for that?
01:41 PM jancoow: power.h?
01:42 PM cehteh: what do the docs say?
01:42 PM cehteh: i dont know, i guess its the boot.h
01:44 PM jancoow: the datasheet doesn't say anything about that function
01:45 PM cehteh: your libc should .. i dont know which one you use becasue this newfangeld chip has this weird api
01:50 PM jancoow: Couldn't find it
01:50 PM jancoow: but did it by myself now
01:50 PM jancoow: https://jancokock.me/f/4801f
01:51 PM jancoow: Had to write 0xD8 to that register
01:51 PM jancoow: after that I could change the divider
01:51 PM jancoow: dunno if I need to change it back to .. 0 ?
01:51 PM cehteh: better read the docs and find out the official/library way to do it
01:53 PM jancoow: well it works now :D it runs at 8mhz now
01:53 PM jancoow: but I need to set the fuse to 20mhz
01:53 PM jancoow: so I can divide it by 2: 10mhz
01:53 PM jancoow: that should be the maximum speed at 3.3v
01:54 PM cehteh: can the osc run at 20mhz at 3.3v?
01:54 PM jancoow: I guess?
01:55 PM cehteh: perfect
01:55 PM cehteh: and btw: you saied uart?
01:55 PM jancoow: There is even a register which tells the error on 20mhz/3.3v
01:55 PM jancoow: yes
01:55 PM cehteh: uart wont work well at internal osc
01:55 PM jancoow: why not
01:56 PM cehteh: maybe you can sync/calibrate the osc on uart, otherwise the internal osc is waay to inprecise
01:56 PM jancoow: it can
01:56 PM cehteh: uart needs stable timing approx 2% correct
01:56 PM jancoow: because it measures the error
01:56 PM cehteh: you need code for that
01:57 PM cehteh: internal osc can be calibrated, thats a advantage
01:57 PM jancoow: this says the doc: https://jancokock.me/f/62a64
01:57 PM cehteh: but unless you do it will be terrible
01:58 PM cehteh: you still need to compensate for it
02:00 PM jancoow: mm okay I didn't know that :/
02:00 PM cehteh: no magic happens
02:00 PM jancoow: I bought this chip especially for the uart support
02:00 PM cehteh: haha
02:00 PM jancoow: what?
02:01 PM cehteh: you need to do bit more investigations
02:01 PM cehteh: do you have the clock pins free and can add an external crystal?
02:01 PM jancoow: I don't have the clock pins free and I can't find an external crystal
02:01 PM jancoow: and 2 caps
02:01 PM jancoow: No board space for that
02:02 PM cehteh: wtf you already did the board?
02:02 PM jancoow: If the uart don't work out I can also use it as I2C slave
02:02 PM jancoow: yes
02:02 PM jancoow: I already have 20 pcb's
02:02 PM jancoow: :D
02:02 PM cehteh: lol
02:02 PM cehteh: still a good chance that the while stuff wont work well/fast enough unless you find a good way to optimize it
02:03 PM jancoow: But the led st rip dimmer board is already a disaster. Used the wrong footprint for both mosfets as step down converter
02:03 PM jancoow: But it works;;
02:03 PM jancoow: ah yeah. But I2C timing is much less critical so can use that instead if this doesn't work out
02:04 PM cehteh: it works? you are done?
02:04 PM jancoow: no
02:04 PM cehteh: so how do you know it works?
02:04 PM jancoow: I fixed the board by cutting traces, pulling some wires and solder mosfets upside down
02:04 PM cehteh: i mean the software
02:07 PM jancoow: https://jancokock.me/f/ea4e6
02:08 PM cehteh: no space left on board?
02:08 PM jancoow: This board is fine
02:08 PM jancoow: the other board not
02:08 PM cehteh: there is much free space :D 80% unused
02:09 PM jancoow: https://jancokock.me/f/d2f41
02:09 PM jancoow: left side is 230v :D
02:09 PM jancoow: right side is low voltage
02:11 PM jancoow: but does it even run terrible at low baudrate? Or doesn't that matter?
02:13 PM jancoow: ooooooooooooh great
02:13 PM jancoow: it doesn't have uart
02:13 PM jancoow: it has usart
02:13 PM jancoow: * kill me *
02:14 PM cehteh: huh?
02:14 PM jancoow: yeah, that's what I thought
02:14 PM cehteh: the uart is usually a usart when present
02:15 PM jancoow: oh
02:15 PM cehteh: i dont know a avr with only uart
02:15 PM cehteh: the s means it can be switched into synchronous mode as well, for spi and other things
02:16 PM jancoow: • Full-duplex or one-wire half-duplex operation
02:16 PM jancoow: • Asynchronous or synchronous operation
02:16 PM jancoow: – Synchronous clock rates up to 1/2 of the device clock frequency
02:16 PM jancoow: – Asynchronous clock rates up to 1/8 of the device clock frequency
02:16 PM jancoow: USART - Universal Synchronous and Asynchronous Receiver and
02:16 PM jancoow: Transmitter
02:23 PM jancoow: do you think it's better to make it an i2c slave?
02:24 PM cehteh: do ahtever you need
02:24 PM jancoow: I can use both :
02:24 PM jancoow: :P
02:26 PM cehteh: can you do smooth led dimming already? just make a loop from 0 to 255 brightness changing very slowly
02:30 PM jancoow: Yeah, but need to make the values in the table a bit better. But it runs now with the timer division on 4, and a top value of 128 towards 175. so: (8000000/2/128)/255 = 122hz
02:30 PM jancoow: uhm division on 2 *
02:30 PM jancoow: can make that 1 I guess
02:30 PM jancoow: as we calculated that before
02:32 PM jancoow: But gonna improve the ISR. Instead of writing values each time interupt, I'm only gonna write if the R/G/B value matched the current step. So it should only be writing at most 9 times per time interupt
02:32 PM cehteh: i was only guessing and had some gut feeling dont nail me down on the numbers
02:36 PM jancoow: yeah it looks like the main method doesn't get a lot time. So I keep the division on 2. So that will result in a 120hz refresh rate more or less
02:39 PM cehteh: should be plenty.. also even if the main gets only 10-20 cycles per timer overflow, you only need to refresh the values once every full cycle, thats 255times so avg 15*255 = 3825 cycles for handling serial
02:40 PM cehteh: even if thats not enough updating every few cycles should give plenty time
02:41 PM cehteh: just make sure that you stash the UDR away in a timely manner thats the most important thing everything else can be done more lazily
02:43 PM cehteh: with a sorted list for the times and double buffering your isr should be very small, just a few lines of code
02:46 PM cehteh: ISR() { ++counter; if(counter == table[buffer][index] .time) {PORT = table[buffer][index].value; ++index; }; }
02:47 PM cehteh: having such a simple ISR leave 255x the timev saved on the ISR for your main to do uart sort the other buffer, swap buffers when done
02:50 PM jancoow: eewh'
02:52 PM jancoow: I just wrote it differenty but it's working slower :P
02:54 PM jancoow: https://jancokock.me/f/ccd5d
02:54 PM jancoow: don't get why it is working slower now tho
02:55 PM jancoow: I mean; It only has to check 10 values each interupt
02:55 PM jancoow: Wit the old code it has to check AND write
02:55 PM cehteh: see my code above that will be much faster :D
02:55 PM jancoow: and shift
02:57 PM cehteh: because you have 2 ports and not only one needs a bit more to setup
02:57 PM jancoow: huh?
02:59 PM cehteh: also i forgotten to reset index when it becomes greater than 9
02:59 PM cehteh: still far simpler code than yours
03:00 PM jancoow: I totally don't get how that would work tho
03:00 PM cehteh: thats the trick :D
03:00 PM jancoow: lol
03:01 PM cehteh: imagine only 8 leds on a single port for simplicity
03:01 PM jancoow: yes
03:02 PM cehteh: so you can make a table: struct {uint8_t time; uint8_t leds} timetable[8];
03:02 PM cehteh: sort that by times where you switch the leds on
03:03 PM jancoow: where time is between 0 and 255
03:03 PM jancoow: ?
03:03 PM cehteh: {{0,0}, {127, 0b00001111 } ...{168, 0b11111111}}
03:03 PM jancoow: ah yes..
03:03 PM cehteh: next step:
03:03 PM jancoow: omg
03:03 PM cehteh: .. there is none
03:04 PM jancoow: I only need to make 2 tables then but
03:04 PM jancoow: I understand..
03:04 PM jancoow: Damn that's freaking easy
03:04 PM jancoow: Sometimes I feel freeking stupid when talking with you
03:04 PM cehteh: so you can make a table: struct {uint8_t time; uint8_t leds_porta; leds_portb} timetable[9];
03:04 PM jancoow: You know. I'm doing only web -based projects for the last 2 years. And then you are completely programming differently
03:05 PM cehteh: haha
03:05 PM cehteh: i cant do web programming :D
03:05 PM jancoow: You shouldn't
03:05 PM jancoow: MCU programming is much more fun then designing api's :P
03:32 PM polprog: thats true
03:32 PM polprog: webdev gave me a slight receding hairline at the age of 18
03:32 PM polprog: nighters :)
03:36 PM cehteh: boah ... found my bug
03:37 PM cehteh: fuu .. need to delete an element from a priority queue
11:48 PM day_ is now known as day