CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using the Encoder Quadrature - QEI - PIC18F2431

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mauricio Lopes



Joined: 11 Oct 2006
Posts: 5

View user's profile Send private message

Using the Encoder Quadrature - QEI - PIC18F2431
PostPosted: Wed Oct 11, 2006 11:59 am     Reply with quote

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

View user's profile Send private message Visit poster's website

Using the Encoder Quadrature - QEI - PIC18F2431
PostPosted: Tue Oct 17, 2006 6:48 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 18, 2006 8:36 pm     Reply with quote

Very Thanks Mr. Sergey,

It works very good... Its all thats i need Laughing
_________________
Best Regards,
Mauricio Lopes
hasimi20



Joined: 04 Sep 2010
Posts: 19

View user's profile Send private message

PostPosted: Sun Apr 24, 2011 7:31 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 25, 2011 9:27 am     Reply with quote

Hi, here is a link to a worked example that you can try out

http://www.ccsinfo.com/forum/viewtopic.php?t=44768

Thanks Scott
hasimi20



Joined: 04 Sep 2010
Posts: 19

View user's profile Send private message

PostPosted: Tue May 03, 2011 12:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue May 03, 2011 12:29 pm     Reply with quote

Your version of the compiler (4.104) doesn't have support for the
setup_qei() function. He is using a later version (4.116).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group