Using Interrupt function NRF52_MBED, how to change clock frequency

Hello ,
I am using the "NRF52_MBED_TimerInterrupt.h" library for interrupts on my Arduino Nano BLE.
How can I change the clock frequency? It seems it is preset to 1Mhz, but I would like to increase it to 16MHz. I tried to change the PRSCALER with:

void initTimer4()

{

NRF_TIMER4->PRESCALER = 0;

}

But it didnt work.

Here is my Code:

#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
  #error This code is designed to run on nRF52-based Nano-33-BLE boards using mbed-RTOS platform! Please check your Tools->Board setting.
#endif

#define TIMER_INTERRUPT_DEBUG         1
#define _TIMERINTERRUPT_LOGLEVEL_     3

#include "NRF52_MBED_TimerInterrupt.h"
#include "hw_config.h"

#define TIMER0_INTERVAL_US        1000   //1000

volatile uint32_t Timer0Count = 0;

void printResult(uint32_t currTime)
{
  Serial.print(F("Time = "));
  Serial.print(currTime);
  Serial.print(F(", Timer0Count = "));
  Serial.println(Timer0Count);
}

void TimerHandler0()
{
  static bool toggle0 = false;

  // Flag for checking to be sure ISR is working as SErial.print is not OK here in ISR
  Timer0Count++;

  //timer interrupt toggles pin LED_BUILTIN
  digitalWrite(CNK_FREQ_OUTPUT, toggle0);
  toggle0 = !toggle0;
}

void initTimer4()
{
  NRF_TIMER4->PRESCALER = 0;
}

NRF52_MBED_Timer ITimer0(NRF_TIMER_4);



void setup() {
    pinMode(CNK_FREQ_OUTPUT, OUTPUT);

    Serial.begin(9600);
  
  initTimer4();

    while (!Serial && millis() < 5000);

  delay(100);

  Serial.print(F("\nStarting Argument_None on "));
  Serial.println(BOARD_NAME);
  Serial.println(NRF52_MBED_TIMER_INTERRUPT_VERSION);
  


  if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_US, TimerHandler0))
  {
    Serial.print(F("Starting ITimer0 OK, millis() = "));
    Serial.println(millis());
  }
  else
    Serial.println(F("Can't set ITimer0. Select another freq. or timer"));
 
}


#define CHECK_INTERVAL_MS     999L
void loop() {
  static uint32_t lastTime = 0;
  static uint32_t currTime;

  currTime = millis();

  if (currTime - lastTime > CHECK_INTERVAL_MS)
  {
    printResult(currTime);
    lastTime = currTime;
  }

Thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.