decoding quadrature encoders


Results 1 to 40 of 94

Threaded View

  1. #11
    ice's Avatar
    ice Guest


    Did you find this post helpful? Yes | No

    Default

    ok,heres my program ,using interrupts..

    the problems i'm encountering are below the code
    ..
    Code:
    DEFINE LOADER_USED 1
    
    
    led     VAR     PORTB.7
    old 			VAR BYTE
    new 			VAR BYTE
    direction_bit 	VAR BIT
    counter 		VAR WORD
    counter_1		VAR WORD
    counter_2		VAR WORD
    direction_store	VAR BIT
    adval			VAR	WORD				' Create adval to store result
    potval			VAR WORD
    servo_val		VAR	WORD
    difference		VAR WORD
    	
    
    counter=32500		
    	
        	HPwm 0,150,20000    
            OPTION_REG = $7f        
            ON INTERRUPT GoTo myint     ' Define interrupt handler
            INTCON = $90                     ' Enable INTE interrupt
    
    	
    
    loop:   High led                ' Turn LED on
    
    		LCDOut $fe,1,"count:"
    		LCDOut $fe,$c0,DEC counter
    		'Pause 10
    		
            GoTo loop               ' Do it forever
    
    
    
    
    		' Interrupt handler
            Disable                 ' No interrupts past this point
    myint:  Low led                 ' If we get here, turn LED off
           
           
    enc:    new= PORTB & %00000011
    
    
    start_1:
    		old=new & %00000011	
    		
    again:
    
    		new= PORTB & %00000011					'load new value of A/B channels into new by anding with HEX3
    			
    		
    	    'IF new=old Then again
    	    direction_bit=old.bit1 ^ new.bit0		'check direction 
    	
    		
    		IF direction_bit = 1 Then  
    		LCDOut $fe,1,"Last was CW"
    		counter = counter + 1				'increment counter
    		LCDOut $fe,$c0,DEC counter," ",BIN direction_bit
    	
    		Else
    			LCDOut $fe,1,"Last was CCW"
    			counter = counter - 1				'decrement counter
    			LCDOut $fe,$c0,DEC counter," ", BIN direction_bit	
    		
    		EndIF
    		Pause 10
    	   			
    
                  
    		INTCON.1 = 0           ' Clear interrupt flag
    	    Resume                 ' Return to main program
    	    Enable
    1>The interrupts are worng fine,however the code is still unable to distinguish between CW and CCW,because of which the counting goes awry..

    2>if i remove the "if then " statement for CW/CCW direction and only put a
    counter=counter+1,it works well


    The whole problem seems to be the direction decoding part..
    ..i cant seem to find a solution to it..
    Last edited by ice; - 3rd May 2005 at 13:00.

Similar Threads

  1. Quick thoughts: DT Ints with encoders
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 7th January 2010, 01:01
  2. PMDC SERVO MOTOR WITH quadrature encoder DRIVE ?
    By phoenix_1 in forum Schematics
    Replies: 37
    Last Post: - 22nd November 2009, 19:45
  3. 32-bit Quadrature Counter With Serial Interface
    By precision in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th June 2008, 02:49
  4. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 17:49
  5. "momentary" IR decoding
    By sporker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th June 2005, 01:53

Members who have read this thread : 4

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts