View previous topic :: View next topic |
Author |
Message |
Mauricio Lopes
Joined: 11 Oct 2006 Posts: 5
|
Using the Encoder Quadrature - QEI - PIC18F2431 |
Posted: Wed Oct 11, 2006 11:59 am |
|
|
Hi,
How i do to use this module in CCS C compiler? Somebody have an exemple to send-me?
Thanks _________________ Best Regards,
Mauricio Lopes |
|
|
sd211
Joined: 15 Nov 2005 Posts: 4 Location: NC, USA
|
Using the Encoder Quadrature - QEI - PIC18F2431 |
Posted: Tue Oct 17, 2006 6:48 pm |
|
|
Here is some code related to setting up QEI, I used it while ago. I could not find a function in CCS C to set it up, but this seemed to work:
In include file:
Code: |
//Defines specific for 18F2431 which are not present in 18F2431.H file
//bits of QEICON Quadrature Encoder Interface control register
#define DISABLE_VELOCITY 0x80
#define QEI_OFF 0x00
#define QEI_2XINDX 0x04
#define QEI_2XPER 0x08
#define QEI_4XINDX 0x14
#define QEI_4XPER 0x18
#define VELOCITY_DIV_1 0x00
#define VELOCITY_DIV_4 0x01
#define VELOCITY_DIV_16 0x02
#define VELOCITY_DIV_64 0x03
#byte QEICON = 0xFB6
//bits in QEICON
#define QEI_NOT_VELM 7
#define QEI_ERROR 6
#define QEI_DIRECTION 5
int16 POSCNT;
#byte POSCNT = 0xF66
#byte POSCNTH = 0xF67
#define POSCNTL = 0xF66
int16 VREG;
#byte VREG = 0xF68
#byte VREGH = 0xF69
#byte VREGL = 0xF68
#byte DFLTCON = 0xF60 //Digital Filter Control Register
#byte CAP1CON = 0xF63
|
in the .c file (initialization):
Code: |
//setup quadrature encoder
QEICON = QEI_2XINDX | VELOCITY_DIV_4;
QEICON &=0b01111111; //clear Velocity mode bit to enable
CAP1CON |= 0b01000000; //enable Time Base reset (TMR5)
//TMR5 used for velocity measurement
setup_timer_5 (T5_INTERNAL | T5_DIV_BY_4);
enable_interrupts(INT_IC1);
enable_interrupts(INT_IC2QEI);
enable_interrupts(INT_IC3DR);
|
And then process interrupts somewhere
Code: |
#int_IC1
/*
Velocity capture interrupt
*/
void IC1_isr()
{
}
#int_IC2QEI
/*
Position counter interrupt
Increment (decrement) variable MSB_position that provides a 32-bit position
counter along with hardware position counter
*/
void IC2QEI_isr()
{
}
#int_IC3DR
/*
Direction of movement interrupt
*/
void IC3DR_isr()
{
}
|
Hope this helps
Sergey Dryga
http://beaglerobotics.com |
|
|
Mauricio Lopes
Joined: 11 Oct 2006 Posts: 5
|
|
Posted: Wed Oct 18, 2006 8:36 pm |
|
|
Very Thanks Mr. Sergey,
It works very good... Its all thats i need _________________ Best Regards,
Mauricio Lopes |
|
|
hasimi20
Joined: 04 Sep 2010 Posts: 19
|
|
Posted: Sun Apr 24, 2011 7:31 pm |
|
|
hello, by using sd211's code, how can i determined the encoder direction and encoder speed??i still cant understand how to use the given code. could any body please share how to program the qei module in order to determined the encoder direction and encoder speed?? |
|
|
scottc
Joined: 16 Aug 2010 Posts: 95
|
|
|
hasimi20
Joined: 04 Sep 2010 Posts: 19
|
|
Posted: Tue May 03, 2011 12:35 am |
|
|
I am using ccs c compiler pcwhd 4.104. I am testing your given program, however the compiler can't compile the "setup_qei(QEI_MODE_X2);"... could you please explain??? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 03, 2011 12:29 pm |
|
|
Your version of the compiler (4.104) doesn't have support for the
setup_qei() function. He is using a later version (4.116). |
|
|
|