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

Clock frequency

Hi everyone

I am working with nRF52 (SD132). I am considering the ble_app_uart example and I'm trying to modify it by setting TIMER1 and TIMER2 peripherals to generate 2 different clocks HFCLK (6250 Hz) and LFCLK (1 Hz) so that they can be altered on-the-fly, allowing the user to change the clock frequencies using UART.

How could I do?

Thanks for your future answers.

Here what I wrote to set TIMER 1 and 2 peripherals:

/* TIMERS INITIALISATION **/

static void timers_init(void) { APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);

nrf_gpiote_task_configure(HFCLK_OUT_GPIOTE_CHAN, HFCLK_OUT, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);

nrf_gpiote_task_configure(LFCLK_OUT_GPIOTE_CHAN, LFCLK_OUT, NRF_GPIOTE_POLARITY_TOGGLE, NRF_GPIOTE_INITIAL_VALUE_LOW);

/* TIMER1 - HFCLK **/

NRF_TIMER1->TASKS_CLEAR = 1;

NRF_TIMER1->PRESCALER = HFCLK_TIMER_PRESCALER; 

NRF_TIMER1->CC[0] = (uint32_t)((1/(float)(2HFCLK_OUT_FREQ)) (XTAL_FREQ >> HFCLK_TIMER_PRESCALER)); 

NRF_TIMER1->MODE = TIMER_MODE_MODE_Timer; 

NRF_TIMER1->BITMODE = TIMER_BITMODE_BITMODE_16Bit; 

NRF_TIMER1->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos); 

NRF_PPI->CH[HFCLK_OUT_PPI_CHAN].EEP = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[0]; 

NRF_PPI->CH[HFCLK_OUT_PPI_CHAN].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[HFCLK_OUT_GPIOTE_CHAN];

/* TIMER2 - LFCLK **/

SIMILAR CONFIGURATION OF THE TIMER1

/**/

// Enable PPI channels 

NRF_PPI->CHEN = (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos) | (PPI_CHEN_CH1_Enabled << PPI_CHEN_CH1_Pos);

NRF_TIMER1->TASKS_START = 1;

NRF_TIMER2->TASKS_START = 1;

}
Related