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

nRF52, 1-4 MHz clock needed

I am using the nRF52 Preview board, PCA 10036. I need to provide a high-frequency clock signal to a peripheral. Anything between 1 and 4 MHz will work. However, I don't need and don't want the CPU to receive an interrupt on every clock pulse.

I think that the GPIOTE example in the SDK is relevant to my needs. (I'm using SDK 0.9.2.) However: the code has a function called timer_dummy_handler(). While this function does nothing, the code does connect it to a timer event, with a call to nrf_drv_timer_init(). The documentation for nrf_drv_timer_init() says that an event handler function is a required argument.

The GPIOTE example code has a timer frequency of 200 milliseconds. Calling a quick and useless function five times/second is harmless. Calling that same function 1-4 million times / second would be a nightmare.

Is that function call actually used?

Can I avoid attaching a function call to a timer event, if I program at a lower level?

Parents
  • seems pretty simple - run one of the TIMERs, set the COMPARE to whatever gives you 1-4MHz, enable the short between COMPARE and CLEAR and set up a PPI to toggle a GPIO pin on the COMPARE event. Now you have a 1-4MHz toggling GPIO pin with no CPU involvement, just the power use from the HKCLK running.

  • yeah you don't need the hardware drivers for this - it should be no more than about 20 lines of code to set it up and make it run.

    Break it down. Job #1, configure a TIMER to count at 16MHz (no scaler) and set COMPARE[0], or another COMPARE to '4' for 4MHz or '16' for 1MHz. Enable the SHORTS for COMPARE[0] and CLEAR. That's all chapter 24 of the manual. Now you have a timer which counts at the right rate.

    Next look up GPIOTE, chapter 21. Configure one of those to Task mode, on a pin you select, with polarity == TOGGLE. Each time you trigger GPIOTE->TASKS_OUT[your task number] the pin will toggle. Test that.

    Now hook those two up with PPI, chapter 22. CH[].TEP is the task address, that's the GPIOTE, CH[].EEP is the event, that's the TIMER COMPARE event, set those, enable the channel, now everytime the timer gets to 4, it will clear and trigger, via the PPI, the pin to toggle.

Reply
  • yeah you don't need the hardware drivers for this - it should be no more than about 20 lines of code to set it up and make it run.

    Break it down. Job #1, configure a TIMER to count at 16MHz (no scaler) and set COMPARE[0], or another COMPARE to '4' for 4MHz or '16' for 1MHz. Enable the SHORTS for COMPARE[0] and CLEAR. That's all chapter 24 of the manual. Now you have a timer which counts at the right rate.

    Next look up GPIOTE, chapter 21. Configure one of those to Task mode, on a pin you select, with polarity == TOGGLE. Each time you trigger GPIOTE->TASKS_OUT[your task number] the pin will toggle. Test that.

    Now hook those two up with PPI, chapter 22. CH[].TEP is the task address, that's the GPIOTE, CH[].EEP is the event, that's the TIMER COMPARE event, set those, enable the channel, now everytime the timer gets to 4, it will clear and trigger, via the PPI, the pin to toggle.

Children
No Data
Related