|
|
View previous topic :: View next topic |
Author |
Message |
JAM2014
Joined: 24 Apr 2014 Posts: 138
|
Suggestions for implementing a rotary (quadrature) encoder. |
Posted: Tue May 03, 2022 1:47 pm |
|
|
Hi All,
I have a new project design that uses a rotary encoder for user input. The encoder is a CTS series 290 (Digikey CT3007-ND), which is a 2 bit quadrature encoder with 20 pulses per revolution, paired with a momentary switch. In the design prototype, I currently have the 'A', 'B', and 'SW' encoder connections made to RD4, RD5, and RD6 of an 18F45K50 PIC. I 'poll' these inputs periodically using an interrupt generated timer 'tick' every 50mS. This seems to work 'OK', but is not really 100% robust and reliable. Other timer 'ticks' execute every 100mS for a PID control loop, and every 1S for a display update....
I'm about to have a 2nd prototype PCB made, and I'm thinking of changing the encoder 'A', 'B', and 'SW' connections to RC0, RC1, and RC2 on the PIC to take advantage of the IOC capability of the 18F45K50. I've also added an RC filter and Schmitt trigger buffer to each of the three encoder connections so the outputs are really clean with nice edges!
If you were designing a new PIC circuit with a rotary encoder, is this how you'd connect the encoder? Is this the encoder you'd use? Are there better/easier encoder devices, and is there a better/different way to connect it?
I'm NOT 100% wedded to this encoder, or this PIC, although I do need a USB capable PIC for this project!
Thanks,
Jack |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9222 Location: Greensville,Ontario
|
|
Posted: Tue May 03, 2022 2:04 pm |
|
|
Used to use HP encoders, then switched to LSI/CSI, FAR superior, simple to install....just looked online, while they still sell the encoders 'chips', didn't see any actual encoders..hmmm....
I would use the IOC pins if possible..grab a breadboard, cut code, test it out....
CCS may have an example ? They do for 'polled' I believe ?? |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Tue May 03, 2022 2:12 pm |
|
|
That's how I've done it in the past, although I had wired mine to pins B4-B6 to take advantage of the INT_RB of the 18F452 I used at the time.
Interrupt occurs, read the state of the port (pins), determine the current state, compare with last state, and you know direction of turn. Bonus points: race this interrupt against a timer to determine rate of turn. Slow turns (timer wins): increment/decrement by one. Fast turns (change interrupt wins), increment/decrement by 5 or 10. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19500
|
|
Posted: Wed May 04, 2022 12:41 am |
|
|
Three different ways of doing this 'sensibly'.
1) Use an external decoder.
2) Use a PIC that has a quadrature decoder built in. Devices like the 4431.
3) As others have said, use IOC (INT_RB). I've done IOC with a highly
optimised interrupt handler with a 10000 line opto sensor in the past,
and merrily handled 400RPM at this resolution.
Have a look at this thread (and the links from it):
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=44491&postdays=0&postorder=asc&highlight=quad&start=15
[/url] |
|
|
|
|
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
|