Frequency measurement of square wave using NCS

I'm trying to measure the frequency of a square wave signal at the input of a GPIO (its somewhere between ~ 30kHz and 60kHz and will be pretty steady for the duration of my measurement, which should only take a second or two) and then convert this to a DC voltage in the range 0-3.3Vdc, via a PWM signal on an output (via some low pass filtering on my hardware)

I'm using v2.2.0 of NCS and an nRF52832

There is a thread here that gives an overview of how to go about the frequency measurement side of things, an even includes the code that was written to achieve this.  But the code all seems specific to SDK (not sure what version they were using)

I've had a look at the nrfx example that toggles a LED whenever a button is pressed, but its not really cleared up how I go about utilising the GPIOTE and PPI functionality using NCS.

Can anyone give me a bit of guidance as to how I can get going with GPIOTE and PPI with NCS?

Cheers,

Mike

  • Hi Mike

    I made a small example showing how to combine the GPIOTE, PPI and TIMER modules here

    Please note that if you want very accurate measurements you should start and stop the measurements directly from a timer over PPI rather than triggering them from software, but I don't know how accurate readings you need. 

    Best regards
    Torbjørn

  • What have to be done to use interrupts so as to achieve more accuracy? Can you show such a variant of measurement?

  • Hi Ivan

    I don't we have an example showing you exactly how to do this, but you can basically just use the same principles show in the example, but extended a bit further:

    Rather than manually call nrfx_timer_capture(..) in the pulse_count_sample(void) function, you can connect the capture task of the timer to the compare event of some other RTC or TIMER module over PPI. 

    Then you simply configure this other RTC/TIMER to generate an event at regular intervals, which will trigger the capture task of the timer. If you also generate an interrupt from the same event you can read out the capture register in this interrupt. 

    Best regards
    Torbjørn

Related