Interrupt Delays and read_timed
Posted: Fri Nov 20, 2020 6:41 pm
I am trying to synchronize an external trigger with the start of the read_timed function into a buffer. The issue that I'm having is that the start of the read_timed function appears to be delayed from the timing of the interrupt pin. My mechanism of testing this is to have the start of the input waveform (not the trigger) have an abnormally high value. The oddity is that this high level appears at the end of the buffer and not the beginning. Also, the index at which the high level is recorded varyies slightly between triggers. This brings up a few questions:
Does this mean the buffer is always running?
How much of delay is there between the IRQ event and the start of the read_timed function?
I believe I'm missing something critical and would appreciate any insights. Ideally, there would be a mechanism to acquire a circular buffer and mark when a trigger arrives and simply roll the array. In short, I'd like to realize some sort of scope type function as my application requires multiple signal averaging events to obtain decent signal to noise ratio.
PYBD SF3W 1.12 with the ulab library
Other pertinent details include setting the system frequency in boot.py: machine.freq(216000000)
Other relevant posts that don't fully address the issue:
viewtopic.php?f=16&t=9163&p=51609&hilit ... lay#p51609
viewtopic.php?f=2&t=6840&hilit=trigger+delay&start=10
viewtopic.php?f=6&t=4700&p=27229&hilit= ... upt#p27229
Does this mean the buffer is always running?
How much of delay is there between the IRQ event and the start of the read_timed function?
I believe I'm missing something critical and would appreciate any insights. Ideally, there would be a mechanism to acquire a circular buffer and mark when a trigger arrives and simply roll the array. In short, I'd like to realize some sort of scope type function as my application requires multiple signal averaging events to obtain decent signal to noise ratio.
PYBD SF3W 1.12 with the ulab library
Other pertinent details include setting the system frequency in boot.py: machine.freq(216000000)
Other relevant posts that don't fully address the issue:
viewtopic.php?f=16&t=9163&p=51609&hilit ... lay#p51609
viewtopic.php?f=2&t=6840&hilit=trigger+delay&start=10
viewtopic.php?f=6&t=4700&p=27229&hilit= ... upt#p27229
Code: Select all
import micropython
from pyb import ExtInt, Pin, LED
import ulab as np
import gc
micropython.alloc_emergency_exception_buf(100)
trigCount = 0
adc = pyb.ADC('X1')
buf = np.zeros(10000)
sumBuf = np.zeros(10000)
timerADC = pyb.Timer(4, freq=200000)
def sumCB(arg):
'''
So the question is whether or not we disable IRQs during this operation?
What if another trigger comes?
Ultimately to be used for signal averaging
'''
global sumBuf
global buf
sumBuf = buf+sumBuf
# gc.collect()
def readCB(arg):
n=adc.read_timed(buf,timerADC)
global trigCount
trigCount+=1
# gc.collect()
micropython.schedule(sumCB, 'Sum Arrays')
ex1 = ExtInt('X9', ExtInt.IRQ_RISING, Pin.PULL_UP, readCB)