Quad encoder problems


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Smitty,
    Try this on your cmd line:

    pbpw -p16f628 -ampasmwin yourfilename

    The trouble is actually two fold.
    1) PBP is DOS based, and does not like long file names. PBPW is ok with them.
    2) You need to use the MPASM assembler. So make sure it is installed before you run the above line! It is needed for the Macros, as well as if you make the switch to the 18F series.

    Out of curiosity, why not use MicroCode Studio?

    Good Night,
    Steve B

    EDIT: Use the name for your file on the above cmd line
    Last edited by SteveB; - 10th September 2006 at 14:18.

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by SteveB
    Smitty,
    .....
    Out of curiosity, why not use MicroCode Studio?
    .....
    Hi Smitty,

    As Steve B also asks about it here, is there a particular reason why you are not using MicroCode Studio?

    Also, for the encoder , don't you think that you can do what you need with one direction?

    If you think you can, then I can give you some piece of code for TMR1 and TMR0 so that you can set it up for reading the encoder, and suggest some ways of having the missing counts minimized.

    In your case, as much as I understood it, the degrees needed are wide enough to cover the missing counts.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default 7 hours and still trying

    I just tried microcode studio and get the same errors. Cant find 16F628.inc

    This file is in the pbp directory, I do not understand.

    sayzer, Thanks for the offer but I do need both directions to be able to tell if it is a right or left roll ,an up or down pitch and how far for both.

    Microcode studio is pretty sweet I must say. Thanks for recommending it.

    Smitty

  4. #4
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    You did restart your computer, right? Well, if we don't have any success going that route, there are alternatives.

    Look at the code in the Interrupt Handler. Put this in your main loop, so it repeatedly checks PORTB for changes. Like This:

    Code:
    '************************
    '  DEFINE your OSC 
    '  and any other
    '  configuation items
    '************************
    
    
    Old_Bits       VAR BYTE
    New_Bits       VAR BYTE
    RotEnc1_val    VAR BYTE  'Connected to PORTB<4:5>
    RotEnc2_val    VAR BYTE  'Connected to PORTB<6:7>
    TRISB = %11110000
    RotEncDir      VAR BIT
    
    '************************
    ' SETUP YOUR LCD HERE!!!
    '************************
    
    Old_Bits = PORTB & (%11110000)
    
    Main:
         New_Bits = PORTB & (%11110000)
         IF (New_Bits & %00110000) = (Old_Bits & %00110000) then No_Change_Rot1
         RotEncDir = New_Bits.5 ^ Old_Bits.4
         if RotEncDir = 1 then
              RotEnc1_val = RotEnc1_val + 1
              if RotEnc1_val = 36 then RotEnc1_val = 0
         ELSE
              RotEnc1_val = RotEnc1_val - 1
              if RotEnc1_val = 255 then RotEnc1_val = 35
         ENDIF
    No_Change_Rot1:
         IF (New_Bits & %11000000) = (Old_Bits & %11000000) then DoneRotEnc
         RotEncDir = New_Bits.7 ^ Old_Bits.6
         if RotEncDir = 1 then
              RotEnc2_val = RotEnc2_val + 1
              if RotEnc2_val = 36 then RotEnc2_val = 0
         ELSE
              RotEnc2_val = RotEnc2_val - 1
              if RotEnc2_val = 255 then RotEnc2_val = 35
         ENDIF
    DoneRotEnc:
         Old_Bits = New_Bits
         
         LCDOUT $FE, 2,"ROT1:", DEC2 RotEnc1_val,"ROT2:", DEC2 RotEnc2_val
    GOTO Main



    Let's walk before we run and get this working.

    Steve

  5. #5
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Steve,
    Yup, restarted pc many times. LOL. I would really like to know what the problem is. I guess I will have to look into it further.

    You said "Look at the code in the Interrupt Handler. Put this in your main loop"

    Did you mean to compile just the code you listed or to add it to one of the others? If you meant by itself then it compiled just fine.

    I tried it out and had some strange readings. It starts with Rot1:00 and Rot2:35. When I rotate the encoders nothing happens.

    To test and see if it was the encoder or the program, I unpluged the a & b chanels from encoder 1 and alternately touched them to ground and the numbers changed. This makes me think something is wrong in the encoder circuit. I played arround with different values on the resistors to no avail. The encoders output a positive voltage between ~1.85 and 5 and I have 4.7K resistors pulled to ground on each channel.

    I did notice if I was under a bright light and held the encoders at just the right angle the numbers changed but they were jumping arround and not going 1.2.3.4~.

    Man I didnt think encoders were so tough.

    Smitty

  6. #6
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Smitty,

    You said "Look at the code in the Interrupt Handler. Put this in your main loop"

    Did you mean to compile just the code you listed or to add it to one of the others? If you meant by itself then it compiled just fine.
    Just use the "new code" in the last post by itself (I did the moving for you).

    It starts with Rot1:00 and Rot2:35
    Add something like this just below the variable declarations to give an initial starting value.

    RotEnc1_val = 0
    RotEnc2_val = 0


    OK. Do you have the datasheet for the encoders? I assumed (always bad) that they where mechanical encoders, similar to the one shown here. Hook-up as per the nice diagram.

    If they are not mechanical encoders, then they are optical. If so, they will have a Vcc, GND, ChA, and ChB. Also, no pull-ups (or downs) required.

    At least it looks like the code is working. More info please.

    Steve

  7. #7
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Ok, I did just use the code by itself and I understand setting the variables to =0. Off to a good start

    The encoders are optical with no data sheet since I pulled them out of a ball mouse. There is an emitter, wheel with 36 slots, and reciever for each encoder. They are in the same mounting positions as when the mouse was a mouse. I just chopped off the pc board behind them and attached my wires. The emitters only have 2 pins, +5v and ground. The recievers have 3 pins, A,B, & +5v. I know this because I traced them back on the mouse board before cutting. I also checked another mouse to be sure. (I bought 4 of them to play with).

    With my original code (the really simple one a few posts back) nothing happened until I put in the resistors to ground. Thats the only reason they are in the circuit. The read out on the lcd also displayed channel A and B status and I could see 00 01 11 10 00 when rotated very slowly.

    I did try your code without the resistors and it didnt make any difference.

    I agree with you when you say we need to walk before we run. So I checked the outputs of the encoders with a logic probe. I am getting a high/low pulse out of each of the channels when they are rotated.

    Smitty

  8. #8
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by smitty505000
    So I checked the outputs of the encoders with a logic probe. I am getting a high/low pulse out of each of the channels when they are rotated.
    What voltage do they output on the channels? I haven't hacked any mouse encoders, so a google on that (or someone else on this forum who has could chime in) could help make sure the hardware portion is working properly.

    I do know the code is working now. I scared up 2 mech encoders, and hooked them up to an 18F4620 I have. Using the internal pull-ups on port B, worked without a hitch. I see no reason it wouldn't work on the 16F628.

    Steve

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by smitty505000
    The encoders output a positive voltage between ~1.85 and 5 and I have 4.7K resistors pulled to ground on each channel.
    So it's never 0V? @1.85 you're probably sometimes in-between Low and High logic Level. You may need to 'filter' it a little bit to avoid oddity.

    1.Use the internal voltage comparator, set the threshold and use their interrupt to increment the counter.
    OR
    2.try something like...
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1067&stc=1&d=115794620 6">
    maybe one diode could be enough... maybe not
    HTH
    Attached Images Attached Images  
    Last edited by mister_e; - 11th September 2006 at 04:54.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I got it working! Sort of. I played arround with different value resistors and some diodes as sugested by mister_e and ended up with 30K resistors. Also seams my pic16f628-20p dosnt have a very accurate osc in it. I hooked up an external resonator and it works at 20mhz using Steve's slightly modified code from post #12. Thanks Steve!
    The only thing now is it sometimes skips or looses count. Either the pic running at 20mhz cant keep up or the infrared red rx cant keep up. These encoders came out of a PS2 computer mouse. The ones that turn off the ball.

    Any ideas guys?

    Thanks!
    Smitty

  11. #11
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by smitty505000
    I got it working! Sort of. I played arround with different value resistors and some diodes as sugested by mister_e and ended up with 30K resistors. Also seams my pic16f628-20p dosnt have a very accurate osc in it. I hooked up an external resonator and it works at 20mhz using Steve's slightly modified code from post #12. Thanks Steve!
    The only thing now is it sometimes skips or looses count. Either the pic running at 20mhz cant keep up or the infrared red rx cant keep up. These encoders came out of a PS2 computer mouse. The ones that turn off the ball.

    Any ideas guys?

    Thanks!
    Smitty

    Now your walking, time to RUN!! Go back to post #6 and give the interrupts a try. With the optical encoders and interrupts, you should have not any switch bounce, and you should also not have any "skips". Well, if it turns faster than the interrupts can process the inputs, you can have some skips, but the nice thing about the interrupts is that the updates to the rotarty encoders count will not "wait" on the LCD output to finish.

    Give it a shot,
    Steve
    Last edited by SteveB; - 17th September 2006 at 02:01.

Similar Threads

  1. Quadrature encoder and ASM Interrupts. questions..
    By godfodder in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th March 2013, 14:45
  2. Instant Int and encoder (Elect. Gearing)
    By boroko in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 29th November 2009, 02:29
  3. encoder HEDL 5540
    By kutsi in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th June 2007, 14:00
  4. quad encoders
    By cpayne in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 13th March 2007, 17:49
  5. encoder wowes
    By wallaby in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 6th December 2005, 21:56

Members who have read this thread : 0

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