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

Time delay

Hi nRF support team,

What do I need to do if I want to use the precise delay of NS, now the delay error is very large.

thanks

Parents
  • Hi 

    You get the most accurate timing by running a TIMER peripheral with prescaler 0. Then you get a timer frequency of 16MHz, which equals an interval of 62.5ns. 

    What kind of accuracy do you need?

    If you are triggering a measurement from the software keep in mind that your code might be interrupted by other parts of the system. 

    If you want to measure hardware events you can use the PPI controller to connect the hardware events to the timer directly, which ensures much more consistent timing.

    Best regards
    Torbjørn

  • Hi,Torbjørn

    Thank you for your reply

    I need the software to measure, and the delay accuracy is around 1us. Do you have the peripheral example of Timer? I am a novice, and I don't know how to configure it

    thanks

  • Hi

    Torbjørn

    Here's my code:

    Since I was using NCS 1.6.0, I replaced it with irq_lock(). Through the for (I = 0; i<200; I++) to flip the IO port, but the waveform seen with the oscilloscope is unstable. If only irq_lock() is executed and irq_unlock() is not executed, then the waveform is normal. The next two videos are my waveforms.

    May I ask what causes this? Looking forward to your reply

    Thank you very much

  • Hi 

    A couple of thoughts: 

    1) Are you running any radio protocol (like Bluetooth) in the background?

    The timing shift you see on the scope might be caused by the external 32MHz clock being enabled and disabled by some other module in your code. 

    The internal high frequency clock can have a frequency drift of 5% and more, and if you switch between that and the external clock you can see this type of shift. 

    The solution to this problem is to request the 32MHz clock to be running all the time. 

    2) Is your end goal to toggle a pin at a specific frequency?

    If so I would strongly recommend using the PWM module, or a combination of the TIMER, PPI, and GPIOTE modules. Then you can have the pin toggled automatically, without having to bit bang everything. 

    Best regards
    Torbjørn

  • Hi,Torbjørn

    Thank you for your reply

    1.What do I need to do to keep 32M on when I send data? Is there this API function? Because of the need for low power consumption, I can't always turn it on. Only turn it on before sending data, and turn it off after sending data, ok?

    2. Since the code segment controlling IO is not periodic, I cannot use PWM.

  • Hi 

    1. You could have a look at the clocks_start(..) function from the ESB example:
    https://github.com/nrfconnect/sdk-nrf/blob/master/samples/esb/ptx/src/main.c#L58

    2. Do you happen to have a description of how the IO pulses are generated?
    The PWM module is quite flexible, and can be configured in a way where both the duty cycle and frequency can change dynamically, so it is possible that there is a way to do this using PWM. 

    Best regards
    Torbjørn

  • Hi,Torbjørn

    Thank you for your reply

    1.I tested the clock at 32M and the exception did not improve.

    2.Is there such a variable cycle PWM driver routine?

     Looking forward to your reply

Reply Children
Related