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

High frequency clock output from PCA10040

Hello,

I am using the PCA10040 DK, and I want to get a 8 MHz OR 4 MHz clock output from one of the GPIOs.

I've followed the instructions from here

and it works.. however I do not understand what is going on because I am new to this, and such low level stuff is not very helpful, especially when you don't know what is goingon.. so I tried implementing the same thing using the GPIOTE, TIMER and PPI drivers to get the following code:

/* create GPIOTE task */
 nrf_drv_gpiote_pin_t XCLK_PIN = 28;
 nrf_drv_gpiote_out_config_t XCLK_GPIO_CONFIG = GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);

 err_code = nrf_drv_gpiote_init();
 APP_ERROR_CHECK(err_code);

 err_code = nrf_drv_gpiote_out_init(XCLK_PIN,&XCLK_GPIO_CONFIG);
 APP_ERROR_CHECK(err_code);

 nrf_drv_gpiote_out_task_enable(XCLK_PIN);

 uint32_t XCLK_task_add = nrf_drv_gpiote_out_task_addr_get(XCLK_PIN);

 /* create timer event */
 nrf_drv_timer_t XCLK_TIMER = NRF_DRV_TIMER_INSTANCE(0);
 nrf_drv_timer_config_t XCLK_TIMER_CONFIG = NRF_DRV_TIMER_DEFAULT_CONFIG;
 err_code = nrf_drv_timer_init(&XCLK_TIMER,&XCLK_TIMER_CONFIG,XCLK_TIMER_HANDLER);
 APP_ERROR_CHECK(err_code);

 nrf_drv_timer_enable(&XCLK_TIMER);

 uint32_t XCLK_event_add = nrf_drv_timer_event_address_get(&XCLK_TIMER,NRF_TIMER_EVENT_COMPARE0);

 /*create ppi between gpiote and timer*/
 err_code = nrf_drv_ppi_init();
 APP_ERROR_CHECK(err_code);

 nrf_ppi_channel_t XCLK_CHANNEL;
 err_code = nrf_drv_ppi_channel_alloc(&XCLK_CHANNEL);
 APP_ERROR_CHECK(err_code);

 err_code = nrf_drv_ppi_channel_assign(XCLK_CHANNEL,XCLK_event_add, XCLK_task_add);
 APP_ERROR_CHECK(err_code);

 err_code = nrf_drv_ppi_channel_enable(XCLK_CHANNEL);
 APP_ERROR_CHECK(err_code);

But I am not getting anything close to 4MHz. I tried playing around with the nrf_drv_timer_config_t values through the CMSIS wizard, but was only able to bring it up to approximately 33 KHz.

I would appreciate some help in udnerstanding what I did wrong

Thank you!

Parents
  • So, with PPI you can connect an event from one peripheral to trigger a task of another peripheral, for instance a compare0 event from a timer to toggle a pin controlled by the GPIOTE peripheral.

    In your case it seems that you are trying to do the same as found in:
    \nRF5_SDK_15.3.0_59ac345\examples\peripheral\gpiote

    Have you tried that example?

    Best regards,
    Kenneth

  • Hi Kenneth,

    Thank you for your response. The code you suggested differs from mine by only the following line:

         nrf_drv_timer_extended_compare(&XCLK_TIMER, (nrf_timer_cc_channel_t)0, 1UL, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);

    However, I do not understand what this does. Would you be able to guide me towards something that may explain this to me?

    I appreciate your time.

    Best Regards,

    Kasra

Reply
  • Hi Kenneth,

    Thank you for your response. The code you suggested differs from mine by only the following line:

         nrf_drv_timer_extended_compare(&XCLK_TIMER, (nrf_timer_cc_channel_t)0, 1UL, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);

    However, I do not understand what this does. Would you be able to guide me towards something that may explain this to me?

    I appreciate your time.

    Best Regards,

    Kasra

Children
Related