|
|
View previous topic :: View next topic |
Author |
Message |
pcmguy
Joined: 24 Oct 2005 Posts: 5
|
rotary encoder |
Posted: Thu Oct 27, 2005 3:25 am |
|
|
I have an 360 pulses rotary encoder from omron (model: e6b2-cw26c), it gives a, b, z output, means I can detect the encoder rotate clockwise and anti clockwise.
So, anybody got the sample program to detect the rotary encoder angle?
Any component need to added in the design (beside pic), any proper wiring diagram?
Thanks!
pcmguy, |
|
|
neil
Joined: 08 Sep 2003 Posts: 128
|
|
Posted: Thu Oct 27, 2005 4:23 am |
|
|
I think triggering an external interrupt on each pulse and then looking which phase is high, would do it. I wrote simple code a few years ago which took phase A into the ext interrupt and in there looked at whether phase B was high or low to give direction. This of course gave only half the resolution, which was a bit of a pain because my encoder had detents.
If you EXOR the two phases and use this as your 'rotation' pulse, then look at the relative polarity of A & B (which one leads) this will give direction information. Perhaps the way to go would be to use Port B interrupt on change, rather than the B0 interrupt?
Are you using the Z phase as well for detecting the origin?
Neil. |
|
|
Ttelmah Guest
|
|
Posted: Thu Oct 27, 2005 9:32 am |
|
|
Do a search in the archives for 'quadrature'. I posted code to do this on the 18F family some time ago. On the interconnection, it depends actual unit. A look at the data sheet is necessary. However the software solutions all have the potential to miss pulses at higher speeds, and then a hardware solution becomes 'better'. This ranges from a simple bit of logic to do X2 decoding, and feeding the outputs into the conter inputs on the processor, through to using a fully hardware solution like the 7166.
Best Wishes |
|
|
|
|
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
|