#avr Logs

Dec 10 2018

#avr Calendar

12:57 AM rue_mohr: regulated charge pump
02:09 AM nohit: --
08:31 AM jesseg: Good Morning
08:34 AM vmt: --
08:52 AM rue_mohr: hey
08:53 AM vmt: hi
09:03 AM polprog: hello
09:06 AM rue_mohr: I have a few thermostats with atmega in them
09:06 AM rue_mohr: anyone here design them? :)
09:07 AM rue_mohr: interested to see what I can do with them
09:07 AM rue_mohr: apparently the power supply in them failed
09:07 AM rue_mohr: seperate board tho
09:26 AM polprog: what do they use as the sensor? thermistors? semiconductors?
03:24 PM cehteh: anyone of you know if the avr-libc routine takes advantage when the divisor is a power of 2 (variable, not constant)
03:52 PM Evidlo: can I play with ADMUX inside the ADC isr in free running mode?
03:52 PM Evidlo: I want my ADC to sample A0, A1, and A2 cyclically
03:53 PM cehteh: just dont use it free running
03:53 PM cehteh: you can trigger it from a timer at constant speed without software intervention
03:53 PM cehteh: and you can change admux
03:57 PM Evidlo: you mean trigger the ADC inside a timer interrupt?
03:58 PM cehteh: no
03:58 PM cehteh: timer can trigger the adc automatically
03:59 PM cehteh: doesnt even neeed a timer interrupt
03:59 PM cehteh: that gives constant/precise ADC timing w/o the need to run super fast
04:02 PM Evidlo: I'm trying to sample 3 microphone inputs as fast as I can. Uniform sampling is fairly important because I'm doing phase analysis on the desktop side
04:02 PM cehteh: you still use the ADC interrupt for reading/muxing then, maybe filter/rolling avg
04:02 PM cehteh: what frequency .. because samlping on AVR is somewhat slow
04:02 PM cehteh: you can go faster when you only do 8 bit sampling
04:03 PM Evidlo: I figure I can get away with 3kHz. and I'm ok with 8 bit depth
04:03 PM cehteh: there are some apnotes about the adc
04:03 PM Evidlo: faster sampling is better
04:03 PM cehteh: yep 15khz is iirc the normal maximum
04:03 PM Evidlo: I'd also prefer a solution I can get working quickly rather than optimizing everything
04:03 PM cehteh: but faster for 8 bit
04:04 PM cehteh: divided by 3 mics .. thats fine then
04:04 PM cehteh: read datasheet, trigger the timer by timer is super simple
04:04 PM cehteh: ADC by timer
04:04 PM Evidlo: I thought that was free running mode
04:05 PM Evidlo: so free running means go a fast as possible with no fixed interval, I guess
04:05 PM cehteh: you have high interrupt load and need to cope with that,
04:05 PM cehteh: dunno if you can mux in free running mode reliably, maybe the next conversion started already when your interrupt starts
04:06 PM cehteh: the adc has a semi fixed frequency in free running mode, only depends on clock and its prescaler
04:07 PM cehteh: but handling 15k/sec interrupts is a lot
04:07 PM cehteh: depends on what you do in the isr
04:07 PM Evidlo: all I need to do is dump the byte into UART
04:07 PM cehteh: and note that your interrupt might be blocked by other interrupts when you have any
04:08 PM Evidlo: I basically using the Nano as a 3 input USB adc. I don't want to do any processing
04:08 PM cehteh: then you need to sync uart with adc somehow .. or make sure the uart us faster than your adc
04:09 PM cehteh: not terribyl complicated what you do, but running the timer only as fast as you really need with some headroom certainly makes things easier
04:10 PM Evidlo: 115200 baud gives me 14,400 B/s, so I'll just sample a little bit slower than 14.4 kHz
04:11 PM cehteh: do the math how fast free running mode would be for you, there isnt much flexibility
04:11 PM cehteh: w/ some timer you have it much easier to make some exact freq
04:12 PM Evidlo: Ill just do the timer then
04:13 PM cehteh: the adc has a prescaler, but thats pretty coars and just enough to operate the adc in its desired frequency range with different main clocks
04:13 PM cehteh: when you only need 8 bit then you can 'overclock' the adc a bit ... if that matters
04:13 PM Evidlo: can't I trigger the ADC from Timer1?
04:14 PM cehteh: read datasheet
04:14 PM cehteh: i know its possible but i forgotten which timer/ register does that
04:14 PM cehteh: i have some code for that too, but actually i am busy now so you are on your own .. deciphering my code or the datasheet .. or ask google
04:15 PM cehteh: https://git.pipapo.org/?p=battswitch.git;a=blob;f=src/battswitch.c;h=fc295f5d018cefcd325a24aaf903aed2345b1eae;hb=3b61d151623630cf010709df981ac1d31f74b2f1
04:15 PM cehteh: 526 // init adc, triggered by timer
04:15 PM cehteh: 527 ADMUX = MUX_REF_1v1 | MUX_VOLTAGE;
04:15 PM cehteh: 528 ADCSRB = _BV(ADTS1) | _BV(ADTS0);
04:15 PM cehteh: 529 ADCSRA = _BV(ADEN) | _BV(ADIE) | _BV(ADATE);
04:16 PM cehteh: that one is muxing as well
04:18 PM cehteh: btw when you read noise/crap you prolly want some RC filter on the input pins, lowpass matched to your sampling frequnecy
04:19 PM cehteh: (or do active filters with opamps, has the advantage that you get a mic preamp for free with that)
04:19 PM cehteh: so busy .. bbl
07:39 PM cehteh: rue_mohr: https://public.pipapo.org/stepper4.png . . looks good now, took just longer than i wanted
09:31 PM rue_mohr: I still dont understaand the advantage over trapazoidal
09:32 PM rue_mohr: it trapazoidal your accel is turned on and off, your velocity is the trapazoid, and your position whatevers
09:32 PM rue_mohr: its ok to change acceleration instentaniously
09:33 PM rue_mohr: and please dont underestimate how much I appreciate being able to debate it with ya
10:06 PM Maya-sama is now known as Miyu
10:34 PM Evidlo: shouldn't this work for a 328? http://termbin.com/mltu
10:34 PM Evidlo: It works fine with 9600 baud, but not 115200
11:15 PM Evidlo: looks like i can't go faster than 57600
11:16 PM Evidlo: that means I can only sample at (57600 / 8) / 3 = 2400Hz for each microphone. that's no good
11:17 PM rue_mohr: you cant do 115200 without a special clock rate
11:17 PM rue_mohr: esp at 16Mhz, the error is too much
11:17 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/baudcalc/avrbaudcalc-1.0.8.php
11:18 PM rue_mohr: go to the 16Mhz table, see the 3.7% error?
11:18 PM rue_mohr: thats BAD
11:18 PM Evidlo: even at 76800 I'm seeing ~3-4% error
11:19 PM rue_mohr: yes, the max I reccommend for internal osc is 19200
11:19 PM Evidlo: at 57600 I see virtually 0%
11:19 PM rue_mohr: I usually use 9600
11:19 PM rue_mohr: if you use an external 18.432Mhz crystal your ok
11:19 PM rue_mohr: (again, see table)
11:19 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/baudcalc/avrbaudcalc-1.0.8.php
11:19 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/baudcalc/avrbaudcalc-1.0.8.php
11:19 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/baudcalc/avrbaudcalc-1.0.8.php
11:19 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/baudcalc/avrbaudcalc-1.0.8.php
11:19 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/baudcalc/avrbaudcalc-1.0.8.php
11:19 PM rue_mohr: ^^ that table
11:20 PM Evidlo: yes I have it open
11:20 PM Evidlo: doesn't correlate with what I get experimentally
11:21 PM Evidlo: but that's OK. I can live with 57600 for now. My bigger problem is that my ADC interrupt is not triggering: http://termbin.com/52la
11:23 PM rue_mohr: your using the internal osc tho, right?
11:24 PM Evidlo: external 16MHz crystal. It's an arduino nano
11:24 PM rue_mohr: on a 328?
11:24 PM rue_mohr: hmmm
11:24 PM rue_mohr: you can still have it set for internal clock, but ok
11:24 PM rue_mohr: want a working adc interrupt code example?
11:24 PM rue_mohr: to test with?
11:25 PM Evidlo: sure, what does it trigger on?
11:25 PM rue_mohr: the adc interrupt
11:25 PM Evidlo: free running?
11:25 PM rue_mohr: er, conversion complete
11:25 PM rue_mohr: yes
11:26 PM Evidlo: its a bit different. I'm trying to trigger on timer0 compare match
11:26 PM rue_mohr: I think I have a FFT one around that triggers on a timer...
11:26 PM rue_mohr: ok...
11:26 PM rue_mohr: see if I can find that fft one
11:26 PM rue_mohr: or a servo one
11:27 PM rue_mohr: I use timer 1 instead is that an issue for ya?
11:27 PM Evidlo: no, its fine
11:28 PM rue_mohr: wow, I never posted the fft stuff!?!?!
11:29 PM rue_mohr: please stand by
11:29 PM rue_mohr: (cleaning, posting...)
11:29 PM Evidlo: it's probably better because timer1 has 8 more bits
11:31 PM rue_mohr: http://ruemohr.org/~ircjunk/avr/atmega328/max7219fft/
11:31 PM rue_mohr: I appologize, the comments in main are actually for a different program
11:32 PM rue_mohr: haha, man I'm abusive, "int8_t sinTable32[] = { -0.000000,-6.242890,-12.245871,-17.778248,-22.6274..."
11:33 PM rue_mohr: carefull, thats the fastest fft code this side of the 19th century
11:34 PM rue_mohr: ;)
11:35 PM Evidlo: why do you trigger on overflow instead of compare match B?
11:35 PM rue_mohr: you have to be in the groove to write stuff like those for loops
11:35 PM Evidlo: doesn't that give you less granularity
11:36 PM rue_mohr: it gave me what I needed
11:36 PM rue_mohr: but it worked if you want to use it to tweek from
11:37 PM rue_mohr: I think its overflow casue I'm having the timer reset itself to 2250 on overflow
11:37 PM rue_mohr: I was so thrilled that the bars actaully responded at the right freqs
11:38 PM day__ is now known as day
11:49 PM rue_mohr: Evidlo, is that throwing any light into the mix for you?
11:50 PM Evidlo: I'm not seeing anything printed yet
11:50 PM Evidlo: http://termbin.com/fw8e
11:51 PM rue_mohr: ughrrrrr
11:52 PM rue_mohr: never
11:52 PM rue_mohr: while(!(UCSR0A & (1<<UDRE0))); do that, in an interrupt
11:52 PM rue_mohr: set and flag and GET OUT
11:52 PM rue_mohr: have main do it
11:53 PM Evidlo: also, I realized I'm missing sei()
11:53 PM rue_mohr: yup, thats mising too
11:53 PM rue_mohr: did you look at my code there?
11:55 PM Evidlo: what does that do?
11:55 PM rue_mohr: hmm
11:55 PM rue_mohr: nothing if you dont look at the things it does
11:56 PM rue_mohr: otherwise, you might notice to isolate system initilization into re-usable functions, set flags and exit handlers, have main loops watch for flags, and set your interrupt mask reg
11:56 PM rue_mohr: regs
11:56 PM rue_mohr: I dont see you enabling the adc interrupt mask flag bit....
11:56 PM rue_mohr: kinda squinting tho...
11:57 PM rue_mohr: (1 << ADIE)
11:57 PM rue_mohr: ah, ok
11:57 PM rue_mohr: / Activate ADC with Prescaler of 128, yielding max of 9.6ksps
11:57 PM rue_mohr: ADCSRA = 1 << ADEN |
11:57 PM rue_mohr: 0 << ADSC |
11:57 PM rue_mohr: 1 << ADATE | /* auto start when timer1 overflows */
11:57 PM rue_mohr: 0 << ADIF |
11:57 PM rue_mohr: 1 << ADIE | /* enable interrupt */
11:57 PM rue_mohr: 1 << ADPS2 |
11:57 PM rue_mohr: 1 << ADPS1 |
11:57 PM rue_mohr: 1 << ADPS0 ;
11:57 PM Thrashbarg: flood the flooding flooder
11:57 PM rue_mohr: Thrashbarg, idle the idling idler
11:58 PM Thrashbarg: yes
11:58 PM Evidlo: I'm not using UART RX. And if I'm sampling at a fixed rate slower than my UART, can't I ignore UDRE0?
11:58 PM rue_mohr: idling is the habbit of the reaper
11:59 PM rue_mohr: Evidlo, I think I suggested to write known, tested, functions, and set flags in the interrupt so they more -or -less return immediatly
11:59 PM rue_mohr: so, shall I show you my rewrite of your code?
11:59 PM rue_mohr: if so, I better write it :)
11:59 PM rue_mohr: take me a min, tell me if your interested