PDA

View Full Version : quadrature encoder pulse (qep) code for TI TMS320F2812


Christian Christmann
12-13-2004, 04:57 PM
Hi,

I'm looking for some code examples for
the quadrature encoder pulse (QEP) unit for
the Texas Instruments TMS320F2812 dsp.

Can anyone send me some examples or post
just an url.

Thanks
Chris

Jack Klein
12-14-2004, 03:39 AM
On Mon, 13 Dec 2004 17:57:33 +0100, Christian Christmann
<[email protected]> wrote in comp.dsp:

> Hi,
>
> I'm looking for some code examples for
> the quadrature encoder pulse (QEP) unit for
> the Texas Instruments TMS320F2812 dsp.
>
> Can anyone send me some examples or post
> just an url.
>
> Thanks
> Chris

I'm using four quadrature decoders on a 2812 based board, two provided
in the DSP event managers, and two more in a CPLD mapped into external
memory space. What is it exactly you want to know about them?

Here's the initialization code watch out for line breaks:

EvaRegs.CAPCON.all = 0x8000U;
EvbRegs.CAPCONB.all = 0x8000U;

EvaRegs.T2CON.all = FREE_RUN_FLAG | /* free run on
emulation stop */
TIMER_DIR_UPDN | /* continuous
up/down counting */
TIMER_CLK_PRESCALE_X_1 | /* clock
prescale x1 */
TIMER_ENABLE_BY_OWN | /* use own
timer */
TIMER_ENABLE | /* enable
timer */
TIMER_CLOCK_SRC_QEP | /* use QEP as
clock source */
TIMER_COMPARE_LD_ON_ZERO; /* load
compare on zero */

EvbRegs.T4CON.all = FREE_RUN_FLAG | /* free run on
emulation stop */
TIMER_DIR_UPDN | /* continuous
up/down counting */
TIMER_CLK_PRESCALE_X_1 | /* clock
prescale x1 */
TIMER_ENABLE_BY_OWN | /* use own
timer */
TIMER_ENABLE | /* enable
timer */
TIMER_CLOCK_SRC_QEP | /* use QEP as
clock source */
TIMER_COMPARE_LD_ON_ZERO; /* load
compare on zero */

EvaRegs.T2PR = 0xffffU;
EvbRegs.T4PR = 0xffffU;

The macros are bit flags we defined equivalent to the bit-fields
defined in the TI DSP28_Ev.h header, so the entire register can be
written in a single operation.

As for keeping track of positions, each hardware encoder is read every
50 microseconds during the 20 KHz PWM interrupt. The real issue is
the fact that the hardware encoder counters, both those in the DSP and
in my CPLD, are 16 bits, and I need to use 32 bits to track the full
range of positions in encoder counts. This takes some extra code.

Email me if you would like more information.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

zimi
05-07-2005, 05:16 PM
Hi

did you have now a code example
I want to use the F2812 with QEP (32-bit). I try it with the Librar
DMCDRV but only the interrupt CAPINT3 works correctly

Thank
Stefa