I have checked the qDEC example, I don't know what it is doing, so I can directly say what I need. I connected a Hall sensor to two pins of 52840, and configured QDEC. I set the sampling rate to 128us, and turned off the sampling report interruption, because the report is interrupted with the minimum of 10 samples. Means it will break after 1.28ms, so I'm going to poll the ACC register directly to read the pulse count in the main loop, configured as follows:
void qdec_init(void)
{
nrfx_qdec_config_t p_config;
p_config.dbfen = true;
p_config.interrupt_priority = 2;
p_config.ledpol = NRF_QDEC_LEPOL_ACTIVE_LOW ;
p_config.ledpre = 0;
p_config.psela = 0x27;
p_config.pselb = 0x26;
p_config.pselled = 0xffffffff;
p_config.reportper = NRF_QDEC_REPORTPER_DISABLED ;
p_config.sampleper = NRF_QDEC_SAMPLEPER_128us;
p_config.sample_inten = false;
ret_code_t err_code = nrfx_qdec_init(&p_config,NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_qdec_enable();//
}
I read the ACC register at 1ms in main() :
nrfx_qdec_disable();
R1_Handle->Encoder.Acc = (float)nrf_qdec_acc_get();
R1_Handle->Encoder.Accdbl = (float)nrf_qdec_accdbl_get();
nrfx_qdec_enable();
My Hall has 24 pulses in a lap, after QDEC I get 48 pulses in a lap, and it shows fine in the ACC register.
So my question: is it necessary to call nrfx_qdec_disable before reading ACC register? Because if I hadn't called nrfx_qdec_disable , the acc value wouldn't have changed. Or can you provide the correct practice for polling acc register values exactly?
I am mainly used for speed measurement, do you have a better way to help me complete this design? I expect to send the resulting speed through the UART at 1khz. thank you