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
  • Could you try to enable this errata workaround, just to see if the two signals are triggered, at some point, very close together?

    http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev2.errata/dita/errata/nRF52832/Rev2/latest/anomaly_832_155.html?cp=2_1_1_0_1_41

     

    Best regards,

    Håkon

  • Yes, i tried, i use construction from errata with in GPIOTE initialising. if GPIOTE_CH_USED is pin number like 4 or 5, i made it write. But it has no effect.

  • It is not the pin used, but the GPIOTE->IN[] instance used. If there are no other IN channels in use, then this is 0 and 1.

  • 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.

Related