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

2 Timers as counter with external input capture pin

Hi. I have to make mesuring impulses quantity of two external low freq signals without interrupts.

I tried to use GPIOTE EVENTS_IN[0] and 1 with PPI ch 0 and 1 to timer 2 and 3 TASKS_COUNT generate. it works, but when the event on pins polarity change occure simultaneously one of the timers counts twice. 

How to make it write to be timers counted independently of each other?

Parents Reply Children
  • Ok.I took an experiment using nrf51 pca10001 board. i had the same problem on nrf51, but when i had used errata code ,  nrf51 code starts to work well! no double events.

    void GPIOTE_IRQHandler(void)
    {
    		if(NRF_GPIOTE->EVENTS_IN[0] == 1)
    		{	
    			NRF_GPIOTE->EVENTS_IN[0] = 0;
    			counter1++;
    
    		}
    		if(NRF_GPIOTE->EVENTS_IN[1] == 1)
    		{			
    			NRF_GPIOTE->EVENTS_IN[1] = 0;
    			counter2++;
    		}
    }
    ...
    ...
    ...
    nrf_gpio_cfg_input(0, GPIO_PIN_CNF_PULL_Pullup);
    nrf_gpio_cfg_input(1, GPIO_PIN_CNF_PULL_Pullup);
    
    *(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 0)) = 1;
    *(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 1)) = 1;
    
    NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos |
    												0 << GPIOTE_CONFIG_PSEL_Pos												 |	
    												GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos;
    
    NRF_GPIOTE->CONFIG[1] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos |
    												1 << GPIOTE_CONFIG_PSEL_Pos												 |	
    												GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos;	
    
    NRF_GPIOTE->EVENTS_IN[0] = 0;
    NRF_GPIOTE->EVENTS_IN[1] = 0;
    
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Enabled << GPIOTE_INTENSET_IN0_Pos | 
    											 GPIOTE_INTENSET_IN1_Enabled << GPIOTE_INTENSET_IN1_Pos ; 
    
    NRF_GPIOTE->POWER = 	GPIOTE_POWER_POWER_Enabled << GPIOTE_POWER_POWER_Pos;
    NVIC_EnableIRQ(GPIOTE_IRQn);

    Then i remake code for nrf 52

    void GPIOTE_IRQHandler(void)
    {
    		if(NRF_GPIOTE->EVENTS_IN[0] == 1)
    		{	
    			NRF_GPIOTE->EVENTS_IN[0] = 0;
    			counter1++;
    		}
    		if(NRF_GPIOTE->EVENTS_IN[1] == 1)
    		{			
    			NRF_GPIOTE->EVENTS_IN[1] = 0;
    			counter2++;
    		}
    }
    ...
    ...
    ...
    nrf_gpio_cfg_input(3, GPIO_PIN_CNF_PULL_Pullup);
    nrf_gpio_cfg_input(4, GPIO_PIN_CNF_PULL_Pullup);
    
    *(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 0)) = 1;
    *(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * 1)) = 1;
    
    NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos |
    						3 << GPIOTE_CONFIG_PSEL_Pos												 |	
    						GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos;
    
    NRF_GPIOTE->CONFIG[1] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos |
    						4 << GPIOTE_CONFIG_PSEL_Pos												 |	
    						GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos;	
    
    NRF_GPIOTE->EVENTS_IN[0] = 0;
    NRF_GPIOTE->EVENTS_IN[1] = 0;
    
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Enabled << GPIOTE_INTENSET_IN0_Pos | 
    					   GPIOTE_INTENSET_IN1_Enabled << GPIOTE_INTENSET_IN1_Pos ; 
    
    NVIC_SetPriority(2, GPIOTE_IRQn);
    NVIC_DisableIRQ(GPIOTE_IRQn);

    But for nrf52 it doesnt works, it always has double event for EVENTS_IN[1]

  • oh, i find, one of my relay time-to-time works incorrect.

  • Just to confirm; the source of the issue has been found?

     

    Best regards,

    Håkon

Related