Max. measurable GPIO input frequency

Hi all, 

I have to measure the frequency of a PWM signal routed to one of the nRF52840 GPIO pins. 

The signal frequency is ~3MHz. 

The measurement is done with the help of two timers, the code is taken from this thread

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// ------------------------------------------------------------ dependencies ---
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "nrf.h"
#include "boards.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "app_util_platform.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_gpio.h"
#include "nrf_drv_gpiote.h"
#define FREQ_MEASURE_PIN 24
uint32_t time = 1; // timer time in seconds
static void timer_init()
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

As long as the PWM frequency on the GPIO pin is below ~2.66 MHz, the measured value is correct, here some results for different frequencies (generated with a signal generator): 

Input Frequency 1.5MHz: 

Input Frequency 2.5MHz: 

If i increase the frequency to 3 MHz, the measured value is incorrect: 

According to this thread the nRF52 is not able to measure frequencies above 2.66 MHz. Is this true?? 


I have - additional to this problem - another problem with the code: 

I have a button on my PCB, which I am currently using to toggle a LED, here is the code: 

Initialization of the GPIO button input:

Fullscreen
1
2
3
4
nrf_drv_gpiote_in_config_t in_config_toggle_button = NRFX_GPIOTE_CONFIG_IN_SENSE_TOGGLE(true); // Configure a pin to use a GPIO IN or PORT EVENT to detect any change on the pin.
in_config_toggle_button.pull = NRF_GPIO_PIN_PULLUP;
APP_ERROR_CHECK(nrf_drv_gpiote_in_init(BUTTON_1, &in_config_toggle_button, button1_handler)); // Call handler when switch pin toggles
nrf_drv_gpiote_in_event_enable(BUTTON_1, true);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Button callback function:

Fullscreen
1
2
3
4
5
6
7
8
9
static void button1_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) //called when switch toggles
{
UNUSED_VARIABLE(pin);
UNUSED_VARIABLE(action);
button1_state = 1;
#ifdef LED_WHITE_ON
nrf_drv_gpiote_out_toggle(LED_WHITE);
#endif
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

When I initialize and use the button like this WITH the timer code shown above, it does not output the frequency to the console. Instead, only the button's callback function is constantly called (the white LED then flashes constantly). It is as if the counter interrupt from my high frequency signal triggers the button's interrupt. Do I have to delete an interrupt flag in the timer interrupt? 

Thanks for your support.

Best Regards

hypn0