free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Go to page  1 [2]
Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
shyam
Thu Jun 19 2008, 10:57PM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 720
Thanked 107 times in 103 posts
hi nic,
well u do need those A and B pin as interrupt pins.. or else u may miss the step changes..


or u can try one thing....

wait until states are 1,1
wait for either 0,1 or 1,0

accordigly u wud come 2 know the direction of rotation..

one more point to note..
the shaft is usually very sensitive...
if u are rotating by self (ur hand) well u might observe both the direction so dont panic .. stay calm cause u are using the right procedure..



off topic: any new development regarding your job searh?
all the best.




lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


nicholastyc
Fri Jun 20 2008, 12:04AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
Hi Shyam, wat is mean by
wait until states are 1,1 , 0,1 or 1,0 ?

is it i need to test the both bit in order to enter the loop for testing the direction?


off topic: i havent start to look for job now...i will start this weekend. do u know any job related in UK? thanks...
Back to top


shyam
Fri Jun 20 2008, 12:23AM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 720
Thanked 107 times in 103 posts
is it i need to test the both bit in order to enter the loop for testing the direction?


nic,


take a variable say
int EncCount_int.
int EncStateClk_int[]= {3,2,0,1};
int EncStateAntiClk_int[]= {3,1,0,2};
since the encoder is fast enough .. there is no harm in waiting for that particular stste that u can mark as START.
case1.
if u r not using the pins as interrupt.
start loop.
now u will have to make the uC idle untill the next state change.. i.e. keep checking for the pins untill u notice a change in either of the pin.

read the pins and store in a vriable
int Pinval_int;
int index =1;

now check
if Pinval_int = EncStateClk_int[index]
// clock wise rotation
//decrease EncCount_int
EncCount_int = EncCount_int -1;
else
// anticlock wise rotation
//increase EncCount_int
EncCount_int= EncCount_int+1;
//increment index;
if ( index ==4)
index =0;

get back to the loop



sorry for not being clear enough... am amidst a project needing some attention...
please se if it helps...



lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


nicholastyc
Fri Jun 20 2008, 04:32AM
 User Offline
Registered Member #7707
Joined: Wed May 07 2008, 07:13PM

Posts: 38
Thanked 1 time in 1 posts
i think something is wrong with my code that its only detects 1 direction!!
i have made my program on interrupt on change to the both input port,
the will go into the ISR to save the bit data...
but its still failed to detect the correct direction.

why?

thanks Shyam for your times...i still failed..

[ Edited Fri Jun 20 2008, 04:34AM ]
Back to top


Ajay
Fri Jun 20 2008, 08:26AM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 3686
Thanked 685 times in 647 posts
can i see your code again?

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top


shyam
Fri Jun 20 2008, 08:36AM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 720
Thanked 107 times in 103 posts
yes lets see the code again.. the interrupt one.

lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


sashijoseph
Fri Jun 20 2008, 11:26PM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 524
Thanked 124 times in 117 posts
Hi Nic,
This is a small adaptation of your polling routine using a single variable A11.It savs the current and previous AB values in this manner as a nibble....



CODE:
START
        CLRF    A11             ; clear memory A11
       
        BCF     STATUS,C; clear carry flag incase there is carry

SHAFT_0        
        BTFSC   GPIO,4          ; check on the changes, 0 or 1
        GOTO    SAVEBIT_A11     ; if 1 go savebitA11
        GOTO    SAVEBIT_A10     ;if 0 go savebit A10
SHAFT_1
        BTFSC   GPIO,5          ; check on gpio 5 changes, channel B
        GOTO    SAVEBIT_B11     ;if 1 go savebit B11
        GOTO    SAVEBIT_B10     ;if 0 go savebit B10
SHAFT_2
        BTFSC   GPIO,4          ;same as above to check to the 4th bit
        GOTO    SAVEBIT_A21     ;
        GOTO    SAVEBIT_A20     ;
SHAFT_3
        BTFSC   GPIO,5          ;
        GOTO    SAVEBIT_B21     ;
        GOTO    SAVEBIT_B20     ;
SAVEBIT_A11
        MOVLW   b'00000001'     ; if 1 received on shaft channel A move 1 to A11 memory
        MOVWF   A11             ;
        RLF     A11,1           ; rotate left to make bit 0 avaible for channel B
        GOTO    SHAFT_1         ;
SAVEBIT_A10
        MOVLW   b'00000000'     ;if 0 received on shaft channel A move 1 to A11 memory
        MOVWF   A11             ;
        RLF     A11,1           ;rotate left to make bit 0 avaible for channel B
        GOTO    SHAFT_1         ;
SAVEBIT_B11
        MOVLW   b'00000001'     ; if 1 received on shaft channel B move 1 to A11 memory
        IORWF   A11,1           ;added up with channel B to form 1 complete bit for
        RLF     A11,1           ;each turn, rotate left 2 times for next bit of turn
                                                  of the encoder
        GOTO    SHAFT_2         ;
SAVEBIT_B10
        MOVLW   b'00000000'     ; same as above ...for 0 bit on channel B
        IORWF   A11,1           ;
        RLF     A11,1   ;
       
        GOTO    SHAFT_2         ;

SAVEBIT_A21
        MOVLW   b'00000001'     ;if 1 received on shaft channel A move 1 to A21 memory
        IORWF   A11,1           ;
        RLF     A11,1           ;rotate left to make bit 0 avaible for channel B
        GOTO    SHAFT_3         ;
SAVEBIT_A20
        MOVLW   b'00000000'     ;
        IORWF   A11,1           ;same as above
        RLF     A11,1           ;
        GOTO    SHAFT_3         ;
SAVEBIT_B21
        MOVLW   b'00000001'     ;bit 1 , added up with channel A to form 1 complete bit for
        IORWF   A11,1

        GOTO    DIRECTION       ; direction of the shaft encoder...
SAVEBIT_B20
        MOVLW   b'00000000'     ;same as above, but 0 bit received from previous action
        IORWF   A11,1           ;
       
        GOTO    DIRECTION       ;


RET_FROM_DIRECTION
        RLF     A11,1
        MOVLW   b'00000110'
        ANDWF   A11,1
        GOTO    SHAFT_2







DIRECTION
        ......
        ......

        GOTO RET_FROM_DIRECTION


Let there be music........
Back to top


sashijoseph
Fri Jun 20 2008, 11:40PM

 User Offline
Registered Member #5870
Joined: Mon Feb 04 2008, 06:26PM

Posts: 524
Thanked 124 times in 117 posts
Now for the nibble A11 you can have the following valid values
0x01,0x07,0x08 and 0x0E representing clockwise direction
and
0x2,0x04,0x0B,0x0D representing anticlock direction.

Thus you need to check the nibble for 1,7,8 or E (hex) for a clockwise rot and 2,4,B or D for anti.
Any other value means either no change or invalid... so you need to ignore.

In the 'direction' part of the code you need to implement this logic.

After that the nibble is rotated left once and 'anded' with 00000110 to save the current AB value(which will now become the previous AB value) and the loop is started again for acquiring the current AB value.

Let there be music........
Back to top


Arun Kumar V
Sat Jun 21 2008, 04:55AM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 427
Thanked 178 times in 149 posts

Hi nic,

i think SJ nailed it !


Arun
Back to top


Go to page  1 [2]  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems