Author Topic: XMEGA QDEC  (Read 2669 times)

0 Members and 1 Guest are viewing this topic.

Offline maurosmartinsTopic starter

  • Regular Contributor
  • *
  • Posts: 62
  • Country: pt
    • Electronics and Embedded systems
XMEGA QDEC
« on: August 27, 2015, 08:49:58 pm »
Hello all,

on my current project I need to use the quadrature decoder (QDEC) present in the XMEGA microcontrollers.

searching the web, I've found the  application note AVR1600 and respective software, with that I've tried to initialize the module as follows:

Code: [Select]
QDEC_Total_Setup( &PORTB,                    /*PORT_t * qPort*/
6,                         /*uint8_t qPin*/
false,                     /*bool invIO*/
0,                         /*uint8_t qEvMux*/
EVSYS_CHMUX_PORTB_PIN6_gc, /*EVSYS_CHMUX_t qPinInput*/
false,                     /*bool useIndex*/
EVSYS_QDIRM_00_gc,         /*EVSYS_QDIRM_t qIndexState*/
&TCC0,                     /*TC0_t * qTimer*/
TC_EVSEL_CH0_gc,           /*TC_EVSEL_t qEventChannel*/
0); /*uint8_t lineCount*/


and then read from the counter as follows:

Code: [Select]
while(1){

PORTA.OUTTGL=PIN0_bm;
delay_ms(500);

printf("Counts %u\r",TCC0.CNT);

}

unfortunately the count numbers is always 0.

I've tried to initialize the registers manually like this :

Code: [Select]
PORTB.DIRCLR = (PIN6_bm | PIN7_bm);
PORTB.PIN6CTRL = PORT_ISC_LEVEL_gc;
PORTB.PIN7CTRL = PORT_ISC_LEVEL_gc;

EVSYS.CH0MUX = EVSYS_CHMUX_PORTB_PIN6_gc;

EVSYS.CH0CTRL = EVSYS_QDIRM_11_gc | EVSYS_QDEN_bm | EVSYS_DIGFILT_1SAMPLE_gc;
TCC0.CTRLD = (TC_EVSEL_CH0_gc | TC_EVACT_QDEC_gc);
TCC0.PER = 7;
TCC0.CTRLA = TC_CLKSEL_DIV1_gc;

with the same results.  :palm:

I'm using PB6 e PB7 on a atxmega128a3u at 32MHz. the encoder signals are ok as can be seen here:



any help would be appreciated!

Thanks in advanced,
Best regards, Mauro.
 

Offline Dago

  • Frequent Contributor
  • **
  • Posts: 659
  • Country: fi
    • Electronics blog about whatever I happen to build!
Re: XMEGA QDEC
« Reply #1 on: August 28, 2015, 11:41:31 am »
Here is a macro I've used on XMegas to setup quadrature decoding:

Code: [Select]
// Macro to setup quadrature decoding by doing following:
// (1) Set pin direction for QDPH0 and QDPH90 as input and enable level sensing
// (2) Select QDPH0 pin as multiplexer input and enable quadrature decoding and digital filtering
// (3) Set quadrature decoding as event action and select Quadtrature event channel as event source
#define SETUP_QUADRATURE( x, ch ) \
x##_PORT.DIRCLR = x##_QDPH0_bm | x##_QDPH90_bm; \
x##_PORT.x##_QDPH0_CTRL = PORT_ISC_LEVEL_gc; \
x##_PORT.x##_QDPH90_CTRL = PORT_ISC_LEVEL_gc; \
EVSYS.CH##ch##MUX = x##_EVSYS_MUX; \
EVSYS.CH##ch##CTRL = EVSYS_QDEN_bm | 1; \
x##_COUNTER.CTRLD = TC_EVACT_QDEC_gc | TC_EVSEL_CH##ch##_gc; \
x##_COUNTER.PER = 0xFFFF; \
x##_COUNTER.CTRLA = TC_CLKSEL_DIV1_gc
Come and check my projects at http://www.dgkelectronics.com ! I also tweet as https://twitter.com/DGKelectronics
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf