qep.h File Reference

Encoder Routines. More...

#include "TIMotorLIB.h"
#include "FilterAndRotations.h"
#include "Utils.h"

Go to the source code of this file.

Data Structures

struct  QEP
 struct used for storing QEP configuration More...

Enumerations

enum  PCRM { PCRM_IE, PCRM_MAX_POS, PCRM_FIE, PCRM_UTE }
 

select position counter reset mode

More...

Functions

void ConfigureQEP1 (void(*interruptFCN)(void), Uint16 qep_us, PCRM pcrm, Uint16 lines, Uint16 polePairs)
void ConfigureQEP2 (void(*interruptFCN)(void), Uint16 qep_us, PCRM pcrm, Uint16 lines, Uint16 polePairs)
void InitEQep1Gpio (void)
 Init GPIO ports as needed for encoder connection QEP1 (GPIO20, GPIO21, GPIO23).
void InitEQep2Gpio (void)
 Init GPIO ports as needed for encoder connection QEP2 (GPIO24, GPIO25, GPIO26).
void SwapDirection (volatile struct QEP *qep)
static void QEP1VelocityAndPosition (void)
static void QEP2VelocityAndPosition (void)
static void QEPVelocityAndPosition (Uint16 newPos, Uint16 oldPos, Uint16 direction, volatile struct QEP *qep)
static void EnableQEP (volatile struct QEP *qep)
static void EnableQEP1 (void)
 Enable QEP1 interface.
static void EnableQEP2 (void)
 Enable QEP2 interface.
static void EqepPIEAck (volatile struct EQEP_REGS *eQEPRegs)
static void Eqep1PIEAck (void)
static void Eqep2PIEAck (void)

Variables

struct QEP qep1
struct QEP qep2

Detailed Description

Encoder Routines.

File Name : qep.h Project : TIMotorLIB

TI Doc: SPRU790

Author:
Pablo Garcia (pgarcia@isa.uniovi.es)
Date:
2007

This unit allows to program the encoder interface and calculates the actual position and velocity optimized for high speed (count units each unit timer interrupt).

Todo:
  • Integrate hall sensor interface
    • Incorporate low speed measurments

Definition in file qep.h.


Enumeration Type Documentation

enum PCRM

select position counter reset mode

Enumerator:
PCRM_IE 

position counter reset on index event

PCRM_MAX_POS 

position counter reset on the maximum position

PCRM_FIE 

position counter reset on the first index event

PCRM_UTE 

position counter reset on a unit time event

Definition at line 69 of file qep.h.


Function Documentation

void ConfigureQEP1 ( void(*)(void)  interruptFCN,
Uint16  qep_us,
PCRM  pcrm,
Uint16  lines,
Uint16  polePairs 
)

Initialize encoder reading (QEP1)

Parameters:
interruptFCN function to be called each qep_us
qep_us unit timer
pcrm position counter reset mode (PCRM_IE/PCRM_MAX_POS/PCRM_FIE/PCRM_UTE)
lines encoder lines
polePairs machine pole pairs

Definition at line 53 of file qep.c.

void ConfigureQEP2 ( void(*)(void)  interruptFCN,
Uint16  qep_us,
PCRM  pcrm,
Uint16  lines,
Uint16  polePairs 
)

Initialize encoder reading (QEP2)

Parameters:
interruptFCN function to be called each qep_us
qep_us unit timer
pcrm position counter reset mode
lines encoder lines
polePairs machine pole pairs

Definition at line 73 of file qep.c.

static void EnableQEP ( volatile struct QEP qep  )  [inline, static]

Enable QEP interface

Parameters:
qep pointer to QEP struct which interface wants to be enabled

Definition at line 294 of file qep.h.

static void EnableQEP1 ( void   )  [inline, static]

Enable QEP1 interface.

Examples:
TIMotorLIBExampleHrdw/main.c, and TIMotorLIBExampleSw/main.c.

