1Mhz clock on arduino nano 33 ble

Does anyone know how to generate a 1Mhz clock on a data pin of the arduino nano 33 ble. I’ve tried using the digital write function but it is to slow does anyone know of another way such as direct port manipulation.

Welcome to the forum.

You can use a timer and the PPI system to create a signal at an IO pin without any software intervention after the initial configuration.

Here is an example. This is not a beginners tutorial. You will need to read the nRF datasheet if you want to do major modifications. This might also break other functionality that makes use of the timer and ppi channel.

/*
  This example shows how to use a nRF52840 Timer and PPI to create square wave signal at a pin.
  The signal is created by hardware and does not require any software after initialization.
  Note:
  - two samples are needed for a full wave
  - to create 1 MHz the SAMPLES_PER_SECOND need to be 2M
  - check pin diagram in Arduino store for nRF pins and ports
  
  The circuit:
  - Arduino Nano 33 BLE/ BLE Sense board.

  This example code is in the public domain.
*/

#include "mbed.h"

#define SAMPLES_PER_SECOND  (2000000)
#define PPI_CHANNEL_T4      (7)

// Arduino Nano 33 BLE Digital pin D10 P1.02
#define PIN_GPIO_T4         (2)
#define PORT_GPIO_T4        (1)

void setup()
{
  initTimer4();
  initGPIOTE();
  initPPI();
}

void loop()
{
  
}


void initTimer4()
{
  NRF_TIMER4->MODE = TIMER_MODE_MODE_Timer;
  NRF_TIMER4->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
  NRF_TIMER4->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos;
  NRF_TIMER4->PRESCALER = 0;
  NRF_TIMER4->CC[0] = 16000000 / SAMPLES_PER_SECOND; // Needs prescaler set to 0 (1:1) 16MHz clock
  NRF_TIMER4->TASKS_START = 1;
}


void initGPIOTE()
{
  NRF_GPIOTE->CONFIG[0] = ( GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos ) |
                          ( GPIOTE_CONFIG_OUTINIT_Low     << GPIOTE_CONFIG_OUTINIT_Pos ) |
                          ( GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos ) |
                          ( PORT_GPIO_T4                  << GPIOTE_CONFIG_PORT_Pos ) |
                          ( PIN_GPIO_T4                   << GPIOTE_CONFIG_PSEL_Pos );
}


void initPPI()
{
  // Configure PPI channel with connection between TIMER->EVENTS_COMPARE[0] and GPIOTE->TASKS_OUT[0]
  NRF_PPI->CH[PPI_CHANNEL_T4].EEP = ( uint32_t )&NRF_TIMER4->EVENTS_COMPARE[0];
  NRF_PPI->CH[PPI_CHANNEL_T4].TEP = ( uint32_t )&NRF_GPIOTE->TASKS_OUT[0];

  // Enable PPI channel
  NRF_PPI->CHENSET = ( 1UL << PPI_CHANNEL_T4 );
}

Thanks for the quick response. I have one more question, since this is timer based can i still do other things in loop() with little interference from the rest of the code?

Yes, you can do whatever you want. When this is all setup it runs completely in hardware without the processor. I do not believe timer 4 is used by any standard Arduino stuff.
Just add your code to setup and loop as usual.