I am working on nRF52840 Preview DK. I want to generate a square wave with accuracy of ON and OFF time = 1 microsecond using timer for driving stepper motor DRB8825.
I am using SDK version : nRF5_SDK_14.2.0_17b948a
I have performed below set of experiments,
Exp 1. Configure timer to generate interrupt after every 1us and toggle port pin p0.13 in interrupt service routine.
Observations : Port pin is toggled after every 3us instead of 1us with jitter (varying ON and OFF time).
Question : Why interrupt handler is called after 3us instead of 1us? How to remove the jitter.
Exp 2. Integrate timer in ble_app_uart (softdevice version used : s140_nrf52840_5.0.0-2.alpha), configure timer to generate interrupt after every 1us and toggle port pin p0.13 in interrupt service routine.
Observations : Port pin is toggled after every 16us instead of 1us with increase in jitter.
Question : Why the interrupt handler is called after 16us instead of 1us? why ISR calling time is increased as compared to Exp 2 after integrating bluetooth? Why jitter is increased?
Exp 3. Integrate timer in ble_app_uart. Generate square wave of 1us ON and OFF time using GPIOTE, timer3 and PPI on port pin p0.13 and toggle port pin p0.14 in interrupt service routine of timer3.
Observations : p0.13 is toggled after every 1us accurately with no jitter using PPI module of the controller, p0.14 is toggled after every 16us with jitter.
Exp 4. Integrate timer in ble_app_uart. Generate square wave of 50us ON and OFF time using GPIOTE, timer3 and PPI on port pin p0.13 and toggle port pin p0.14 in timer3 interrupt service routine.
Observations : p0.13 is toggled after every 50us accurately with no jitter, p0.14 is toggled after every 50us with jitter.
Question : p0.13 and p0.14 should be toggled at the same time as they are based on same timer3, why ther is jitter in toggling p0.14
Exp 5. Integrate timer in ble_app_uart. Generate square wave of 10us ON and OFF time using GPIOTE, timer3 and PPI on port pin p0.13. Stop generating square wave after 4 cycles by disabling timer, ppi and gpiote in timer3 interrupt service routine.
Observations : p0.13 is toggled after every 10us accurately with no jitter, but it takes some time after 4 cycles to stop generating waveform.
Question : How to stop generating waveform exactly after 4 cycles.
I have to generate accurate time period of square wave(lets say 1us) & predefined number of cycles(lets say 8 pulses) for controlling motor. However, I am not able to control the generation of desired number of square wave pulses with PPI.