Quad encoder problems


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Hey Steve,

    I have tried microcode studio and microchips mpasm. I think I might have a problem with mpasm talking to pbp or I installed something wrong. I was going to unistall everything and try again but my pbp is on a floppy and I found out my floppy drive (havent used it in years! LOL) is bad. I ordered a new one and will have it by the end of the week. Its amazing how cheap a floppy drive is these days. I also ordered my first Oscilloscope! Its only a BK precision 2120b 30mhz dual channel but it should be able to handle everything I do.

    Thanks,
    Smitty

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


    Did you find this post helpful? Yes | No

    Default

    I think others may have had the same problem. DynamoBen recently got his to work. Maybe he can help sort out whats wrong. He mentions that he "changed the registry", but no specifics. Not having had a problem with my setup, I'd just be guessing.

    The other alternative is writing the interrupt routine is ASM. Better to get your compiler/assembler arrangement working properly.

    Steve

  3. #3
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I got it to compile!!! Using microcode studio. Happy dance. LOL

    On a down note, it dosnt do anything. The LCD has a value of 0 for both encoders. I tried switching the a&b channels and still nothing. I checked all my connections and everything looks good. I am using a 16F876A now instead of the 16F628. I need to check those pins and see if anything needs to be turned off.

    I think I am getting close!

    Thanks,
    Smitty

  4. #4
    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 to compile!!! Using microcode studio. Happy dance. LOL

    Once you check over the hardware to eliminate any problems there, then post the code you are using. Lots of folks can help out with that!

    Steve

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


    Did you find this post helpful? Yes | No

    Default

    Hey Steve, seems we use the same source for this 'Dancing Awesome'
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=881&d=1148640458">
    Steve

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

  6. #6
    Join Date
    Sep 2006
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    LOL, Thanks for the help and support guys!

    Here is the run down

    Code from Steve on post 12 works but looses count if rotated too fast so I know the circuit is good.

    I then went to the code in post 6 with both asm routines and compiled it with microcode studio. Compiled fine. The only things I changed in the code from post 6 was adding:
    DEFINE OSC 20
    PAUSE 1000
    SEROUT2 on PORTB.0 FOR LCD clear

    SEROUT2 ON PORTB.0 FOR DISPLAY

    Here it is:

    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!!!
    '************************
    DEFINE OSC 20
    PAUSE 1000 'Pause for LCD Power up

    SEROUT2 PORTB.0, 84,[254, 88] 'Clear LCD

    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler INT_INT, _Rot_Encoder, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    @ INT_ENABLE RBC_INT ;RB Port Change Interrupt

    Old_Bits = PORTB & (%11110000)
    Main:
    SEROUT2 PORTB.0, 84,[254, 71, 1, 1, "ROT1:", DEC2 RotEnc1_val,"ROT2:",_
    DEC2 RotEnc2_val]
    pause 10
    GOTO Main

    '---[RBC - interrupt handler]---------------------------------------------------
    Rot_Encoder:
    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
    @ INT_RETURN


    The LCD comes up and displays ok. Then when I rotate an encoder, sometimes I get a little garbage on the screen and then it just seams to hang. I can go thru many restarts before the LCD will display properly again. It kinda seams like the chip is stuck. Is that possible even though I disconnect power and then reconnect? Is the pic holding something in memory where it hangs? I am using a 16F876A

    Thanks guys!
    Smitty

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


    Did you find this post helpful? Yes | No

    Default

    OK, I found an error in the interrupt setup. Make the change highlighted in red.

    Code:
    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
              INT_Handler RBC_INT, _Rot_Encoder, PBP, yes
         endm
         INT_CREATE ; Creates the interrupt processor
         INT_ENABLE RBC_INT ;RB Port Change Interrupt
    ENDASM
    I tried this out on a 16F877a (since I don't have your model). Worked fine with the one encoder I have available hooked to Rot1. Don't see any reason it wouldn't work with both hooked up.

    Steve

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