Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HELP....QUADRATURE ENCODERS....

Status
Not open for further replies.

roykyn

Full Member level 5
Joined
Sep 15, 2006
Messages
253
Helped
12
Reputation
24
Reaction score
5
Trophy points
1,298
Activity points
2,704
hi there to all of you.... my problem is that i am using 3 quadrature encoders (total 6 photo detectors) connected pic16f72 . All to portA, so can any one suggest me a C-program,logic,algorithm or hardware it would help me.Thank you in advance.
I am using CCS C compiler.It would be great if the code is in ccs c. :idea:
 

Here's example polling code (Microchip C18) for 4 encoders which I hope may help. All of the encoder 'A' lines are connected to RB0..RB3 and all of the encoder 'B' lines are connected to RB4..RB7. This is just one of a hundred different ways you can do it.

Good luck with your project. Kind regards, Mike - K8LH

Code:
void ReadEncoders()
/*                                                               *
 *  a '1' bit indicates that A or B has changed (not both)       *
 *                                                               */
{ Anew = (PORTB << 4);
  Bnew = PORTB;
  Changed = (Anew ^ Aold)^(Bnew ^ Bold);
/*                                                               *
 *  xor Anew and Bold or Bnew and Aold as appropriate to set     *
 *  CountUp bits (subsequently qualified by the Changed var')    *
 *                                                               */
  CountUp = Anew ^ Bold;
  Aold = Anew;
  Bold = Bnew;

  if (Changed & BIT4)
  { if (CountUp & BIT4)
      Count0++;
    else
      Count0--;
  }
  if (Changed & BIT5)
  { if (CountUp & BIT5)
      Count1++;
    else
      Count1--;
  }
  if (Changed & BIT6)
  { if (CountUp & BIT6)
      Count2++;
    else
      Count2--;
  }
  if (Changed & BIT7)
  { if (CountUp & BIT7)
      Count3++;
    else
      Count3--;
  }
}
 

    roykyn

    Points: 2
    Helpful Answer Positive Rating
thanks mike.... i ll try this code ......mike i am not able to reach you by personal message... its just not working..... i am having some doubts about the program.....
can you help me out..... wat is BIT4-7
 

probably :
#define BIT4 (1<<4)
#define BIT5 (1<<5)
#define BIT6 (1<<6)
#define BIT7 (1<<7)

those should correspond to micro's port pins where encoder outputs must be connected.
 

roykyn said:
hi there to all of you.... my problem is that i am using 3 quadrature encoders (total 6 photo detectors) connected pic16f72 . All to portA, so can any one suggest me a C-program,logic,algorithm or hardware it would help me.Thank you in advance.
I am using CCS C compiler.It would be great if the code is in ccs c. :idea:

TO DETECT DIRECTION (in pseudo code):

variables:
chA.......... pic pin input from encoder channel A (1=high 0=low)
chB.......... pic pin input from encoder channel B (1=high 0=low)
old_chA... value of chA from previous pulse
cw........... rotation direction (1=cw 0=ccw)

quadrature sequence sample:
step1: chA=1 chB=0
step2: chA=1 chB=1
step3: chA=0 chB=1
step4: chA=0 chB=0

in pseudo-code the logic to detect direction would be:
Code:
 while 1     'repeat forever
     if newPulse then
          cw = (chB = old_chA) 'if actual chB = old_chA, CW, else CCW
          old_chA = chA        'backup chA for next cycle
       end if
 end while
 

if you use proteus vsm

youll find a simulation model i made
for a dented {not important within vsm }
rotary encoders 3 pin


look in the software download section at my sticky post

if it helps i can add facets to it as needed let me know

both the dll and lisa files are there
the lisa model is tested and worked with the code above

i dont mind if someone needs another type
although the models and parts as is are pretty flexable

and the dll will be ready next week sometime im sure
but you can watch how i get on with it over the next few days
as ill upload it when more complete again

however the lisa model works fine .... you can add a switch to it much like the data sheet i added

just pm me a datasheet or url and ill see whats needed


the dll i plan to have some nice features like pause sim slide an amount
then on restart sim the encoder will step to its new position
even many full rotations is easy to store and step im sure...
it has an animated screen i plan to add a graphic to
some sort or rotating symbol etc or 3d vecter plot {quite easy to me}

well hope its helpfull anyway :cry:

note:
to get this sequence is easy just adjust the lisa model
step1: chA=1 chB=0
step2: chA=1 chB=1
step3: chA=0 chB=1
step4: chA=0 chB=0

the type i built for uses 2bit gray code

A:B
0:1 right {cw} step
1:0 left {ccw} step
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top