I can read the AMP skin microphone using a timed read and I can seem to read values individually using adc.read() from the prompt. But, I need to read at an interrupt-driven rate (6kHz). I've tried everything but seem to get weird (max) values doing adc.read() from an ISR.
Can you do an adc.read() from an ISR?
I've check timer values etc. etc., nothing clashes but all I seem to be able to read from X22 in my ISR are values stuck pretty much as 4096.
AMP skin adc.read() from ISR?
-
- Posts: 6
- Joined: Wed Jul 13, 2016 9:27 pm
Re: AMP skin adc.read() from ISR?
Wow - can'y anybody answer this? Can you do an adc.read() from within an ISR? I'll update to latest drivers but if you can't access the h/w from an ISR, mmmm.
Re: AMP skin adc.read() from ISR?
I see no reason why you cannot. You have to tell the ISR where adc is. So once you have the adc to, let's say, you have to declare that symbol global in the ISR to make it visible, or cache it, like:
See also a related discussion here: viewtopic.php?f=6&t=3038#p18058
@pythoncoder found, that adc.read() takes 94 µs. That does not leave much headroom, when you want to sample at 6 kHz = 167µs period.
Code: Select all
from pyb import ADC
from array import array
_BUFFERSIZE = const(128)
adc = ADC(pin)
data = array("H", [0] * _BUFFERSIZE)
index = 0
def adc_isr(x, adc = adc.read, data=data):
global index
data[index] = adc()
index = (index + 1 ) % _BUFFERSIZE
@pythoncoder found, that adc.read() takes 94 µs. That does not leave much headroom, when you want to sample at 6 kHz = 167µs period.
-
- Posts: 6
- Joined: Wed Jul 13, 2016 9:27 pm
Re: AMP skin adc.read() from ISR?
Thanks. It's working now, even though I'm seeing a significant DC offset using the AMP Audi skin - but that's a separate issue! Thanks.
Re: AMP skin adc.read() from ISR?
You need an DC offset to sample an AC signal, since the built-in ADC just receives positive values. The optimal DC offset in readings would be about half of the ADC range, for a 12 bit ADC that would be 2047.
-
- Posts: 6
- Joined: Wed Jul 13, 2016 9:27 pm
Re: AMP skin adc.read() from ISR?
Thanks, yes, understand that as they're unsigned 12-but values (0 - 4095). I'm seeing a significant offset with the AMP Audio skin, with a somewhat noisy silence hovering anywhere between 2,400 to 3,000. I can compensate for this in post-processing but it would be nice to be able trim it out.