Using 52840, I would like to drive an ADC chip - and it needs to get 800KHz. sampling speed (800/16=50KHz) should be accurate
* a timer isn't an option - not accurate enough
* PWM provides the period in uSec, so 1uSec is 1MHz and 2 is 500KHz - no finer resolution is provided (?) in order to get 800KHz.
* using HFCLK (code below) works fine with an empty main() app, but blocks my application other features
Ideas?
{
NRF_CLOCK->TASKS_HFCLKSTART = 1; // Start high frequency clock
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
{
// Wait for HFCLK to start
}
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; // Clear event
// Configure GPIOTE to toggle pin
NRF_GPIOTE->CONFIG[0] =
GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos |
GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos |
ADC_clk << GPIOTE_CONFIG_PSEL_Pos |
GPIOTE_CONFIG_OUTINIT_Low << GPIOTE_CONFIG_OUTINIT_Pos;
// Configure timer
NRF_TIMER1->PRESCALER = 0;
NRF_TIMER1->CC[0] = 10; // Adjust the output frequency by adjusting the CC.
NRF_TIMER1->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled
<< TIMER_SHORTS_COMPARE0_CLEAR_Pos;
NRF_TIMER1->TASKS_START = 1;
// Configure PPI
NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TIMER1->EVENTS_COMPARE[0];
NRF_PPI->CH[0].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];
NRF_PPI->CHENSET = PPI_CHENSET_CH0_Enabled << PPI_CHENSET_CH0_Pos;
}