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

help needed to debug Quadrature Encoder coding ( very Basic)

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



Joined: 22 Nov 2011
Posts: 32
Location: puducherry

View user's profile Send private message Send e-mail

help needed to debug Quadrature Encoder coding ( very Basic)
PostPosted: Mon Feb 06, 2012 12:14 am     Reply with quote

hi.
I am using pic 18f4431.
When qei is used with older versions it was working fine.

Now updated to the latest version.

This is my code:
Code:

#include <18F4331.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#fuses SSP_RD
#use delay(clock=20000000)

#byte MCHH=0Xf65     //SET THE MAX COUNT HIGH
#byte MCLL=0Xf64     //SET THE MAX COUNT LOW

#bit up  = 0xFB6.5  //UP AND DOWN CALCULATION
long value;
int b;

#int_IC3DR
void  IC3DR_isr(void)
   {
    MCHH=0X03;MCLL=0XE8;
    value = qei_get_count(0);
    output_c(value);
   }

#int_IC2QEI

void  IC2QEI_isr(void)
   {
   MCHH=0X03;
   MCLL=0XE8;
   value = qei_get_count(0);
    output_b(value);
   }

void main()
{
   MCHH=0X03; MCLL=0XE8;
   set_tris_b(0x00);
   set_tris_c(0x00);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_IC3DR);
   enable_interrupts(INT_IC2QEI);
   enable_interrupts(GLOBAL);
   setup_qei(QEI_MODE_X2_RESET_ON_MATCH | QEI_FILTER_DISABLED);
   qei_set_count(0);
   while(1);
}


My objective is whenever there is change in rotor position in motor I want to display the count of position counter for every count.
When there is a change in direction the count gets displayed in C-PORT due to direction change interrupt...

But for every count the position counter value is NOT GETTING DISPLAYED in B-PORT due to Position counter interrupt.

I wanted to reset the counter for every 1000 pulses.
Correct the code and help me if I am wrong.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 06, 2012 6:22 am     Reply with quote

If you mean you updated the compiler and your original program no longer works correctly, then there is a bug in the newer compiler.
Simply compare the listings of the program the older version and the new one. Since the code is short, it should only take a few minutes to see the difference.
You don't say what version of the compiler but report the 'bug' to CCS and include versions as well as your program (so they can test as well).

If you mean this program is the 'updated' one, but same compiler then you've changed something which we don't know as you haven't shown us your old working program. Since I don't have this PIC (I use external QEI) I can't further comment on the code you've shown or the hardware that I can't see.
gokulrred



Joined: 22 Nov 2011
Posts: 32
Location: puducherry

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 06, 2012 10:52 pm     Reply with quote

EUREKA..... EUREKA.....

found the theory behind it......

IC3DR:

this is the interrupt which gets generated whenever there is a change in direction of rotation of motor.

IC2QEI:

this interrupt gets generated in one of the following cases:
1. when position counter gets reset due to index pulse.
2. when we set the MAXCNT and if it is reached then this interrupt gets generated.

i think in former versions there was a bug and it might be corrected in this updated version.......
gokulrred



Joined: 22 Nov 2011
Posts: 32
Location: puducherry

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 06, 2012 10:55 pm     Reply with quote

Code:
#include <18F4431.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#byte MCHH=0Xf65     //SET THE MAX COUNT HIGH
#byte MCLL=0Xf64     //SET THE MAX COUNT LOW
#bit up  = 0xFB6.5  //UP AND DOWN CALCULATION
long new_count, old_count, value,value1;
int b;


#int_IC3DR
void  IC3DR_isr(void)
{
    value= qei_get_count();
    output_c(value);
}

#int_IC2QEI
void  IC2QEI_isr(void)
{
  value1=value1+1;
  output_b(value1);
}



void main()
{
   enable_interrupts(INT_IC3DR);
   enable_interrupts(INT_IC2QEI);
   value1=0;
   enable_interrupts(GLOBAL);
   setup_qei(QEI_MODE_X2_RESET_ON_MATCH | QEI_FILTER_DISABLED);
   MCHH=0X00; MCLL=0X20;

   while(TRUE)
   {
   new_count= qei_get_count();
   output_d(new_count);
   }


check out this code......
whenever direction changes port C displays the current count value.
i've set the max count = 20(hex).

whenever the position counter crosses 20 and reset to zero the port B will increment count and displays it.....
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