analogRead inside Timer ISR causes MBED OS to crash on RP2040 Connect #6
Replies: 5 comments
-
Hi @jmdodd95682
It's bad that you design to use the TimerInterrupt the wrong way. You violate the basic rule of using any interrupt.
The better way to do is to set a flag inside ISR, then poll, using Good Luck, |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response! I'm used to being able to perform atomic operations within the ISR to avoid asynchronous behavior. However, I tried your suggestion and it does work. I will have to watch my delay in the main loop carefully so that I am not losing samples, but I think it should work. By the way, the timer works extremely well. Thanks again! |
Beta Was this translation helpful? Give feedback.
-
I discovered the same issue, but was able to resolve it by using adc_read(); instead of analogRead(INPUT_PIN); I also needed the following before starting the interrupt: |
Beta Was this translation helpful? Give feedback.
-
Interesting. I am not familiar with adc_read(). I’ll try it too. I like learning new things.
Thanks.
From: Byon Garrabrant ***@***.***>
Sent: Thursday, November 17, 2022 11:19 AM
To: khoih-prog/MBED_RPI_PICO_TimerInterrupt ***@***.***>
Cc: jmdodd95682 ***@***.***>; Mention ***@***.***>
Subject: Re: [khoih-prog/MBED_RPI_PICO_TimerInterrupt] analogRead inside Timer ISR causes MBED OS to crash on RP2040 Connect (Discussion #6)
I discovered the same issue, but was able to resolve it by using adc_read(); instead of analogRead(INPUT_PIN);
I also needed the following before starting the interrupt:
adc_init();
adc_gpio_init(26);
adc_select_input(0);
—
Reply to this email directly, view it on GitHub <#6 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALCX2KCEFDID3RHVMOAV5ULWI2AKZANCNFSM6AAAAAASALEIRA> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/ALCX2KD7SJ5ZKWDMMAUBJXTWI2AKZA5CNFSM6AAAAAASALEIRCWGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAH6SGK.gif> Message ID: ***@***.*** ***@***.***> >
|
Beta Was this translation helpful? Give feedback.
-
Thanks again for the help. Its working perfectly. BTW the adc_read is about 4 times faster than using the standard analogRead routine. It only takes 2us versus 8us.
And, as you pointed out, it works inside the Timer ISR, so the implementation is a bit cleaner.
From: Byon Garrabrant ***@***.***>
Sent: Thursday, November 17, 2022 11:19 AM
To: khoih-prog/MBED_RPI_PICO_TimerInterrupt ***@***.***>
Cc: jmdodd95682 ***@***.***>; Mention ***@***.***>
Subject: Re: [khoih-prog/MBED_RPI_PICO_TimerInterrupt] analogRead inside Timer ISR causes MBED OS to crash on RP2040 Connect (Discussion #6)
I discovered the same issue, but was able to resolve it by using adc_read(); instead of analogRead(INPUT_PIN);
I also needed the following before starting the interrupt:
adc_init();
adc_gpio_init(26);
adc_select_input(0);
—
Reply to this email directly, view it on GitHub <#6 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/ALCX2KCEFDID3RHVMOAV5ULWI2AKZANCNFSM6AAAAAASALEIRA> .
You are receiving this because you were mentioned. <https://github.com/notifications/beacon/ALCX2KD7SJ5ZKWDMMAUBJXTWI2AKZA5CNFSM6AAAAAASALEIRCWGG33NNVSW45C7OR4XAZNRIRUXGY3VONZWS33OINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAH6SGK.gif> Message ID: ***@***.*** ***@***.***> >
|
Beta Was this translation helpful? Give feedback.
-
I been trying to get a HW timer running to periodically sample an analog input value. I can get the timer working fine using the example code. I set the timer to 30KHz timeout and inside the TimeoutHandler the only thing I have is:
input_signal=analogRead(INPUT_PIN);
Where INPUT_PIN is defined as A3. I also tried A6 to see if it was related to WiFiNINA.h.
The first time it hits the TimeoutHandler, the MBED OS crashes and the RP2040 drops into "SOS" mode.
I tried delaying the analogRead thinking it might have something to do with setup. But, it seems like (I have not verified) that the analogRead is using the same timers as the MBED_RPI_PICO_TimerInterrupt. This is somehow causing the MBED OS to go off into the weeds.
Is this a known problem? Is this something that can be worked around. Without the ability to do the analogRead, there is no point is trying to us the HW timers.
Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions