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

    What is the prescaler setting of the timer, and how much variation are you seeing on the captured result?

    Since the CPU core is running at a higher frequency than the timer I would expect some variation in this case, but not more than a single count up or down.

    If you allow the timer to run freely, without resetting it for each capture, then you won't get any accumulation of error. You just need to calculate the difference between one capture and the next.

    May I ask what time you are trying to measure?

    Best regards
    Torbjørn

Reply
  • Hi

    What is the prescaler setting of the timer, and how much variation are you seeing on the captured result?

    Since the CPU core is running at a higher frequency than the timer I would expect some variation in this case, but not more than a single count up or down.

    If you allow the timer to run freely, without resetting it for each capture, then you won't get any accumulation of error. You just need to calculate the difference between one capture and the next.

    May I ask what time you are trying to measure?

    Best regards
    Torbjørn

Children
No Data
Related