#avr Logs

Feb 06 2020

#avr Calendar

12:05 AM day__ is now known as day
02:04 AM Roden: do you guys ever talk about assembly for cpus?
02:12 AM Thrashbarg: ...sometimes
02:44 AM hackkitten is now known as Miyu
02:44 AM Miyu is now known as hackkitten
03:10 AM Roden1 is now known as Roden
05:11 AM Roden1 is now known as Roden
06:12 AM Roden1 is now known as Roden
06:20 AM Roden1 is now known as Roden
06:35 AM Roden1 is now known as Roden
07:36 AM Roden1 is now known as Roden
10:06 AM L0g4nAd4ms: Whats the preferred way to constrain the ADC of my to a AVR MCU particular sampling rate?
10:12 AM Fuchikoma: sampling *rate* ?
10:12 AM Fuchikoma: Just sample it at whatever rate you want
10:13 AM Fuchikoma: You control when the ADC does the sample
10:17 AM L0g4nAd4ms: Yes, I know that. However, I want to to able to exactly control the point in time when the samples are picked.
10:19 AM L0g4nAd4ms: Which means i think i would need to configure a timer in such a way that gives me an interrupt frequency that is equal to the sampling rate i wish Fuchikoma.
10:28 AM Fuchikoma: Yeah that's one way to do it
10:28 AM Fuchikoma: You can set the ADC to sample continuously, and just read out the most current sample at whatever frequency you want
10:29 AM Fuchikoma: Or you can trigger the ADC when necessary and wait for it to process
10:29 AM twnqx: since there's an STM32 fraction here... i want to build https://github.com/linklayer/cantact-hw/blob/master/cantact.pdf - what do i need for programming this? i suppose you use the SWDIO 5 pin socket?
10:48 AM L0g4nAd4ms: Fuchikoma, yes, but i need a stream of samples because my samples are processed by some algorithms, hence the more the better
10:49 AM Fuchikoma: Seems neither here no there
10:49 AM Fuchikoma: It takes a finite amoutn of time to do a sample; You can either set it up to sample over and over, and read the most current sample from the output register whenver you need it
10:50 AM Fuchikoma: Or you can manually trigger the sample process when you need it, and wait for it to finish
10:50 AM Fuchikoma: It sounds like continuous sampling is what you want. What kind of frequency are you looking to take readings at?
10:52 AM L0g4nAd4ms: Currently I am aiming for 11,5kHz
10:52 AM L0g4nAd4ms: 11.5kHz
10:52 AM Fuchikoma: Yeah no problem either way
10:55 AM L0g4nAd4ms: Fuchikoma, with continuous sampling I guess you mean to let the ADC run in free run mode?
10:58 AM L0g4nAd4ms: The problem I see with the free run mode is how I can enforce the sampling rate in this mode, Fuchikoma
10:59 AM twnqx: i am not sure you can enforce it all
10:59 AM twnqx: with the way the ADC in AVRs works i think each sampling itself hitters
10:59 AM twnqx: jitters*
11:03 AM L0g4nAd4ms: well of course, for example for the Atxmega128a1 each "conversion" takes 7 clock cycles, but with the "time way" i proposed i can at least approx. control the sampling rate.
11:03 AM L0g4nAd4ms: *timer way
11:04 AM L0g4nAd4ms: When running in freerun mode the ADC samples approx. at the system clock frequency divided by the prescaler value
11:05 AM L0g4nAd4ms: + divided by 7
11:05 AM twnqx: then use a timer, trigger, and use the end of sampling interrupt to get your result
11:06 AM twnqx: if you do that, you can even send the chip to sleep in between to get better result
11:06 AM L0g4nAd4ms: that
11:07 AM L0g4nAd4ms: *thats what I plan to do, basically to sample over and over again triggered by the timer. However, I have some difficulties with the implementation.
11:07 AM Fuchikoma: Yeah you don't enforce sampling rate; At best you can tweak clock rates to slow down the ADC operation I think
11:07 AM twnqx: i feel you're better off with an external adc...
11:08 AM Fuchikoma: So you effectively adjust the "sampling rate" by controlling how often you extract the data from the ADC, rather than how often it actually samples
11:08 AM Fuchikoma: I guess I don't understand what you mean by "enforce the sampling rate"
11:09 AM Fuchikoma: There's two steps here; The sampling rate that the ADC does conversions in free mode, and the sampling rate that your program extracts the data from the buffer
11:10 AM Fuchikoma: Unless you for some reason need the ADC to sample *in synch* with something else, which is not so much controlling the sampling "frequency" but the actual timing
11:14 AM L0g4nAd4ms: No, thats what I need that for: I get sampled data from my MCU and need to pass my sample block (size e.g. 512 samples) from all channels via the serial to another piece of software that uses the samples that does some localization.
11:16 AM Fuchikoma: So this isn't about controlling the sample frequency
11:16 AM L0g4nAd4ms: One parameter of these algorithms is the sampling frequency I need to pass
11:16 AM Fuchikoma: But making sure the sample happens at a very specific time?
11:16 AM Fuchikoma: 'cause frequency and timing are very different things
11:17 AM Fuchikoma: There is nothing about free running mode that prevents you from controlling how many samples per second you record
11:17 AM L0g4nAd4ms: Yes, because I calculated an "ideal sampling frequency" interval that avoids aliasing effects for my signals.
11:18 AM L0g4nAd4ms: Hence, I want to be able to configure the sampling rate of ADC in the MCU
11:18 AM Fuchikoma: So you have *multiple* signals that you're sampling all at the same time?
11:19 AM L0g4nAd4ms: I have 4 channels in total
11:19 AM Fuchikoma: And do you need to sample all of them at exactly the same time?
11:20 AM L0g4nAd4ms: Yes.
11:20 AM Fuchikoma: Then you absolutely need to use external ADCs
11:21 AM Fuchikoma: While I'm not familiar with every single AVR being produced, to my knowledge they all only contain one ADC that gets shared with all of the analog inputs, and they need to take turns
11:21 AM L0g4nAd4ms: No, my xmega-a1 xplained board has two ADCs with 4 channels each.
11:22 AM Fuchikoma: if sampling all four channels at exactly the same time is neccessary - if you can't sample each one in turn with even a handful of microseconds time difference - then you need external ADCs
11:23 AM L0g4nAd4ms: Additionally, the ADC is pipelined which means I go up to a max. sampling frequency of 2MHz.
11:23 AM Fuchikoma: Two ADCs means you can conceivably sample two channels at exactly the same time, but not four.
11:23 AM Fuchikoma: This is the difference between frequency and timing
11:24 AM Fuchikoma: Even with a single ADC, you can sample all four channels at 11.5KHz absolutely no problem
11:24 AM Fuchikoma: But Channel 1 will take a few uS, and channel 2 will be sampled after that, and channel 3 after that... each in turn
11:25 AM Fuchikoma: They won't be exactly in synch
11:25 AM Fuchikoma: But they will all be producing 11,500 bytes per second of data
11:25 AM Fuchikoma: (or 23000 bytes per second if you're using 10-bit I suppose)
11:26 AM L0g4nAd4ms: According to the manual 4 channels can be sampled within 1,5 us.
11:26 AM Fuchikoma: What manual? What is the application?
11:27 AM L0g4nAd4ms: The official manual for the atxmega128a1.
11:27 AM Fuchikoma: okay
11:27 AM twnqx: datasheet*
11:27 AM Fuchikoma: ^
11:27 AM L0g4nAd4ms: No its called the manual if you dont belive me.
11:28 AM L0g4nAd4ms: https://www.mouser.com/datasheet/2/268/doc8077-1066117.pdf (xmega-a1 xplained)
11:28 AM Fuchikoma: What is the application? Do your samples need to be at the exact same time?
11:29 AM L0g4nAd4ms: I already told you the application: sound localization, more specifically Direction of Arrival Localization.
11:29 AM Fuchikoma: If your samples need to be synchronous, then you will need to use external ADCs because the xmega can't sample four signals at once
11:29 AM Fuchikoma: It can sample four signals in a very short amount of time, but not at the same time
11:30 AM Fuchikoma: Do you udnerstand what I'm saying?
11:33 AM L0g4nAd4ms: Yes, I get what you mean. However, using the xmega is not meant as a top notch piece of hardware for this, as it was provided to be. Its more what kind of results you can get still with the constraints of the hardware.
11:33 AM L0g4nAd4ms: Its just the practial application in this case and what comes out in the end.
11:33 AM Fuchikoma: So answer the question; Do you need the samples to be at the same time or not?
11:34 AM Fuchikoma: If yes, you need external ADCs. If not, you can use what you have onboard
11:36 AM L0g4nAd4ms: No.
11:36 AM Fuchikoma: Okay then!
11:36 AM Fuchikoma: All your concerns about sampel frequency are moot.
11:38 AM L0g4nAd4ms: And you say that because why? Because i dont need to sample at exactly the same point in time?=
11:38 AM Fuchikoma: Yes
11:38 AM L0g4nAd4ms: What if i just want to record some stream of audio data and want to export it as file? what do i pass in the metadata of the file as sampling rate because otherwise the stream is useless
11:39 AM Fuchikoma: Put one fo the ADCs into free running mode
11:39 AM Fuchikoma: Set up a timer with an interrupt to trigger at 11.5 KHz
11:40 AM Fuchikoma: On interrupt, copy the data from the four ADC result registers into a buffer
11:40 AM Fuchikoma: Presto, four channel, 11.5KHz sampling
11:41 AM L0g4nAd4ms: And in the interrupt i would to increment some variable so that i can constraint the length of my samples in total.
11:41 AM Fuchikoma: No
11:41 AM Fuchikoma: Just put it into a buffer. Interrupts should be as short as possible
11:41 AM L0g4nAd4ms: *not the length i mean the amount of samples in total.
11:41 AM L0g4nAd4ms: `num_samples`.
11:41 AM Fuchikoma: Do that outside the interrupt, in a separate process that exports the buffer
11:42 AM Fuchikoma: And does all the metadata stuff
11:43 AM L0g4nAd4ms: so basically were at this point at the start of our conversation again .P
11:43 AM Fuchikoma: Not really?
11:43 AM L0g4nAd4ms: i mean with the timer method
11:43 AM Fuchikoma: I guess I don't see the problem here
11:43 AM Fuchikoma: You are recording samples at 11.5KHz like you wanted
11:44 AM L0g4nAd4ms: i do not mean that as a problem i mean as a proposition for the solution.
11:44 AM Fuchikoma: Well that was always the solution
11:44 AM Fuchikoma: The only difference was if you manually invoke the ADC or if you let it run freely
11:45 AM Fuchikoma: I guess you could dumbfuck it and use a tuned delay loop?
11:45 AM Fuchikoma: Any interrupts wold screw that up though so never do that
11:47 AM L0g4nAd4ms: So, if my ADC clockrate is at 2e6 and my desired interrupt_freq is 11.5kHz ADC_CLK/interrupt_freq -1 yiels approx. 172,91 as a value for the counter.
11:47 AM L0g4nAd4ms: 172.91
11:48 AM Fuchikoma: sure I guess
11:49 AM L0g4nAd4ms: which means the most precise value for the counter I can give is 173
11:49 AM Fuchikoma: Yes
11:50 AM Fuchikoma: I really don't think the 0.05% error will cause a problem
11:50 AM Fuchikoma: (9/17291 = 0.0005205 or 0.05%)
11:52 AM Fuchikoma: Which if I did the math right, is 1.8 seconds per hour :D
11:52 AM L0g4nAd4ms: And letting the ADC in free run mode better as the manual start & stop method
11:52 AM Fuchikoma: It will take less time per sample, giving you more time to do things between interrupts
11:59 AM L0g4nAd4ms: Okay thanks. Now i just need to get the implementation right.
12:09 PM cehteh_ is now known as cehteh
12:13 PM L0g4nAd4ms: Fuchikoma, do you happen to know something how to consume an "event" after having it configured as an event source in the "EVSYS.CHnMUX" register?
12:19 PM Fuchikoma: Not sure what you mean by "consume"
12:20 PM L0g4nAd4ms: well somehow i need to react when the event occurs like an ISR
12:20 PM L0g4nAd4ms: like a callback
12:22 PM Fuchikoma: What peripheral is triggering the event, and what peripheral is reacting?
12:23 PM L0g4nAd4ms: TCC1 OVF triggers the event
12:23 PM Fuchikoma: okay
12:24 PM L0g4nAd4ms: `EVSYS.CH0MUX = 0b11001000; // TCC1 OVF, set overflow of TCC1 as event`
12:24 PM L0g4nAd4ms: Reacting i do not know, i guess its channel0 of the event system, so i still have to write that reaction part
12:27 PM Fuchikoma: Well like
12:28 PM Fuchikoma: You can have one timer set as a timer, to generate your 11.5KHz
12:29 PM Fuchikoma: You'd service that as an interrupt I'd imagine, but if you want to count samples I guess you could use the event to increment another timer/counter automatically
12:29 PM L0g4nAd4ms: Ah okay, thanks for your help. Anyway, now i need to go offline as i have other things to do.
03:13 PM lvlinux is now known as ruel
09:12 PM rue_shop2: what ya up to?