Read an Encoder With Polling or Interrupts

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 yous demand to register. Registration is free. Click hither to register now.

  • Forums
  • Digital Design and Embedded Programming
  • Microcontrollers
Y'all are using an out of engagement browser. It may not display this or other websites correctly.
Y'all should upgrade or use an alternative browser.

counters or interrupts for rotary encoder?

  • Thread starter mamech
  • Start engagement
Status
Non open for further replies.
  • #1
Joined
Nov 9, 2010
Messages
176
Helped
0
Reputation
0
Reaction score
0
Bays points
1,296
Activeness points
3,135
Hello

I am new to the globe of interfacing with rotary encoders with motion picture microcontroller. I searched and I read some codes, and I see that the efficient way is to use interrupts, simply my question is, volition I need to use interrupt on change on A / B pins ? or I volition demand to employ counter/timer TMR0 & TMR1 for example?

most of the code that I accept seen are using interrupts, will not be more efficient if i use counter to count pulses?

  • #two
I had seen most of the people uses external interrupt to notice roraty encoder outputs.
Merely that method doesn't worked for me, then i used timer interrupt and recorded the sequence of rotary encoder outputs and based on that i had done rest of the part.
  • #3
The style I normally do it is to use 1 signal to the interrupt pivot and the other to any port pivot. Each interrupt means the encoder was rotated and by immediately looking at the polarity on the port pin you can run into which direction. 'Polling' the encoder inputs without using interrupts presents the risk that one of the signal changes is missed. Information technology depends on the latency of the polling and how fast the encoder pulses make it. For a hand operated encoder you can probably use polling, if it is an encoder on say a motor shaft where the pulse rate can be very fast, I would only consider interrupts.

Notation that some PICs accept congenital-in quadrature detectors which are platonic for sensing rotary encoder signals.

Brian.

  • #4
Joined
Nov ix, 2010
Letters
176
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
three,135
'Polling' the encoder inputs without using interrupts presents the take chances that i of the signal changes is missed. It depends on the latency of the polling and how fast the encoder pulses arrive. For a paw operated encoder you lot can probably use polling, if information technology is an encoder on say a motor shaft where the pulse rate tin be very fast, I would only consider interrupts.

yes, i know this, that is why I excluded polling considering I know that it is inefficient. actually the trouble is that I am facing is to deal 7200 pulse per second encoder with a motor that rotates with 1.667 rotation per second , which equals : 7200*ane.667 = 12000 pulse per 2nd , and this tin not exist dealt with polling I think.

when I say to use counters/timers, I meant to use TMR0 as a counter to take hold of channel A, and to use TMR1 to catch channel B. I imagine that this volition reduce much the interrupts that happens to the primary programme , considering in this case interrupts will happen only when counter overflow happens.

the available micros that I accept does not have built-in detectors, I bargain mainly with pic16f887 and pic16f84a.

and then I am still wondering, will using TMR0 and TMR1 as counters instead of external interrupt on pins be more efficient?

  • #5
Not really, although they can count fast (~50 meg counts per 2d) they cannot tell you in which direction the encoder is turning. A standard quadrature encoder produces equal numbers of pulses per revolution on it'southward A and B outputs and they are at the aforementioned speed then you proceeds nothing by counting both of them.

If you are only using the encoder output to sense speed (as a tachometer) y'all can utilise just one of the outputs and measure its frequency. The easiest fashion to practice that is to use TMR1 as a pulse counter and TMR0 or TMR2 to count a time interval using the PICs own clock. From that y'all tin derive the number of pulses per second.

If management has to be checked, feed ane output to the interrupt pin and as soon as possible in the ISR, check the polarity of the other input. In one direction the input pin wil be high, in the other direction it will be low. Y'all can notwithstanding measure the speed by counting how fast the interrupts occur.

Brian.

  • #vi
Joined
November 18, 2008
Letters
2,123
Helped
596
Reputation
1,188
Reaction score
573
Trophy points
i,393
Location
Norwich, Uk
Activeness points
xiii,069
  • #seven

HTA

Advanced Member level i
Joined
Nov 17, 2011
Letters
445
Helped
108
Reputation
216
Reaction score
104
Trophy points
i,323
Activity points
3,925
Software based AB-counting is o.k. for low speed, all the same information technology requires execution fourth dimension in the microcontroller. For higher speed incremental position encoding we used a counter solution with integrated direction discrimination similar https://world wide web.ichaus.de/wp2_simple_measurement .

Savor your pattern work!

Status
Not open up for further replies.

Similar threads

  • rotary encoder for proteus.needed
  • PIC18F452 Timers/Counters Interrupts,...
  • rotary shaft encoder
  • Rotary encoder probleam
  • reading a rotary encoder
  • Forums
  • Digital Design and Embedded Programming
  • Microcontrollers

cagleforis1984.blogspot.com

Source: https://www.edaboard.com/threads/counters-or-interrupts-for-rotary-encoder.331142/

Related Posts

0 Response to "Read an Encoder With Polling or Interrupts"

ارسال یک نظر

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel