Hi team !
I'm facing issue when porting my code from nRF52840DK to nRF5340DK
I implemented SAADC acquisition, using Timer/SAADC/(D)PPI stack on both boards, handling the few differences I found (i.e: nrfx_ppi_channel... vs nrfx_dppi_channel... functions, includes, etc).
So I got my code running on both boards, but I still see a huge difference I can't tell where it comes:
As I log some timing values at runtime, I can see how long my firmware takes to do a full loop (ADC acquisition, writing buffer in flash/sending buffer through BLE, depending on the situation).
- With the nRF52840, I have a 100ms loop, as expected. During this time, I take 100 ADC samples from 1 channel, get it in my main() from ADC queue, and handle it.
- With the nRF5340, the same code take 400ms to do a loop, everything else is OK.
The only way I found to fix this delta is to divide by 4 the compare value I set when calling nrfx_timer_compare(), from 1000 (1ms @ 1MHz), to 250 (don't really know what this value means in this situation...).
My question is: why do I have to change this compare value and is it the best way to achieve my goal ?
Thanks in advance for your support.
Guillaume
const nrfx_timer_t m_sample_timer = NRFX_TIMER_INSTANCE(1);
const uint32_t saadc_sampling_rate = 1; // milliseconds (ms)
void timer_init(void)
{
// SAADC timer config
nrfx_timer_config_t timer_config_sample = {
.frequency = NRF_TIMER_FREQ_1MHz,
.mode = NRF_TIMER_MODE_TIMER,
.bit_width = NRF_TIMER_BIT_WIDTH_32,
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY
};
// Hot fix for code compatibility 5340DK vs 52840DK
#ifdef DPPI_PRESENT
int compare_value = 250;
#else
int compare_value = 1000;
#endif
err_code = nrfx_timer_init(&m_sample_timer, &timer_config_sample, timer_handler);
if(err_code != NRFX_SUCCESS) {
printk("Unable to init sampling timer (error %d)", err_code);
}
nrfx_timer_compare(&m_sample_timer,
NRF_TIMER_CC_CHANNEL0,
nrfx_timer_us_to_ticks(&m_sample_timer, saadc_sampling_rate * compare_value),
false);
nrfx_timer_compare(&m_sample_timer,
NRF_TIMER_CC_CHANNEL1,
nrfx_timer_us_to_ticks(&m_sample_timer, saadc_sampling_rate * compare_value * 2),
false);
nrfx_timer_compare(&m_sample_timer,
NRF_TIMER_CC_CHANNEL2,
nrfx_timer_us_to_ticks(&m_sample_timer, saadc_sampling_rate * compare_value * 3),
false);
nrfx_timer_extended_compare(&m_sample_timer,
NRF_TIMER_CC_CHANNEL3,
nrfx_timer_us_to_ticks(&m_sample_timer, saadc_sampling_rate * compare_value * 4),
NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK,
false);
nrfx_timer_resume(&m_sample_timer);
}
Config:
- Windows_NT x64 v10.0.19042
- VSCode v1.65.2
- nRF Connect for VS Code v2022.3.104