this is my ecoder:
http://www.ebay.com/itm/1PCS-KY-040-...item27e8f12b89
Any help , please ?
Thanks
Ambrogio
this is my ecoder:
http://www.ebay.com/itm/1PCS-KY-040-...item27e8f12b89
Any help , please ?
Thanks
Ambrogio
CAUTION: UNTESTED CODE
Code:main: A var portb.6 B var portb.7 state var byte if(( A == 1)&&(B==1)) then state = 1 if(( A == 1)&&(B==0)) then state = 2 if(( A == 0)&&(B==1)) then state = 3 if(( A == 0)&&(B==0)) then state = 4 ;pause 100 if state = 1 then portC = %00000001 if state = 2 then portc = %00000010 if state = 3 then portc = %00000100 if state = 4 then portc = %00001000 debug " state = ",#state goto main
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
I found this interesting.
http://makeatronics.blogspot.it/2013...ture-with.html
is your "re " a 20 count per turn with indents ? the 10 for a $1 ones I got from ebay have enough contact bounce to start a spring factory but the inherent software filtering of the above code does an amazing job on them 1 (4k7 pu r's and .1uFs included). I have not ported this to pbp but have for mikro c and xc8 if that helps
http://www.circuitsathome.com/mcu/re...age-1#comments
this link has some other insights
basically you just need to adjust your re count using this current value / old value matrix (illegal values [bounces] are just ignored )
One of possible ways to implement filter(Not tested)
Code:OutputValue=0 Select Case OldValue Case 0 If Current=1 then OutputValue=-1 If Current=2 then OutputValue=1 Case 1 If Current=3 then OutputValue=-1 If Current=0 then OutputValue=1 Case 2 If Current=0 then OutputValue=-1 If Current=3 then OutputValue=1 Case 3 If Current=2 then OutputValue=-1 If Current=1 then OutputValue=1 EndSelect
still not able to make my panel encoder working .
Could someone post the complete code applicable to mechanical encoder like my one please ?
Thanks in advance.
regards,
Ambro
post the code you are trying , and a bit of info about your re setup .
does it have detents ?
how many edges per turn ?
pull ups ?
filter caps ?
pic type ?
pins used ?
is not much to work withstill not able to make my panel encoder working
Thanks for the assistance.
My encoder has detents and has about 24 edges per turn.
I used a pull up of 2x 10 k on both encoder phases and a 2x 0.1uF to ground.
I am using pic18f452 , xtal=10 Mhz, ppl X 4 to get 40 Mhz clock speed.
I used RB0 for the "A" phase as shown on the code.
At the end of the world I am now able to make it working well using the following picbasic program by including Darrel Taylor interrupt routine.
The program prints counter results on a terminal @ 115200 baud rate 8,n,1.
Regards, Ambro
DEFINE OSC 40 ' XTAL= 10 MHZ CLOCK= 40 MHZ
INCLUDE "MODEDEFS.BAS"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
INTCON2.BIT6=0 ' interrupt from 1 down to 0 on RB0
CNT VAR WORD ' COUNTER TO BE DISPLAYED ON TERMINAL
CNT= 32000
CNTOLD VAR WORD
CNTOLD=32000
B VAR PORTD.1 ' encoder B PHASE
A VAR PORTD.0 ' encoder A PHASE
' DEBUG INTERFACE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\
'' Set Debug pin port ________________________________________
DEFINE DEBUG_REG PORTD
'' Set Debug pin bit _________________________________________ PIC_PIN_30
DEFINE DEBUG_BIT 7
'' Set Debug baud rate _________________________________________
DEFINE DEBUG_BAUD 115200
'' Set Debug mode: 0 = true, 1 = inverted ______________________
DEFINE DEBUG_MODE 1
DEBUG 13,10,13,10, " START OF PROGRAM ", 13, 10, 13, 10
ADCON1=7 ' all digital !
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
Main:
PAUSE 1
IF CNT <> CNTOLD THEN
DEBUG DEC CNT,13,10
CNTOLD=CNT
ENDIF
sorry for not having paste the complete code...
DEFINE OSC 40 ' XTAL= 10 MHZ CLOCK= 40 MHZ
INCLUDE "MODEDEFS.BAS"
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts
INTCON2.BIT6=0 ' interrupt from 1 down to 0
CNT VAR WORD ' COUNTER TO BE DISPLAYED ON TERMINAL
CNT= 32000
CNTOLD VAR WORD
CNTOLD=32000
B VAR PORTD.1 ' encoder B PHASE
A VAR PORTD.0 ' encoder A PHASE
' DEBUG INTERFACE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\
'' Set Debug pin port ________________________________________
DEFINE DEBUG_REG PORTD
'' Set Debug pin bit _________________________________________ PIC_PIN_30
DEFINE DEBUG_BIT 7
'' Set Debug baud rate _________________________________________
DEFINE DEBUG_BAUD 115200
'' Set Debug mode: 0 = true, 1 = inverted ______________________
DEFINE DEBUG_MODE 1
DEBUG 13,10,13,10, " START OF PROGRAM ", 13, 10, 13, 10
ADCON1=7 ' all digital !
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT_INT ; enable external (INT) interrupts
Main:
PAUSE 1
IF CNT <> CNTOLD THEN
DEBUG DEC CNT,13,10
CNTOLD=CNT
ENDIF
GOTO Main
'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
if b=0 then cnt=cnt-1
IF B=1 THEN CNT=CNT+1
@ INT_RETURN
I found that strategy gave quite disappointing results , was jerky missed counts and had sudden and unexpected direction reversals. there are better waysCode:ToggleLED1: if b=0 then cnt=cnt-1 IF B=1 THEN CNT=CNT+1 @ INT_RETURN
Bookmarks