Shop OBEX P1 Docs P2 Docs Learn Events
74HC165 confusion! — Parallax Forums

74HC165 confusion!

eagletalontimeagletalontim Posts: 1,399
edited 2013-10-05 02:35 in Propeller 1
Good evening all! I am tinkering with a 74HC165 and using the code posted below. When viewing the serial terminal, the output is either all 1's or all 0's.
_CLKMODE = XTAL1 + PLL16X                            
  _XINFREQ = 5_000_000                                


  
  CLOCK = 17                     ' Connected to pin 2 of 74HC165
  LOAD = 16                      ' Connected to pin 1 of 74HC165
  DATA  = 18                     ' Connected to pin 9 of 74HC165 (for inverted data use pin 7)
                                ' The data pin should be connected to the Propeller with
                                ' a 4.7K Ω series resistor.
  BITS_IN = 8

  
  DEBUG_BAUD = 9_600

  DEBUG_HEADING_X = 2          ' Output formatting data
  DEBUG_HEADING_Y = 2
  DEBUG_DYNAMIC_X = DEBUG_HEADING_X + 8
  DEBUG_DYNAMIC_Y = DEBUG_HEADING_Y + 2
  
VAR

  long xInputs 
  
OBJ

  Pst :  "Parallax Serial Terminal"
   
PUB Setup

  Pst.Start(DEBUG_BAUD)
  waitcnt(clkfreq * 3 + cnt)  ' time to open serial terminal
  
  dira[CLOCK] := 1
  outa[LOAD] := 1
  dira[LOAD] := 1
  
  Pst.Clear
  Pst.Position(DEBUG_HEADING_X, DEBUG_HEADING_Y)
  Pst.Str(string("xInputs FEDCBA9876543210", 13))
  Pst.PositionX(DEBUG_HEADING_X)
  Pst.Str(string("------- ----------------", 13))
  Pst.PositionX(DEBUG_HEADING_X)
  Pst.Str(string("Status  ................"))
  MainLoop
  
PUB MainLoop
  
  repeat
    xInputs := 0                                        ' clear variable to hold input states
    outa[LOAD] := 0
    outa[LOAD] := 1
    repeat BITS_IN
      xInputs <<= 1
      xInputs += ina[DATA] 
      outa[CLOCK] := 1
      outa[CLOCK] := 0
    Pst.Position(DEBUG_DYNAMIC_X, DEBUG_DYNAMIC_Y)
    Pst.Bin(xInputs, BITS_IN)

I am attempting to read 7 switches that output 12V +. I have voltage divider circuits on each input pin that drops the voltage to 2.99V per input pin. The 165 is being powered from the 3.3V rail. The only time I am getting a reading is when I either ground or bring high the 8th input or input "H". According to the datasheet, "Unused inputs must always be tied to an appropriate logic voltage level (e.g., either GND or VCC)." I am using the 3 pin connection method to the Prop : Load, Clock, and Pin 9 on the 165 as the data.

What I am trying to accomplish is to get which pin is high, then run a "CASE" using the select case method according to what pin is high. If more info is needed, please feel free to ask.

Comments

  • eagletalontimeagletalontim Posts: 1,399
    edited 2013-10-04 23:07
    Nevermind :P I had the Load and Clk pins reversed on my circuit board. Need to find some different color wires!
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-10-05 02:35
    This is a method for x165s that I use in a couple products.
    pub x165_in(bits, shiftmode) | work
    
    '' Input value from 74x165(s)
    '' -- takes about 91us @ 80MHz      
                                                                                              
      outa[LD_165] := 0                                             ' load inputs   
      outa[LD_165] := 1                                                                          
                                                                                              
      work := 0                                                     ' clear workspace
      bits := 1 #> bits <# 32                                       ' limit to legal value         
      repeat bits                                                   ' read n bits         
        work := (work << 1) | ina[DO_165]                           ' get new bit             
        outa[CLK_165] := 1                                          ' blip clock              
        outa[CLK_165] := 0  
    
      if (shiftmode == LSBFIRST)                                    ' LSBFIRST result?
        work ><= bits                                               ' reverse bits
    
      return work
    
Sign In or Register to comment.