Trying to make very simple code to read 74HC165
AGCB
Posts: 330
in Propeller 1
Trying and trying but no good yet.
Thanks
Aaron
CON _clkmode = xtal1 + pll16x ' use crystal x 16 _xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clockP = 80 MHz) 'Simple code to read in data from 74HC165 with DIP switch clockP = 19 'clock pin (low to high edge triggered) loadP = 18 'parallel load Pin (active low) dataP = 16 'data pin Receives data from 165 obj TV : "TV_text" VAR byte winput long data_in PUB main tv.start(0) waitcnt(clkfreq +cnt) outa[loadP]~~ 'preset load pin high dira[loadP]~~ ' make load pin output dira[clockP]~~ ' make clock pin output repeat winput:=get_data tv.bin(winput,8) waitcnt(clkfreq*6+cnt) 'time to change switches tv.cr PUB get_data data_in:=0 ' pull clock low and single strobe to clear all outa[CLOCKP] := 0 '##strobe low to latch inputs on 165 outa[loadP] := 0 'load pin low to load data from 8 inputs wait outa[loadP] := 1 ' Must go high here wait '##loop through all inputs and stick into data_in 'MSBPRE repeat 8 'data_in := (data_in << 1) | ina[dataP] data_in :=(data_in << 1) + ina[dataP] wait PostClock(clockP) return data_in PUB wait waitcnt(clkfreq/100+cnt) PUB PostClock(_clockP) !outa[clockP] wait !outa[clockP]Can you tell me what's wrong. I don't want to use complicated objects and can't find anything much for 74HC165. This will be for a wind direction sensor with 8 magnets
Thanks
Aaron
Comments
Another note: You don't need to slow down the process by putting the delay in the clock; in Spin you'll never outrun that chip. In my HC-8+ projects I use this unrolled code to read 17 digital inputs. It's more code, but faster without the loop overhead.
So it may be a hardware problem. Have you connected the 'clock inhibit' pin (15) to ground?
Andy
and still got all 1s in the output.
As @ARIBA said " may be a hardware problem", I checked all connections and I found that for some reason I had a 10k pull up on the Q7 output pin. Removing that solved the problem!
Thank you all much!
Aaron
Edit: I should have read the last post more carefully. It looks like your code works fine. It looked fine when I read it as well.