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

Writing to Timer1 EVENTS_COMPARE register doesn't seem to work

The nRF52810 datasheet shows the EVENTS_COMPARE register as RW, so I'm assuming that I can write to it.

But when I write to it, nothing happens.

Example.

I set up the timer to generate an event at 10 seconds and use a While statement to wait.

while (NRF_TIMER1->EVENTS_COMPARE[TMRCC1] == false);

During this 10 seconds, I wait for an interrupt from an incoming ESB packet.

In the ESB handler, I write to the EVENTS_COMPARE register so that when the handler is done,

the program doesn't have to finish waiting for the remainder of the 10 seconds.

NRF_TIMER1->EVENTS_COMPARE[TMRCC1] = true;

However, this doesn't do anything as the program still waits until the 10 seconds is done.

Any tips would be greatly appreciated.

  • Hello,

    So you are not using the NRF_TIMER1 itself to trigger the capture compare?

    Are you sure that you get the event on the ESB?

    Wouldn't it be easier to use an app_timer to do this? I believe so, but you may have some reason to not use that.

    Have you set the INTENSET register? I don't know whether this solves anything, but according to the spec, you can't generate a Compare event by writing to the register manually. Reading from infocenter's section about TIMER:

    "A COMPARE event is generated when the Counter is incremented and then becomes equal to the value specified in one of the capture compare registers"

    I suggest that you use a volatile variable in the ESB handler, and check:

    esb_handler()
    {
        esb_triggered = true;
    }
    
    while ((NRF_TIMER1->EVENTS_COMPARE[TMRCC1] == false) || !esb_triggered));

    BR,

    Edvin

  • That being said, it is very little power efficient to wait in a while loop like this. It will prevent the CPU from going to sleep. I'd suggest that you rather use the interrupts to do things, instead of waiting for interrupts to occur.

  • To be more specific about the application, this 10s wait period is only done upon first powering up the device. It allows a 10s window to perform some configuration operations. So, low power is not important during this period.

    It sounds like the EVENTS_COMPARE flag is only allowed to be generated by the CPU and not by a write to the register?

  • It may be. However, I believe using the app_timer is more suited for this. If you use app_timer_start() to start the 10 second timer, and then app_timer_stop() inside the esb event, then you can do pretty much the same. 

    It may be due to some optimization issues. You can try to disable this, but again, I suggest that you set a volatile variable in the ESB event, and add this to your check. 

    pseudo code:

    volatile bool check_configuration = false;
    
    esb_callback()
    {
        handle_callback();
        check_configuration = true;
    }
    
    main()
    {
        ESB_Setup();
        TIMER1_setup();
        TIMER1_Start();
        while ((NRF_TIMER1->EVENTS_COMPARE[TMRCC1] == false) && (check_configuration == false));
        // Continue ...
        do_stuff();
    }

  • This works. Thanks for the help. I would have never thought to try this.

Related