While trying to implement a simple qdec demo application, I find that QDEC_SAMPLEPER_SAMPLEPER_512us above works ok, yet QDEC_SAMPLEPER_SAMPLEPER_256us does not work at all - qdec_event_handler is not called not even once.
Any suggestions?
I am based on the qdec example, only connected to an Arduino board for psela and pselb signal generation, instead of the software qenc simulation.
#define NRF_DRV_QDEC_DEFAULT_CONFIG \
{ \
.reportper = QDEC_CONFIG_REPORTPER, \
.sampleper = QDEC_CONFIG_SAMPLEPER, \
.psela = QDEC_CONFIG_PIO_A, \
.pselb = QDEC_CONFIG_PIO_B, \
.pselled = QDEC_CONFIG_PIO_LED, \
.ledpre = QDEC_CONFIG_LEDPRE, \
.ledpol = QDEC_CONFIG_LEDPOL, \
.interrupt_priority = QDEC_CONFIG_IRQ_PRIORITY, \
.dbfen = QDEC_CONFIG_DBFEN, \
.sample_inten = QDEC_CONFIG_SAMPLE_INTEN \
}
static void qdec_event_handler(nrf_drv_qdec_event_t event)
{
nrf_drv_timer_disable(&TIMER_QDEC);
if (event.type == NRF_QDEC_EVENT_REPORTRDY)
{
m_accdblread = event.data.report.accdbl;
m_accread = event.data.report.acc;
}
nrf_drv_timer_enable(&TIMER_QDEC);
}
void timer_qencOFF_event_handler(nrf_timer_event_t event_type, void* p_context)
{
nrf_drv_timer_disable(&TIMER_QDEC);
switch(event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
.....
break;
default:
//Do nothing.
break;
}
nrf_drv_timer_enable(&TIMER_QDEC);
}
int main(void)
{
m_iteration = 0;
uint32_t err_code;
bool forever = true;
// Initialize UART
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_ENABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud115200
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
// Initialize hardware
err_code = nrf_drv_qdec_init(NULL, qdec_event_handler);
APP_ERROR_CHECK(err_code);
printf("\nQDEC testing started\n");
uint32_t time_ms = 555; //Time(in miliseconds) between consecutive compare events.
uint32_t time_ticks;
//Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
err_code = nrf_drv_timer_init(&TIMER_QDEC, NULL, timer_qencOFF_event_handler);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_QDEC, time_ms);
nrf_drv_timer_extended_compare(
&TIMER_QDEC, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_QDEC);
while (forever)
{
nrf_drv_qdec_enable(); // start burst sampling clock, clock will be stopped by REPORTRDY event
while (! m_report_ready_flag) // wait for a report
{
__WFE();
}
m_report_ready_flag = false;
}
return -1; // this should never happen
}