Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

How to read frequency of pulse signal in GPIO pin?

I have a custom board using nRF52832, s132 softdevice and nRF5 SDK. I would like to add a new circuit on my board, that will contain a 555 timer which gives as output signal a pulse stream. The aim is to measure the frequency of the pulse. If I have undrestood correctly this is possible if I connect this output pin to a GPIO digital pin, and using PPI, GPIOTE or timer I will be able to measure the incoming frequency. My questions are:
1. What is the best way to measure the frequency of the signal? Is there any code I could use as a guide/example to help me develop this?
2. I have read in the forum that high frequency signals might cause interference in the radio signal of BLE. Is this true for all digital GPIO pins? and what exactly will be the consequences to the radio signal?

Thank you in advance. Any suggestions or alternatives are welcomed.

Parents Reply Children
  • 8Mhz = 8,000,000Hz, 2.4GHz = 2,400,000,000Hz, so GPIO won't damage any BLE transmission.

    Although I'm developing in nRF Connect SDK, and the last time I dealt with nRF5 was a few years ago, here is the general flow:

    #include "nrf_gpio.h"
    #include "nrf_delay.h"
    
    #define YOUR_GPIO_PIN 13 // Replace with your specific GPIO pin number
    
    #define FREQUENCY_TO_DELAY(f)   ((1000 / (f)) / 2)
    
    void gpio_init(void) {
        nrf_gpio_cfg_input(YOUR_GPIO_PIN, NRF_GPIO_PIN_PULLUP);
    }
    
    uint32_t gpio_status;
    
    void read_gpio_status(void) {
        gpio_status = nrf_gpio_pin_read(YOUR_GPIO_PIN);
        // Now, gpio_status contains the status (0 or 1) of the GPIO pin.
    }
    
    int main(void) {
        gpio_init();
    
        while (1) {
            read_gpio_status();
            nrf_delay_ms(FREQUENCY_TO_DELAY(f));   //Replace f with your desired sampling frequency - if you have higer sampling frequency than 1kHz, multiply this macro by 1000 and use nrf_delay_us function instead)
        }
    }

    More info and a good tutorial about the topic with nRF5: 

    www.youtube.com/watch

Related