Slow reaction on IRQ #18008
Replies: 3 comments
-
ESP32 interrupts are soft interrupts because of the underlying FreeRTOS. For low interrupt latency you need a bare metal port such as STM32 or RP2, with the code specifying hard interrupts. You can then expect latency on the order of 10-20μs. See docs. |
Beta Was this translation helpful? Give feedback.
-
Like Peter said, it is unlikely that you can improve things reliably when using a ESP32. As powerful as it is, the code timing is not very reliable. |
Beta Was this translation helpful? Give feedback.
-
Thanks, peterinch & robert-hh for the answer. What I can try if I don't want to switch to another processor is taking care that CSn goes low a short period after the rising and falling edge. Then this will be a hardware solution. Well every solution needs a change in my pcb design. So, lots of work to do. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an analog signal that I want to measure. See the green line in the attached picture. After a rising and falling edge of the green signal I want to read the analog value by using an external ADC (ADS7884), which is connected to the SPI bus of the ESP32. The dutycycle of the green signal can go from 10 to 90%, and its frequency is 1kHz. I have digitized the green signal and fed the digital version to two ESP pins, one with the original digitized signal and one with the inverted signal. This gives me two interrupt functions. This is all working well. But what I see and what is the problem is the slow reaction after an interrupt occurs. In the attached picture is the top blue line the ck signal that read the data from the ADC and the lower blue line the CS line on the ADC. This CS line is the problem. Unfortunately, the first rising edge of the green signal in not shown, but the time form this edge to a low going CSn line is way too long. It takes roughly more that 200 us to go low. When CSn is going low the ADC samples the analog value and start the conversion. Reading out the data is also rather late not that’s not really the problem. Weird enough is the reaction on the falling edge of the green signal much faster, but still to slow.
From my main software I call get_adc_samples() and after that calc_cp_voltage(). After 100 millisec I call these functions again.
Anyone suggestion how I can make this faster? I would like to have that CSn goes low within 50us after a rising or falling edge of the green signal
`
#################################################
read ADC on interrupt trhough SPI
ESP32-WROOM-32 processor
ADS7884 ADC (falling edge of CSn starts conversion)
#################################################
from machine import Pin, ADC, SPI
from time import ticks_us, ticks_diff # Importeer tijd functies voor debouncing
#from definities import cp_val_pos, cp_val_neg
import definities_hardware
import definities
cp_val_pos_buf = bytearray(2)
cp_val_neg_buf = bytearray(2)
pos_done = False
neg_done = False
Create ADC object
cp_in_adc = ADC(Pin(definities_hardware.cp_in_pin))
Make SPI Chip Select line
cs = Pin(definities_hardware.spi_cs_pin, mode=Pin.OUT, value = 1) # create chipselect
CReate SPI interface with prameters
spi = SPI(2, baudrate=2000000, polarity=0, phase=1, bits=8, firstbit=SPI.MSB, sck=Pin(definities_hardware.spi_clk_pin), mosi=Pin(13), miso=Pin(definities_hardware.spi_miso_pin) ) # 35 is unused pin
Define GPIO pins for IRQ detection
IRQ_pos_trig = Pin(Pin(definities_hardware.cp_pos_trig), Pin.IN) # for rising edge
IRQ_neg_trig = Pin(Pin(definities_hardware.cp_neg_trig), Pin.IN) # for falling edge
Interrupt handler for rising edge of signal
def handle_pos_interrupt(pin):
global cp_val_pos_buf
Interrupt handler for falling edge of signal
def handle_neg_interrupt(pin):
class class_CP_sniffer:
def init(self, pin, cp_adc_range, cp_adc_bits, cp_adc_width, cp_adc_scale, cp_adc_shift):
# make Pin object for analog signal
self.cp_in_pin = Pin(pin)
`
Beta Was this translation helpful? Give feedback.
All reactions