Shop OBEX P1 Docs P2 Docs Learn Events
9 bit optical encoder input to SX28 or how to read the ports — Parallax Forums

9 bit optical encoder input to SX28 or how to read the ports

frankhaertleinfrankhaertlein Posts: 1
edited 2008-02-01 21:35 in General Discussion
I need help on this one...............

Am learning to program the SX chips·so I'm not sure of how to read 9 input pins at once. I've got a rotary optical encoder giving me 9 bits in parallel that represent 0 to 360 Degrees of rotation. I need to use 9 pins to read the encoder as it doesn't have a serial output.

Does anyone know the instruction that would read 9 pins at one time and store the state (1 or 0, high or low status) of each pin? I'm looking to·develop a binary number 9 digits long like 101010101 to use in the code I'm writing. I would then convert this binary number to degrees rotation·as a·decimal number.

Let me say thanks in advance to anyonethat can help me with this one.

Comments

  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2008-02-01 20:12
    I would use·(2) cascaded 74HC165 Parallel-in/Serial-out shift register·IC's (8 inputs + 1 input)·and connect the rotary optical encoder to the ICs and then have (1) serial word going into (1) pin on the SX chip. However, if you have plenty of I/O then you can skip the (2) cascaded ICs.
    Something like this...
     
    Clock            VAR     RA.5    ' shift clock (74HC165.2)
    SerData          VAR     RA.6    ' serial data (74HC165.7)
    Load1             VAR     RA.7    ' input load (74HC165.1)
     
    switches         VAR     BYTE   'Probably can change this to a WORD
     
    Get_165:
      PULSOUT Load1, 50                             ' load switch inputs
      SHIFTIN SerData, Clock, MSBPRE, switches      ' shift them in
      RETURN
     
    DO
    Get_165   'Read 74HC165 button inputs
    PAUSE 200
        IF switches.1 = 1 THEN   'Check upper button and increment hours
        INC tmpB3
    ENDIF
    IF switches.2 = 1 THEN   'Check 2nd button and decrement hours
        DEC tmpB3
    ENDIF
    IF switches.0 = 1 THEN   'Ready...Go to the next selection (Minutes setting...)
      GOTO HRS_EXIT_HERE
    ENDIF
    LOOP
    
    

    ·
  • Doug HaleDoug Hale Posts: 23
    edited 2008-02-01 20:23
    If you don't have the pins to directly read all 9, instead of using other chips to "multiplex" the pins, just use another SX - then you can move some of the programming to th second SX, simplifying the first one.

    These things were designed/marketed to be Virtual Periferals - use them like that - use them as their own extenders.
  • BeanBean Posts: 8,129
    edited 2008-02-01 21:35
    I would read it as 8+1 like this (assume the encoder is connected to pins RB.0 thru RB.7 + RC.0

    encoder VAR WORD

    encoder = RBC AND 511

    Note that RBC is a virtual 16 bit I/O port. It is actually read as two seperate reads, so you have to make sure the value from the encoder doesn't change between the reads.


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
Sign In or Register to comment.