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

Capture then clear timer.

Is there a way to capture and clear a timer without being interrupted. This doesn't seem possible with shortcuts. also it looks like theres no capture event with which to trigger a clear task over ppi only compare events, or are the compare events also capture events (as compare registers also seem to be capture registers). What about an event that triggers both capture and clear tasks over ppi? what event could be used for code to trigger both tasks? what about a multiple store operation in asm (specifically I think the STMDB instruction might work, writing 1 on the capture register then zeros on the other registers, then finally a 1 on the clear register) community.arm.com/.../c-c-atomic-operation-on-arm9-and-arm-cortex-m4

	NRF_TIMER2->TASKS_CAPTURE[3] = 1;
	NRF_TIMER2->TASKS_CLEAR = 1;

can be interrupted?

Parents
  • Hi

    Where there is a will there is a way ;)

    In this case I think the simplest solution is to use one of the EGU units and the PPI to trigger both tasks in the timer at the same time.

    The EGU unit is a very simple peripheral that allow you to generate an internal event by activating a corresponding task (in software or hardware). The internal event can then be connected to the PPI controller, and since each PPI channel has a secondary FORK endpoint you can connect it to two different tasks.

    As an example, in the following code I am using PPI channel 0 to connect EGU0 channel 0 to the capture and clear tasks from your example:

    NRF_PPI->CH[0].EEP = (uint32_t)&NRF_EGU0->EVENTS_TRIGGERED[0];
    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TIMER2->TASKS_CAPTURE[3];
    NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_TIMER2->TASKS_CLEAR;
    NRF_PPI->CHENSET = 1 << 0;
    

    To run the capture and clear operation, simply trigger the task of the EGU like this:

    NRF_EGU0->TASKS_TRIGGER[0] = 1; 
    

    Best regards
    Torbjørn

  • Hi

    I definitely think a free running timer is the way to go.

    To simulate a 64-bit timer you can configure a second timer module in counter mode, and have the first timer trigger the count task over PPI every time it overflows.
    There is no dedicated overflow event, so you would have to use one of the CC registers (and the corresponding COMPARE event) for this. I haven't tested this, but if you set the CC register to 0 the event should fire when the timer overflows.

    To run an atomic capture on both timers you could use a trick similar to the capture/clear method I proposed earlier: Use one of the other task/events in the EGU, and use a PPI channel with the FORK feature to activate two capture tasks at the same time.

    Best regards

Reply
  • Hi

    I definitely think a free running timer is the way to go.

    To simulate a 64-bit timer you can configure a second timer module in counter mode, and have the first timer trigger the count task over PPI every time it overflows.
    There is no dedicated overflow event, so you would have to use one of the CC registers (and the corresponding COMPARE event) for this. I haven't tested this, but if you set the CC register to 0 the event should fire when the timer overflows.

    To run an atomic capture on both timers you could use a trick similar to the capture/clear method I proposed earlier: Use one of the other task/events in the EGU, and use a PPI channel with the FORK feature to activate two capture tasks at the same time.

    Best regards

Children
No Data
Related