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

Reset timer with high frequency without generating NRF_ERROR_NO_MEM error

Hello!

I'm currently implementing Modbus RTU into my nRF52832 to enable the CPU to communicate with other Modbus RTU capable devices.

When communicating via Modbus RTU it's necessary to detect if the transmission of data from the other device to mine has been completed.

To do this there is a timeout timer which resets after every character received.

With a baudrate of 19200 and 11 bits per character a new character is being received just about every 572 microseconds.

With a maximum baudrate (defined by our other modbus capable device the nRF52832 should talk to) of 115200 this value goes down to 95 microseconds.

Naturally, this seems to be way too fast for the app_timer module to stop and restart a timer, the timer action queue fills up and after receiving a bunch of data I always and up with a NRF_ERROR_NO_MEM error.

How would you suggest that I should implement such a quickly resetting timer?

I'm currently using the app_timer module and the following lines of code are how I reset the timer

APP_ERROR_CHECK(app_timer_stop(timer_t35));
APP_ERROR_CHECK(app_timer_start(timer_t35, APP_TIMER_TICKS(T35_FOR_19200_MS), NULL));

Thanks for taking the time!

Michael 

Parents
  • Hi Michael,

    As you write, you get NRF_ERROR_NO_MEM when the app_timer queue is full because events are added faster than they are processed.

    How would you suggest that I should implement such a quickly resetting timer?

    If you just need one fast and simple timer, then using a TIMER peripheral (assuming you have one available and current consumption is not an issue when it is in use) directly, is probably more appropriate. You can easily generate interrupts for any value by setting the CC register(s) appropriately, and you can reset the timer by a single register write. You can refer to the Timer example to see how the timer driver can be used.

    Einar

Reply
  • Hi Michael,

    As you write, you get NRF_ERROR_NO_MEM when the app_timer queue is full because events are added faster than they are processed.

    How would you suggest that I should implement such a quickly resetting timer?

    If you just need one fast and simple timer, then using a TIMER peripheral (assuming you have one available and current consumption is not an issue when it is in use) directly, is probably more appropriate. You can easily generate interrupts for any value by setting the CC register(s) appropriately, and you can reset the timer by a single register write. You can refer to the Timer example to see how the timer driver can be used.

    Einar

Children
No Data
Related