QDEC for EC11 in SDK17

Hello,

nRF52840, SDK17.2, keil5, EC11 codec button

  

void MY_QDEC_INTERRUPT(nrfx_qdec_event_t event)
{
	static uint8_t flag=0;;
	static int cnt = 0;
	if(NRF_QDEC_EVENT_REPORTRDY  == event.type)
	{
		nrfx_qdec_disable();
 
		//int8_t  dat = nrf_qdec_sample_get();
		int16_t p_acc = event.data.report.acc;
		uint16_t p_accdbl = event.data.report.accdbl;

		nrfx_qdec_enable();
		
		if(0==p_accdbl)
		{
			if(p_acc<0)
				cnt++;
			else 
				cnt--;
		}
		NRF_LOG_INFO("cnt=%2d  acc=%2d  accdbl=%2d",cnt,p_acc,p_accdbl);
	}	
}

void QDEC_INIT(void)
{
	nrfx_qdec_config_t p_config;
	p_config.dbfen = true;
	p_config.interrupt_priority = 3; 
	p_config.ledpol = NRF_QDEC_LEPOL_ACTIVE_LOW ;//QDEC LED active on output pin low.
	p_config.ledpre = 0; //Time (in microseconds) how long LED is switched on before sampling
	p_config.psela = 39; //A pin
	p_config.pselb = 35; //B pin
	p_config.pselled = 0xffffffff; //no led
	p_config.reportper = NRF_QDEC_REPORTPER_80 ;
	p_config.sampleper = NRF_QDEC_SAMPLEPER_2048us; 
	p_config.sample_inten = 0;
	
	nrfx_qdec_init(&p_config,MY_QDEC_INTERRUPT); 
	
	nrfx_qdec_enable();
}

Output the same log in the positive and negative directions,

Turn one space:   <info> app: cnt=-1  acc=1  accdbl=0

Turn one more:    <info> app: cnt=0  acc=-1  accdbl=0

Unable to distinguish positive and negative directions.

   

Best regards

Related