-
Hello, I am using Zephyr 3.4 for my MIMXRT1062 system. I am trying to enable ADC interrupts and am not able to. I have the following code: prj.conf: Overlay file: &adc1 {
}; In my main code, since I don't see an API for adding interrupts, I have the following: adc_config_t adcConfigStruct; adc_channel_config_t adcChannelConfigStruct; while (1) { I have the following defined as well: I am printing the config registers of ADC1: I got this code the an example from MCUexpresso and have this code running in that example (evkbmimxrt1060_adc_12b1msps_sar_interrupt). All my register values map with MCUexpresso. The behavior I observe is that "ADC1_IRQHandler" is never called. I looked into startup_mimxrt1062.c code as well, where ADC1_IRQHandler is declared, and the weak definition of ADC1_IRQHandler is also never called. So it looks like interrupts are not being triggered. Can you please help with what I might be missing to trigger interrupts? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
As for interrupts generally, please read the Zephyr interrupt documentation to understand the context But more specific to this case, the interrupt for the ADC is already enabled and associated with the ADC driver. Is there something that you are trying to accomplish that is not covered by the Zephyr API? Please see the ADC API documentation, maybe the ADC sequence callback meets your needs |
Beta Was this translation helpful? Give feedback.
-
Hey Declan, Thanks for your response. I need to be able to continuously read ADC conversions on a channel (as fast as the processor allows) and process them in a separate thread. Ideally, I would have liked to set up the interrupt function to read and then swap buffers and/or channels as needed for my application for as long as the application is running. The advantage of the bare-metal implementation is that I can write ADC1_IRQHandler as needed. With the Zephyr ADC driver, it looks like this API is not exposed to the user. I am looking at functions like: Stepping through the code, it seems like even if I give the following options: For the swapping buffer fix, I can use the sequence callback to swap buffers, but I will still need to call adc_read again in a thread. But this is still workable. The delay I mentioned above might be a gating factor. Is there something I am not understanding correctly? |
Beta Was this translation helpful? Give feedback.
-
An update here, adc_read takes ~530us with the above configuration. That is a delay of ~4.14us between samples. This is about 4x what the hardware can support. How can I make this delay less? |
Beta Was this translation helpful? Give feedback.
-
Another update: |
Beta Was this translation helpful? Give feedback.
-
@Shruuts I have seen this limitation on other platforms with other ADC as well. Perhaps you can make an enhancement request in the issues tab, and ask for the ADC context to be enhanced so that it doesn't need so much cpu intervention after each sample. Issues are much more likely to get attention from developers than discussions. This is not really an issue with the user-facing zephyr API or the 12b1msps_sar ADC driver specifically; it is an issue with the common driver code in adc_context that has severe implications for performance in certain use cases like the one you describe. In addition to this use case, there are also some ADCs I have seen with hardware features that cannot be supported with this current adc_context, such as DMA driven buffer filling, and ADCs with hardware fifos that cannot be fully taken advantage of since they must be limited to a size of 1 sample to meet this adc_context api. Alternative is to re-write the driver not to use adc_context, but this should not be what happens in the tree because the point of adc_context is to save work for driver development since there are some common operations that need done. So we should just be improving adc_context first. Another alternative specifically for you for now is to just disable the zephyr ADC driver with kconfig and use the mcuxpresso sdk adc driver from your application. You can connect the interrupt to an isr with IRQ_CONNECT as mentioned in the documentation I linked above. But this is more awkward, obviously, defeats the point of having zephyr drivers, and not what we want people to have to do. I would prefer to extend adc_context functionality than for this to be the norm. |
Beta Was this translation helpful? Give feedback.
-
@Shruuts before this though, can you confirm that the most delay is from the adc context/driver code and not user callback, also, calling adc_read is not necessary except after all of the sequence extra samplings complete. as for enableHighSpeed, I suppose this could be a configuration option for this specific ADC, so you can make an issue about that too or contribute it yourself if you wish |
Beta Was this translation helpful? Give feedback.
-
Hey Declan, I haven't looked at the DMA functionality for this chip, so I don't have comments on that for now. As you suggested, for now I am disabling adc from my overlay file and calling NXP functions directly. This works as expected now! The latency per sample is ~1.7us (I am reaching out to NXP to try and reach their minimum of 0.7us). The same sample reading takes ~4us if I use the adc_context API by setting the 'extra_samplings` option in adc options (with the high-speed option enabled). Here are the enhancement requests I have made: |
Beta Was this translation helpful? Give feedback.
@Shruuts I have seen this limitation on other platforms with other ADC as well. Perhaps you can make an enhancement request in the issues tab, and ask for the ADC context to be enhanced so that it doesn't need so much cpu intervention after each sample. Issues are much more likely to get attention from developers than discussions. This is not really an issue with the user-facing zephyr API or the 12b1msps_sar ADC driver specifically; it is an issue with the common driver code in adc_context that has severe implications for performance in certain use cases like the one you describe.
In addition to this use case, there are also some ADCs I have seen with hardware features that cannot be sup…