Just try PortB.7 and PortB.6 ...
and read the '877 Databook , Interrupts section :
WHICH are the 4 pins that create "interrupts on change" ???
HOW to avoid the " Mismatch condition " ???
Alain
Just try PortB.7 and PortB.6 ...
and read the '877 Databook , Interrupts section :
WHICH are the 4 pins that create "interrupts on change" ???
HOW to avoid the " Mismatch condition " ???
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
These code count pulses from one pin of quadrature encoder good and fast.
It use RB0 INT very good.
Now I need idea to implement full reading quadrature encoder A and B inputs with count of pulses and direction indication..
Encoder is with 500 pulses per full revolution.
How - need idea..?
Procesor 16F877 @ 20MHz
Regards RobertCode:define OSC 20 DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_SPBRG 64 ' 19200 Baud @ 20MHz, 0.16% DEFINE HSER_CLROERR 1 ' Clear overflow automatically ADCON1 = 7 TRISB = %00000011 a var word a = 0 INTCON = %10010000 ; Enable INTE RB0 interrupt $90 INCLUDE "DT_INTS-14.bas" INCLUDE "ReEnterPBP.bas" ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT_INT, _TEST, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM Main: if a >= 5000 then a = 0 endif hserout [ dec a ] pause 100 GOTO Main '---[INT_INT - interrupt handler]------------------------------------------ TEST: a = a + 1 @ INT_RETURN![]()
Last edited by phoenix_1; - 30th August 2009 at 22:24.
Connect encoder channel A to portB.0 (I assume you already have it) and channel B to portB.1. Since channel A is out of phase on channel B turning your encoder CW channel A will be high before channel B and turning it CCW channel B will be high first.
In your interrupt handler check the above conditions
If variable CW is 1 then your motor is turning clockwise if CW = 0 then is turning counterclockwise, while word variable a will contain the updated count.Code:If portB & %00000011 = 1 Then a = a + 1 CW = 1 Else a = a - 1 CW = 0 Endif
Al.
Last edited by aratti; - 30th August 2009 at 23:57.
All progress began with an idea
I have forgotten to say, in my previuos post, that the code snippet is not a quadrature count, and it counts only channel A, while Channel B is used only for direction. So total count per encoder turn will be n/2.
To get a quadrature count you need to detect the rising and falling edges of the square waves, thing that is not possible with the pic you have in use. To obtain the quadrature count you either need additional external logic or you have to choose a pic with the quadrature counter. (Much easier)
Al.
Last edited by aratti; - 31st August 2009 at 07:42.
All progress began with an idea
Bookmarks