Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 09, 2016, 02:34:43 14:34


Login with username, password and session length


Pages: [1]
Print
Author Topic: REQ - Circuit to count pulses of encoder  (Read 4270 times)
0 Members and 1 Guest are viewing this topic.
niktesla
Cracking Team
Active Member
****
Offline Offline

Posts: 213

Thank You
-Given: 166
-Receive: 278



« on: May 11, 2008, 12:45:22 00:45 »


Hi,

Who knows some circuit using PIC to count pulses of incremental encoder?


Thanks


Niktesla   Smiley
Logged

Ensinar é aprender, compartilhar é se tornar mais forte!!!<br />Teaching is learning, sharing is becoming stronger!<br />NikTesla
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 3816

Thank You
-Given: 567
-Receive: 2049


There is no evidence that I muted SoNsIvRi


« Reply #1 on: May 11, 2008, 08:39:50 20:39 »

http://en.wikipedia.org/wiki/Rotary_encoder
also tim over in proton site has posted some work on encoders. but don't post in there, as they have spies in here. Smiley
http://www.picbasic.org/forum/showthread.php?t=6828
Logged

Note: If you have no posts other than, I want or reporting a dead link Then you can't complain If I remove your post So Stop Leeching
margo
Junior Member
**
 Muted
Offline Offline

Posts: 52

Thank You
-Given: 38
-Receive: 33


« Reply #2 on: May 13, 2008, 11:43:55 23:43 »

here is a bit of code ive used many times, its written for picbasic pro,,it expects a 2 bit gray code input..hope its what your after

edit:::: in response to a couple of queries...the code is set up for 2 encoders...the OUTPUTS from each encoders is tied to +5v via 2x 10k resistors
the COMMON terminal of the encoder is tied to 0v

the encoder outputs are connected to portB 4 & 5 and the other encoder to portB 2 & 3

the code outputs a SERIAL interface to a lcd, and simply presents a 'count' of the position of the encoder,, this is easily converted to a standard parallel LCD in the usual PBP way

ive not simulated this with proteus, although i have downloaded the 'ROTENC' model elsewhere on this site...and after a few false starts it seems to work ok..if anyone gets it working pls post the project!!!!

here is an example of a cheap encoder
http://cgi.ebay.co.uk/Rotary-Encoder-push-button-switch-Ideal-for-Data-Entry_W0QQitemZ270130801383QQihZ017QQcategoryZ58169QQrdZ1QQssPageNameZWD1VQQcmdZViewItemQQ_trksidZp1638Q2em118Q2el1247



end edit::::

include "modedefs.bas"

zFlags          var     byte
Changed         var     zflags.0
OldA            var     byte ' Previous state of encoder A bits
NewA            var     byte ' Current state of encoder A bits
DirectionA      var     bit  ' Direction of encoder A travel; 1=CCW.
zza6            var     NewA.0
zza15           var     OldA.1
PositionA       var     byte
OldB            var     byte ' Previous state of encoder B bits
NewB            var     byte ' Current state of encoder B bits
DirectionB      var     bit  ' Direction of encoder B travel; 1=CCW.
zzb6            var     NewB.0
zzb15           var     OldB.1
PositionB       var     byte




true            con     1
false           con     0







PositionA = 0
PositionB = 0


' Rotary encoders connected as follows:

'RenA1           var     PortB.5
'RenA2           var     PortB.4
'RenB1           var     PortB.3
'RenB2           var     PortB.2

NewA = PortB & %00110000
NewB = PortB & %00001100
NewA = NewA >> 4
NewB = NewB >> 2


pause 500


'LCDOut LCDCmd, LCDClear
pause 200


MainLoop:
OldA = newA
OldB = newB
Changed = false
Again:
NewA = PortB & %00110000
NewB = PortB & %00001100
NewA = NewA >> 4
NewB = NewB >> 2
IF NewA <> OldA Then Gosub ChangedA
IF NewB <> OldB Then Gosub ChangedB
if Changed = false then Again

'serout 7,t2400,$fe[#PositionA]
serout 7,t2400,[$fe,1]
serout 7,t2400,[#PositionB]


Goto MainLoop




ChangedA:
DirectionA = zza6 ^ zza15 ' XOR right bit of new w/ left bit of old.
IF DirectionA = 1 Then
        PositionA = PositionA - 1
       
        else
        PositionA = PositionA + 1
        pause 10
        endif
Changed = true
Return

ChangedB:
DirectionB = zzb6 ^ zzb15 ' XOR right bit of new w/ left bit of old.
IF DirectionB = 1 Then
        PositionB = PositionB - 1
        pause 10
        else
        PositionB = PositionB + 1
        pause 10
        endif
Changed = true
Return
« Last Edit: May 17, 2008, 01:27:49 01:27 by margo » Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC