#avr | Logs for 2015-04-17

Back
[07:37:19] <Fryed> I've plugged 5v to GND and vice versa
[07:37:26] <Fryed> Is the micro damaged?
[07:38:56] <LeoNerd> Maybe. Depends how long
[07:39:11] <LeoNerd> I've got an OLED display at home I powered up backwards for ~10 seconds or so, and it's fine now
[07:53:15] <Fryed> less than 10 seconds
[07:53:40] <Fryed> the programmer (usbtiny) powered down
[08:10:52] <Fryed> it does detect the chip
[10:11:59] <Crak> hi all
[10:15:34] <Crak> is it possible, that some interrupts in my code are skipped?
[10:33:43] <learath> are you hitting interrupts in interrupts?
[10:34:47] <Crak> no
[10:34:56] <Crak> well
[10:35:02] <Crak> i don't think so
[10:35:13] <Crak> i only set 'flags' in the interrupts
[10:35:33] <Crak> i am building a clock to get familiar with the avr
[10:35:56] <Crak> with fotoresistor and rotaryencoder
[10:36:50] <Crak> if i only use the assynchronous interrupt driven by external 32khz clock it is quiet prezise
[10:37:34] <Crak> but when i uncomment the the other interrupt (with prescaler to have about 125khz) to read fotoresistor and rotary encoder
[10:37:44] <Crak> the clock becomes slower
[10:38:27] <Crak> maybe i have to make code atomic ... i don't know
[10:42:32] <Crak> learath: this is my code: http://pastebin.com/pqk5AsMv
[10:45:23] <learath> some of your comments are not actually commented?
[10:45:46] <learath> I don't see anything super obvious, but I'm not good at finding things like that
[10:46:44] <Crak> yeah, i c. i uncommented before pasting. maybe some of them lost their //
[10:47:06] <learath> I really don't see anything super obvious
[10:47:12] <Crak> maybe i soldered something wrong
[10:47:18] <learath> init_timer2 does disable interrupts, but it looks like it only runs once
[10:48:48] <Crak> so that the capacity changes when i read rotary or fotoresistor
[10:49:54] <Crak> i put 2pf on xtal1 and 12pf on xtal2
[10:50:29] <learath> oh
[10:50:37] <LeoNerd> 2pF??
[10:50:45] <LeoNerd> Your PCB trace alone will be more than that :P
[10:50:51] <learath> so, this random doc I found says In normal mode TOV2 can generate a Overflow interrupt. In order to activate the timer1 overflow interrupts you need to SET(1) the TOIE1 bit within the TIMSK2 register.
[10:51:12] <learath> hm. I wonder if that's a screw up
[10:51:50] <Crak> yeah -> my calculation: c1 = 2*CL - Cs1 => 2*10pF - 18pF = 2pF
[10:52:03] <Crak> i set TOIE1 in TIMSK2
[10:52:30] <Crak> init_timer2
[10:53:00] <Crak> well i do not use timer1
[10:54:30] <learath> yeah. that's a screw up, it should be TOIE2
[10:54:47] <LeoNerd> ;)
[10:54:58] <Crak> ah
[10:55:07] <Crak> Table 8-8. Capacitance for Low-Frequency Crystal Oscillator
[10:55:17] <learath> LeoNerd: but the internet is always right!
[10:55:26] <Crak> learath: u mean the doc is wrong?
[10:55:33] <learath> Crak: no, the doc I found was wrong
[10:55:46] <Crak> yes
[10:56:16] <learath> I really don't see anything obviously wrong with your code
[10:56:46] <Crak> learath: ok, thx alot
[10:57:07] <Crak> so there is no possibility that some seconds are 'dropped'?
[10:57:16] <learath> that's not what I said :)
[10:57:33] <Crak> :)
[10:58:12] <Crak> i cannot understand, why the clock is ok running only the timer2 and unncomment the rest
[10:58:39] <learath> eh. make it simpler
[10:58:46] <learath> start with a fixed string
[10:58:48] <learath> and go from there
[10:59:11] <Crak> what do u mean with fixed string?
[10:59:18] <Crak> fixed time?
[10:59:38] <learath> What's the old saw? "Once you eliminate the impossible, whatever is left, no matter how strange, is the case"
[10:59:42] <learath> Crak: yes
[10:59:57] <learath> just to test your output & wiring
[11:00:00] <Crak> this is what i am doing
[11:00:12] <learath> are you using PWM anywhere?
[11:00:32] <Crak> no
[11:01:42] <Crak> this is the commented code that is running with good seconds: http://pastebin.com/cmNDtcN0
[11:02:15] <learath> someone needs to make diffbin
[11:02:36] <Crak> hehe yes
[11:03:10] <Crak> well no init_timer0() in main()
[11:03:35] <learath> is your rotary encoder super noisy?
[11:03:48] <Crak> i guess yes
[11:04:09] <Crak> this is why i worked whit scanRotaryEncoder()
[11:04:14] <learath> try your code with the encoder, but disconnect the encoder
[11:04:34] <Crak> it is all soldered already
[11:04:52] <learath> do you have a 'scope you can tag on it?
[11:04:59] <Crak> no
[11:05:01] <Crak> sry
[11:05:02] <learath> if the encoder is constantly triggering that could cause lost interrupts
[11:05:09] <Crak> well
[11:05:20] <Crak> i do not interrupt on pin change
[11:05:26] <Crak> i use overflow
[11:05:31] <learath> hmmm
[11:05:32] <Crak> in timer0
[11:05:37] <Crak> then scan the encoder
[11:05:44] <Crak> and the fotoresistor
[11:05:54] <learath> hmm. well maybe test your rotary encoder?
[11:05:57] <learath> without your clock
[11:06:11] <learath> like, have the interrupt update a counter
[11:06:17] <learath> instead of your clock
[11:06:18] <Crak> ?
[11:06:24] <learath> just count every rotary encoder event
[11:06:35] <learath> no events, 00:00, first event 00:01, second 00:02
[11:06:50] <learath> maybe be fancy if you want, do digits for different cases
[11:06:59] <Crak> well the encoder does work fine
[11:07:11] <learath> right_simple updates x0:00, right_pressed updates 0x:00, etc
[11:07:19] <learath> are you sure?
[11:07:19] <Crak> i can adjust the time in 15min steps and 1min step if button is pushed too
[11:07:26] <Crak> yes
[11:07:42] <Crak> there are two patterns
[11:07:48] <Crak> one has to be matched
[11:07:58] <Crak> else no enc_delta is done
[11:08:23] <Crak> have a look at scanRotaryEncoder()
[11:09:04] <Crak> if (current != last) { ... if (shiftreg == RIGHT) {
[11:09:26] <learath> hmm
[11:09:36] <Crak> where RIGHT is 0b11010010
[11:10:04] <Crak> i figured it out some weeks ago that only certain states are possible
[11:10:25] <Crak> so some kind of software debouncing
[11:10:27] <Crak> ...
[11:11:08] <learath> is it possible you are overflowing a variable?
[11:11:27] <Crak> shiftref yes
[11:11:48] <Crak> if something has changed -> if (current != last)
[11:12:01] <Crak> well it is permanently overflowed
[11:12:05] <learath> I had an impossible to track down bug, that happened to be a variable that was getting a longer string written to it
[11:12:11] <learath> so it was smashing the next variable
[11:12:14] <Crak> because i shift deltas into it
[11:12:31] <learath> I found it by just going through *everything*
[11:12:40] <learath> check state, next command, check state, next command, check state
[11:12:42] <learath> super tedious
[11:13:04] <Crak> what is happening if i shift left into it? ->shiftreg <<= 2;
[11:13:20] <Crak> the left bits go to nowhere right?
[11:13:26] <learath> I don't know.
[11:13:33] <Crak> or do they override something else?
[11:13:44] <learath> but that part is working right?
[11:13:48] <Crak> yes
[11:14:14] <Crak> but only on this prescaler config -> 125kHz sampling
[11:14:45] <Crak> if clock is faster than 1mhz
[11:14:58] <Crak> it does not work right
[11:15:00] <Crak> any more
[11:15:36] <Crak> i think then the bouncing is taken into account
[11:16:04] <Crak> but i am really not sure
[11:16:19] <Crak> i have to poor knowlegde about this. i am sorry!
[11:16:53] <Crak> let me make a short video...
[11:28:52] <theBear> how does err, no sound
[11:28:58] <theBear> you may not make a video, use yoru big boy words
[11:29:20] <N1njaneer> the
[11:29:29] <N1njaneer> theBear: May I pass GO and collect $200?
[11:29:41] <theBear> DO NOT PASS GO ! DO NOT COLLECT !
[11:29:43] <theBear> :)
[11:33:51] <Crak> upload on youtube takes some time
[11:35:42] <Crak> learath: here is the video: https://youtu.be/0jtAHivKM-Y
[11:44:20] <Crak> as u can see the rotary encoder does work and the fotoresistor does too
[11:49:57] <Elec_A> Hello, I have set DDR and PORT registers to enable Pull-up resistors. Now how can I make AVR to sink current ?
[11:50:23] <Elec_A> Should I Reset PORT register ?
[11:50:47] <Elec_A> Or I should modify PIN register ?
[11:51:17] <LeoNerd> ?
[11:51:24] <LeoNerd> Surely: output low ?
[11:51:32] <Elec_A> pardon ?
[11:51:34] <LeoNerd> PIN is for reading input, it's not useful for setting the output hardware
[11:52:09] <LeoNerd> If you want to sink current, surely you set the output low? I.e. by enabling output (by turning on the DDR bit), and outputting a logic low value (i.e. by turning off the PORT bit)
[11:52:46] <Crak> Elec_A: DDRD = 0x00; PORTD &= ~(1<<PORTD1); then toggle between tri-state and sink -> DDRD ^= (1<<DDD1);
[11:53:12] <Crak> Elec_A: change D1 to the pin u use
[11:53:13] <Elec_A> aha , so you mean I can sink current by turning Rpu Off ?
[11:54:34] <Crak> Elec_A: see doc for atmega88: Table 13-1. Port Pin Configurations
[11:55:20] <Crak> DDD1 i toggle so no pullup resistor
[11:55:51] <Crak> only Tri-state (Hi-Z) and sink
[11:56:29] <Crak> i use this to let my double dots blink on my clock: https://youtu.be/0jtAHivKM-Y
[11:56:42] <Elec_A> Crak: but aas datasheet says Turning DDR and PORT registers ON , will activate Pullup resistors
[11:57:19] <Crak> Elec_A: my doc does not say this: 1 1 X Output No Output High (Source)
[11:58:04] <Crak> it says, if DDR is 0 and Port is 1 then pullup yes
[11:58:31] <Crak> maybe it depends on your mcu
[11:59:30] <Crak> i have to say that there is a z-diode between leds and pin
[12:00:27] <Elec_A> Crak: yes , I reviewed datasheet again and you are right, thank you very much !
[12:03:14] <Crak> ur welcome
[12:10:25] <Crak> ok, thank you guys for helping me. specially u learath!
[12:10:40] <Crak> i have to investigate my time gap problem
[12:13:56] <Crak> cya
[14:12:17] <Elec_A> Hello, How can I find PORT addresses in AVR ? I have searched datasheet but i cannot find it. I know PORTC is 0x15 .
[14:45:12] <Tom_itx> Elec_A, it's in the table at the back for sure