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
  • 1. Make sure the interval between readings complies with the Nyquist rule - so if your max 555 frequency is 1kHz, you need to have no more than 0.5ms between two readings - but this is a very edgy value. I recommend you sample at the top 0.25ms between samples (for a maximum 1kHz signal).

    2. BLE signals are around 2.4GHz (2.402-2.480 if I remember correctly). GPIO top speed at nRF52832 is 8MHz - so there is no expected interference with BLE. Theoretically, suppose you have GPIO that can communicate in BLE rates. In that case, it will cause interference issues, which might cause you to lose or unwillingly modify values or the packets you send over BLE.

  • Thank you for your response. 

    1. Do you have in mind any example or code that could help me develop this?

    2. What about 10kHz mentioned in this link nrf52, clarification on Low Frequency I/O for input that will probably affect radio? 

  • 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

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

Children
No Data
Related