This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problem with software, need help

Hi,

i have some troubles with my software which i doesn't understand maybe some one with more microcontroller Experience cann tell me how to solve this Problem.

I have a method which waits for a Time, its like the nrf_delay but instead of this i use my own method wait_ms (TimeToWait). If i use this method in the main loop it works fine, it waits for the "TimeToWait" and then the programm is going on. But if i use this method int an timertimeout-method like my systemOff( )- method it doesn't work and i don#t understand why.

The same is if i use a method to run pwm on one pin. If i use this method in the main loop, the pwm method works but if i use it in an timeouthandler or in the SystemOff () method it does not work.

And i don't know what a reason for this could be, it would bee great if some one have an idea beacouse its a realy silly problem but it hang up the hole microcontroller.

Thanks and best regards Nils :)

  • Your question is quite vague, and sparse on details on the exact problem, so it's not very easy to help you.

    However, in general, if you have trouble with methods behaving differently when called from interrupt context and main context, you should make sure that any global variables that you use from both are handled in a safe way. Depending on your application, you may have to use the critical_region_enter()/_exit() functionality of the softdevice, make sure that your variables are declared volatile or similar.

    Also, the code snippet you have shared seems very strange, and I'd strongly recommend you to reconsider your application structure. Doing a spin loop like this waiting for a global variable isn't any more power effective than a simple nrf_delay_ms() loop.

Related