Frequency counter on NRF52805

Hi, I want to use an NRF52805 with a voltage to frequency detector. If I understand the datasheet, there is one timer/counter and RTC on that chip. Is it possible to set the RTC as the timing gate, and  use the T/C as an input pulse counter through the event system? I'm planning to use a single clock source (prob. 32MHz) and synthesize the LF clock required for the RTC from it.

I will be happy to know if this is a good way to go before fully adopting the hardware.

Cheers,

Parents Reply Children
  • Excellent suggestion! I didn't understand that by default the crystal source might be unused..

    OK, I *think* I sorted this out. I was using a previous example:

    	NRF_CLOCK->TASKS_HFCLKSTART = 1; //Start high frequency clock
    	while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    	{
    		//Wait for HFCLK to start
    	}
    	NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; //Clear event

    and assumed that this will force start the crystal clock. For some reason it doesn't. Online I saw that is NRF51 this was recommended to do with sd_clock_hfclk_request();

    ***annoyingly*** the nRF connect SDK API is different and ***undocumented***. Neither are examples nor explanations in the API that does exist what the sd request has turned into.

    What did it for me is putting in my main() function (after BT and uart service have started) the following:

    mpsl_clock_hfclk_request(&hfclk_started_callback);
    	uint32_t is_running = 0;
    	while (is_running==0){
    	mpsl_clock_hfclk_is_running(&is_running);
    	}

    This requires a definition of cb function (I put it before main())

    void hfclk_started_callback(){
    
    }

    I then used an Arduino configured as a clock source (WITH A RESISTIVE DIVIDER! IT'S WORKING AT 5V, DONT BURN YOUR INPUT PIN!) as follows (this is the Arduino code):

    const int freqOutputPin = 9;   // OC1A output pin for ATmega32u4 (Arduino Micro)
    const int ocr1aval  = 7; 
    
    void setup()
    {
        pinMode(freqOutputPin, OUTPUT);
        
        TCCR1A = ( (1 << COM1A0));
       
        TCCR1B = ((1 << WGM12) | (1 << CS10));
    
        TIMSK1 = 0;
        
        OCR1A = ocr1aval;    
    }
    
    void loop()
    {
       
    }

    Results over 400 samples with 1MHz clock input

    Before requesting HF clock: Average Frequency 997968.1Hz, STDEV=277.6Hz (ppm)

    After requesting HF clock: Average Frequency 999351.7Hz, STDEV=0.45Hz (ppm)

    FYI

    Cheers,

Related