How to make working one HCTL2016 and a PIC16F876


Closed Thread
Results 1 to 4 of 4
  1. #1
    hawk72501's Avatar
    hawk72501 Guest

    Unhappy How to make working one HCTL2016 and a PIC16F876

    Hi to everyone! I am a newbie at PIC16F876 and i have a project to make(that's why i am not swimming at a beach now!snif,snif)

    The problem is the following:
    I have an incremental encoder (AGI HEDL-5540 A11) connected with a motor (maxon).And i want to take the pulses that the encoder sends and save it as a number in the PIC16F876. Somebody told me that HCTL2016
    makes that.Reading the manual i made the right connections but i am stuck with the code in PIC that is required.Every pin like PORTB.0,PORTB.1..... have 0 or 1 as i understood.But iam save it as a whole number in 1 register!And the manual says that HCTL2016 is 16-bit.So must it the number of a position be send in two cycles?Please help me!

    I would really really...appreciate if you could give me some bit of code to understand.Thanks anyway in advance

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


    Did you find this post helpful? Yes | No

    Default

    mmm, can you tell more about what you want to do with the rotary encoder???

    i'd never use this IC and i believe we can remove it and connect the encoder directly to the PIC.

    I often use rotary encoder in my apps to navigate between menu and/or get user entry. So an extra IC should be motivated by something that i don't see/understand.

    Bellow is one example to use rotary encode to increment/decrement a variable
    Code:
        ' Procedure to get value change from rotary encoder
        '
        OldPos = (PORTB & %11000000)>>6 ' get only PORTB<7:6> bits
        NewPos = OldPos 
        
        ' see if encoder has move
        ' 
        while ((NewPos==0) or (NewPos==3)) 
           NewPos = (PORTB & %11000000)>>6 ' get only PORTB<7:6> bits
           wend
        
        pause 20 ' debounce delay
     
        ' Get encoder movement
        ' --------------------
        '
        '      Rotary encoder output table (clockWise rotation):
        '      -------------------------------------------------
        '             00
        '             01 between move (half detent)
        '             11
        '             10 between move (half detent)
        '
        '     Using XOR
        '
        '               OldPOS   : 0     0     3     3
        '               NewPos   : 1     2     1     2
        '               movement : CW   CCW   CCW    CW
        '           XOR -------------------------------
        '                          1     2     2     1
        '
        ' So, if NewPos XOR OldPos = 1 => increment
        '        Newpos XOR OldPos = 2 => Decrement    
        '
        Newpos=newpos ^ oldpos 
        select case newpos
    
               case 1
                   menuchoice=menuchoice+1
    
               case 2
                   menuchoice=menuchoice-1
    
         end select
    Last edited by mister_e; - 9th July 2005 at 13:21.
    Steve

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

  3. #3
    hawk72501's Avatar
    hawk72501 Guest


    Did you find this post helpful? Yes | No

    Unhappy

    Thanks for answering.I don't want nothing extreme.Just to have a number in PIC16F876(for example 16 degrees or 352.16 degrees,something like that) how many degrees the motor turned. The concept is to make a PD controller.But in order to make the PD controller i must subtract the desire degrees of rotating the motor (turn 5 degrees) with the actual.And i want to control the actual degree.The first i made it with a SERIN2.They said to me that the encoder gives pulses and in order to make them 0 or 1 i must have the HCTL.Is that wrong?

    i really didn't understand much from your code (f.e what is >>6).Can you be please more specific?Sorry but i am now beginning....
    Last edited by hawk72501; - 9th July 2005 at 13:28.

  4. #4
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    hawk,

    I'm sorry I have to say this,
    but how about having a look at your chips datasheets and the PBP Manual?

    i.e.
    "<<" and ">>" are described in Section 4.17.3 of the Manual
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



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