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

Frequency measurement accuracy

Hello,

I would like to measure the frequency of a signal and I use PPI, a timer and input capture to achieve this.

Here's the configuration :

/** @brief Function for initializing the PPI peripheral.
*/
static void ppi_init(void)
{
    NRF_PPI->CH[0].EEP = (uint32_t)&NRF_GPIOTE->EVENTS_IN[0]; // Put add of the event to EEP register
    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TIMER1->TASKS_CAPTURE[0]; // Put add of the task to TEP register
    NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_TIMER1-> TASKS_CLEAR;// Put add of the task to TEP fork register
    
    NRF_PPI->CHENSET = (uint32_t)(1<<0); //Enable PPI channel0
}

/** @brief Function for initializing the timer1 peripheral.
*/
static void timer1_init (void){

    NRF_TIMER1->MODE = (uint32_t)TIMER_MODE_MODE_Timer<<TIMER_MODE_MODE_Pos; // Timer mode
    NRF_TIMER1->BITMODE = (uint32_t)TIMER_BITMODE_BITMODE_24Bit<<TIMER_BITMODE_BITMODE_Pos; // 32 bits resolution
    NRF_TIMER1->PRESCALER = (uint32_t)0; // Prescaler = 0
}

/**
 * @brief Function for configuring: input PIN, output PIN.
 */
static void gpio_init(void)
{
    /********************************** Configure input for capture **********************************/
   
    NRF_GPIOTE->CONFIG[0] = GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos | 
                                         GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos | 
                                         29 << GPIOTE_CONFIG_PSEL_Pos | 
                                         GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos;
    
    /*************************************************************************************************/
}

The frequency of my signal is stable but the return captured value varies a bit.

<info> app: 176
<info> app: 176
<info> app: 177
<info> app: 175
<info> app: 176
<info> app: 176
<info> app: 176

Is due to the nRF52 timer precision ?
I use the external Xtal so I don't think it his precision

Development conditions

- Segger Embbeded Studio
- SDK 14.2 no softdevice
- Windows 10
- nRF52840-PDK PCA10056 V0.9.3

Parents Reply Children
  • Hi

    And you are sure that the external HF clock is running all the time?

    I just tested this myself and I typically see the result vary between two values (198 and 199 in my case), which is to be expected. Since the external signal will not be synchronized to the clock of the nRF52, you can get slightly different results depending on what the phase of the nRF52 clock is when the external signal triggers. 

    This doesn't fully explain why you see variation between 175, 176 and 177. 

    In either case I would suggest averaging the result over multiple pulses for more accurate results. 

    Best regards
    Torbjørn 

Related