decoding quadrature encoders


Results 1 to 40 of 94

Threaded View

  1. #13
    ice's Avatar
    ice Guest


    Did you find this post helpful? Yes | No

    Default

    Luciano,

    when i try the program u recommended [12th april] as below,
    there are alot of instances when the program gets confused with direction,
    so it sometime increments and decrements.Im not using interrupts

    when i move the motor slowly,the problem still persists.

    Code:
    old_val 		VAR BYTE
    new_val 		VAR BYTE
    direction_bit 	VAR BIT
    enc_counter 	VAR WORD
    adval			VAR	WORD				' Create adval to store result
    potval			VAR WORD
    servo_val		VAR	WORD
    difference		VAR WORD
    	
    TRISB=%11111111
    enc_counter=32500		
    HPwm 0,100,20000	
        
    	
    
    	new_val = PORTB & %00000011
    start:
    	old_val = new_val
    	
    	
    again:
    	new_val = PORTB & %00000011
    	'LCDOut $fe,1,"no move"
    	IF new_val = old_val Then again
    
    	direction_bit = old_val.bit0 ^ new_val.bit1
    	
    	IF direction_bit = 1 Then  
    	
    		LCDOut $fe,1,"Last was CW"
    		enc_counter = enc_counter + 1
    		LCDOut $fe,$c0,DEC enc_counter
    
    	Else
    		LCDOut $fe,1,"Last was CCW"
    		enc_counter = enc_counter - 1
    		LCDOut $fe,$c0,DEC enc_counter	
    	
    	EndIF
        	GoTo start
    Thank you for your responses
    Last edited by ice; - 4th May 2005 at 10:55.

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