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

about nrf51822 timer1 TASKS_CAPTURE

hello,

void GPIOTE_IRQHandler(void)
{
    volatile NRF_TIMER_Type * p_timer;
    if ((NRF_GPIOTE->EVENTS_IN[0] == 1) && 
        (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))
    {
			  if(nrf_gpio_pin_read(9)==1)
				{
						
								 
						NRF_CLOCK->EVENTS_HFCLKSTARTED  = 0;
						NRF_CLOCK->TASKS_HFCLKSTART     = 1;

					 
						while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) 
						{
								// Do nothing.
						}
						p_timer = NRF_TIMER1;
						
						p_timer->MODE           = TIMER_MODE_MODE_Timer;       
						p_timer->PRESCALER      = 9;                            // Prescaler 9 produces 31250 Hz timer frequency => 1 tick = 32 us.
						p_timer->BITMODE        = TIMER_BITMODE_BITMODE_16Bit;  // 16bit  
						p_timer->TASKS_CLEAR    = 1;                            / 
    
					 
						p_timer->TASKS_START    = 1;                    // Start timer.		
					 					
				}
				else
				{
					  p_timer->TASKS_CAPTURE[0] = 1;;
					  timer_left = p_timer->CC[0];
						//p_timer->EVENTS_COMPARE[0]  = 0;
						p_timer->TASKS_STOP         = 1;                // Stop timer.
					
					 

				}
			
        NRF_GPIOTE->EVENTS_IN[0] = 0;  
				

    }

}

i want to run the timer 1 at rising edge and get the timer value at falling edge. TASKS_CAPTURE[0] :capture Timer value to CC[0] rigister. but,i find the value of CC[0] is 0,WHY?

Parents
  • That should work fine as far as I can tell. Two questions:

    • Is this program branching correctly, i.e. is the button function working so that the TIMER starts at a rising edge?

    • How are you checking the timer_left value? If you are checking the value with setting a breakpoint in debugger mode, make sure that you have compiler optimization level set to 0 in Options for Target -> C/C++ tab. That will enable proper debugging. You can also see register values in KEil by selecting View -> System Viewer -> TIMER while you debug and halt executuion on a breakpoint.

Reply
  • That should work fine as far as I can tell. Two questions:

    • Is this program branching correctly, i.e. is the button function working so that the TIMER starts at a rising edge?

    • How are you checking the timer_left value? If you are checking the value with setting a breakpoint in debugger mode, make sure that you have compiler optimization level set to 0 in Options for Target -> C/C++ tab. That will enable proper debugging. You can also see register values in KEil by selecting View -> System Viewer -> TIMER while you debug and halt executuion on a breakpoint.

Children
No Data
Related