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

Shouldn't this function below output 2us Pulses, instead of outing 3us!

Hello

I am using nRF52 DK, I am trying to use PIN 30 as Pulse train. The following while loop is expected to send out Pulse train of 2microseconds period but instead, it is giving me 3-microsecond pulse width. which is weird or what is that I am missing here?

while(true)
{
//__WFE();
nrf_drv_gpiote_out_set(PIN_OUT_1);
nrf_delay_us(1);
nrf_drv_gpiote_out_clear(PIN_OUT_1);
nrf_delay_us(1);
}
}

SIgnal as on oscilloscope 

Seconds/Divison = 1us. 

Parents
  • You're missing execution delays, the nrf_delay_us() function is not entirely accurate, probably the least accurate at its lowest input value. It's implemented as assembly 'No Operation' instructions.

    Also the gpio functions has CPU execution time as well as the time-delay it takes to change the state of the pin. 

    If you want an accurate pwm signal you need to use TIMER+ PPI +GPIOTE. See the PPI example for details. 

      

  • I got your point, I noticed that GPIO is giving me an approximate pulse when in milliseconds. Would you mind to tell me what is the accuracy for PWM generated through TIMER+PPI+GPIOTE? So that I could decide whether to go for a seperate time to digital converter or use nRF52832 peripherals. and thanks for that response.

  • The TIMER, PPI, and GPIOTE peripherals operates on a 16MHz clock, that means that the PPI will trigger a GPIOTE task based on a TIMER event one 16MHz clock cycle later (62.5ns), and I believe the GPIOTE peripheral uses one clock cycle to change a pin state. 

    In short, you should se a 125ns delay from a TIMER event to a GPIOTE pin change. Do note that any loading of the pin will change the slew rate. 

    You can also use the RTC — Real-time counter instead of the TIMER, but your time resolution will be 1/32.768kHz = 30.51µs instead of 62.5ns.



    Alternatively you can use the PWM — Pulse width modulation peripheral.

Reply Children
No Data
Related