Definition at line 301 of file qep.h.

static void EnableQEP2 ( void   )  [inline, static]

Enable QEP2 interface.

Definition at line 308 of file qep.h.

static void Eqep1PIEAck ( void   )  [inline, static]

ACK unit timer interrupt for EQEP1. This function MUST be called if more interrupts from PIEACK_GROUP5 are wanted

Examples:
TIMotorLIBExampleHrdw/main.c, and TIMotorLIBExampleSw/main.c.

Definition at line 327 of file qep.h.

static void Eqep2PIEAck ( void   )  [inline, static]

ACK unit timer interrupt for EQEP2. This function MUST be called if more interrupts from PIEACK_GROUP5 are wanted

Definition at line 334 of file qep.h.

static void EqepPIEAck ( volatile struct EQEP_REGS *  eQEPRegs  )  [inline, static]

ACK interrupts from Unit timer associated to eQEPRegs register

Parameters:
eQEPRegs register register which interrupt is ACK

Definition at line 315 of file qep.h.

void InitEQep1Gpio ( void   ) 

Init GPIO ports as needed for encoder connection QEP1 (GPIO20, GPIO21, GPIO23).

Definition at line 151 of file Copia de qep.c.

void InitEQep2Gpio ( void   ) 

Init GPIO ports as needed for encoder connection QEP2 (GPIO24, GPIO25, GPIO26).

Definition at line 189 of file Copia de qep.c.

static void QEP1VelocityAndPosition ( void   )  [inline, static]

Calculate position and velocity from encoder readings QEP1:

  • Mechanical position is stored in QEPx.theta_mech.
  • Electrical position is stored in QEPx.theta_elec.
    • Mechanical velocity is stored in QEPx.w_mech.
    • Electrical velocity is stored in QEPx.w_elec.
      Warning:
      : If ISR for encoder is used, this function MUST never be called outside the ISR. This is because the function does not assume an ISR is used and it also clears the unit timer flag (EQep1Regs.QCLR.bit.UTO=1;)
      Todo:
      Same function can be used for both QEP1 and QEP2. Code for function QEPVelocityAndPosition just merged in the new common one.
Examples:
TIMotorLIBExampleHrdw/main.c, and TIMotorLIBExampleSw/main.c.

Definition at line 199 of file qep.h.

static void QEP2VelocityAndPosition ( void   )  [inline, static]

Calculate position and velocity from encoder readings QEP2:

  • Mechanical position is stored in QEPx.theta_mech.
  • Electrical position is stored in QEPx.theta_elec.
  • Mechanical velocity is stored in QEPx.w_mech.
  • Electrical velocity is stored in QEPx.w_elec.
    Warning:
    : If ISR for encoder is used, this function MUST never be called outside the ISR. This is because the function does not assume an ISR is used and it also clears the unit timer flag (EQep1Regs.QCLR.bit.UTO=1;)

Definition at line 228 of file qep.h.

static void QEPVelocityAndPosition ( Uint16  newPos,
Uint16  oldPos,
Uint16  direction,
volatile struct QEP qep 
) [inline, static]

Internal function for calculation of velocity and position. It is called in QEPxVelocityAndPosition.

Parameters:
newPos position in current sample time from QPOSLAT
oldPos position stored in lastPos:
Todo:
: This parameter should be gone
Parameters:
direction direction of counting (0:down, 1:up)
qep pointer to configuration struct for encoder device

Definition at line 256 of file qep.h.

void SwapDirection ( volatile struct QEP qep  ) 

Swaps direction of positive counting

Parameters:
pointer to qep unit (qep1/qep2)

Definition at line 172 of file qep.c.


Variable Documentation

struct QEP qep1

Definition at line 32 of file Copia de qep.c.

struct QEP qep2

Definition at line 33 of file Copia de qep.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Mon Apr 23 12:59:21 2012 for TIMotorLIB by  doxygen 1.6.3