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

GPIOTE one input pin to few channels

Hello!

I want meashure pulse time via input capture.

I configured  NRF_P0, NRF_GPIOTE, NRF_PPI and NRF_TIMER1.

	NRF_P0->PIN_CNF[4] = 0x0000000C;
	
	NRF_GPIOTE->CONFIG[0] = 0x00010401;
	NRF_GPIOTE->CONFIG[1] = 0x00020401;
	
	NRF_GPIOTE->INTENSET = 3;
	
	NRF_GPIOTE->EVENTS_IN[0] = 1;
	NRF_GPIOTE->EVENTS_IN[1] = 1;
	
	NRF_PPI->CH[0].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[0];
	NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TIMER1->TASKS_CAPTURE[0];
	
	NRF_PPI->CH[1].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[1];
	NRF_PPI->CH[1].TEP = (uint32_t)&NRF_TIMER1->TASKS_CAPTURE[1];
	
	NRF_PPI->CHENSET = 3;
	
	uint32_t err_code;
	NRF_TIMER1->TASKS_STOP = 1;
	
	NRF_TIMER1->MODE = 0;
	
	NRF_TIMER1->BITMODE = 3;
	
	NRF_TIMER1->PRESCALER = 0;
	
	NRF_TIMER1->TASKS_CLEAR = 1;

	NRF_TIMER1->SHORTS = 3;
	
	NRF_TIMER1->CC[0] = 0;
	
	NRF_TIMER1->INTENSET = 0x10000;	

It work fine, but in datasheet I found next text:

Only one GPIOTE channel can be assigned to one physical pin. Failing to do so may result in unpredictable
behavior.

If using two GPIOTE channels with one pin is prohibited, then how should I measure the pulse duration without constantly reconfiguring the input capture?

And is it really impossible to use two GPIOTE lines with one pin?

  • This is nice, just implemented something like this myself. So, let me tell you how I did this using PPI, a PORT event and COUNTER.

    First I configured the GPIO to trigger on both a rising and falling edge using:

    nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);

    To be able to start and stop the counter, at least two PPI channels are to be created with the start-task and the stop-task of the counter respectively connected. However, only the start-channel needs to be enabled initially. When the event occurs, this start-channel needs to be disabled and the stop-channel enabled.

    However, the PPI does not have tasks to enable or disable channels directly. Instead PPI channel groups can be used to enable or disable a PPI channel. Adding the 'start' channel to one channel group and the 'stop' channel to the other now makes it possible to have a channel disable 'itself' by attaching the fork of the channel to the disable task of the channel group.

    The tasks to enable a PPI channel group again I need two additional PPI channels, that are also added to the respective channel groups as illustrated in the final configuration below:

    I hope this gives you inspiration ;-)

  • Were you able to work with the suggested answer below? If so, please accept it as such.

Related