a couple of 100nF were needed for mine. After placing the caps to ground from each encoder output pin, false readings were a past.
Ioannis
a couple of 100nF were needed for mine. After placing the caps to ground from each encoder output pin, false readings were a past.
Ioannis
Need help with one enconder ... a little different.
How can I read the "up/+" and "down/-" action of this particular encoder ?
Any help will be appreciated ! Thanks in advance !
It's ok something like this ?!
Code:TrisA = %00000000 TrisB = %11110000 PortB = 0 Flag var bit Q_New var Byte Q_Old var byte M_Count var byte [4] P_Count var byte [4] Q_Count var word ' ---------------------- Set variable value @ startup ---------------------- For Q_Old = 0 to 3 Read Q_Old,M_Count[Q_Old] Read Q_Old + 4,P_Count[Q_Old] Next Q_Old Q_Count = 0 Q_New = 0 Q_Old = 0 Flag = 0 Goto Main_Loop Encoder: ' Q_New = PortB.7 + PortB.6 + PortB.5 ' get port status If M_Count[Q_Old] = Q_New then ' if M_Count code satisfied then minus Q_Count = Q_Count - 1 Flag = 0 ' set flag for DOWN goto Q_Skip endif If P_Count[Q_Old] = Q_New then ' if M_Count code satisfied then plus Q_Count = Q_Count + 1 Flag = 1 ' set flag for UP endif Q_Skip: Q_Old = Q_New ' update Q_Old Byte Main_Loop: if Flag = 1 then do command1 if Flag = 0 then do command2 goto Main_Loop
So far...no good...
Complete "hardware" it's like in picture . I intend to use an remote with some "rotary encoder" ...
The remote controller has six wires . They are connected to three rows and three columns. This allows maximum of 3*3=9 functions. Roller takes three functions because it must be possible to know which way it is rotated (how doing this in PBP ?!?). Rest of the functions are assigned to six buttons.
I use great pice of code (keypad matrix routine) of Mr. Mister-e and the "regular" buttons works verry fine...but I want to use the function of roller too.
I can't figure out how doing this, so any "clue" will be appreciated !
Hi,
Without analyzing your code in detail one possible problem might be this lineIn this case you'll get Q_New = 1 no matter WHICH of the three pins are high. I'm not sure but I guess that's not what you want.Code:Q_New = PortB.7 + PortB.6 + PortB.5 ' get port status
You could try something like Q_New = PortB & %11100000 >> 5 instead.
Here's another approach (untested) which is smaller in terms of program space and RAM but like I said it's untested so it might not even work.Code:oldState VAR BYTE newState VAR BYTE Q_Count VAR WORD DIR VAR BIT UP CON 1 DN CON 0 newState = (PortB & %11100000) ' Isolate top three bits, newState will be 32, 64 or 128 If newState <> 0 THEN If newState <> oldState THEN ' Changed from last time? Select Case oldState Case 32 If NewState = 128 THEN ' Was 1 now 4 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 1 now 2 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 64 If NewState = 32 THEN ' Was 2 now 1 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 2 now 4 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 128 If NewState = 64 THEN ' Was 4 now 2 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 4 now 1 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF END SELECT oldState = NewState ENDIF ENDIF
It a real pleasure to see how generous some people can be ... Thank You, AGAIN, Mr. Henrik !
...I think I missing something ... If UP do something, If Down do something else...dont ?!
But nothing happens.
Or I wired the roller wrong ?Code:'**************************************************************** @ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_ON, BOD_OFF, MCLR_ON, LVP_OFF Define OSC 4 ' 4MHz CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode include "alldigital.pbp" TrisA = 000000 PortB = 010000 TrisB = 000000 oldState VAR BYTE newState VAR BYTE Q_Count VAR WORD DIR VAR BIT UP CON 1 DN CON 0 Main_Loop: newState = (PortB & 100000) goto encoder if dir = up then portb.0 = 1 if dir = dn then portb.1 = 1 goto Main_Loop goto encoder if dir = up then portb.4 = 1 portb.0 = 1 endif if dir = dn then portb.4 = 0 portb.1 = 1 endif goto Main_Loop encoder: If newState <> 0 THEN If newState <> oldState THEN ' Changed from last time? Select Case oldState Case 32 If NewState = 128 THEN ' Was 1 now 4 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 1 now 2 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 64 If NewState = 32 THEN ' Was 2 now 1 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 2 now 4 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 128 If NewState = 64 THEN ' Was 4 now 2 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 4 now 1 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF END SELECT oldState = NewState ENDIF ENDIF
Here ( http://www.angelfire.com/nd/maza/kenwood.html ) it's a working variant, but in other "way" , using Atmega ...
Last edited by fratello; - 13th April 2012 at 10:46.
Dave
Always wear safety glasses while programming.
Bookmarks