Line follower (28034) with 74hc165n
Hi all. Working on some code for a stingray based bot, currently tethered to a ppdb. I have a number of sensors working and the motors, but have a weird issue with a line follower and a 74hc165n. I have a public method that runs in its own cog that is responsible for reading a number of sensors (pub get). If I attempt to read the 165 in that cog, the result returned is always %0 or %11111111. However if read the chip in cog zero with the same statement it reads the data in correctly. I thought perhaps the stack space of the get method was too small so i doubled it and the issue persists. Any suggestions on where I should look next?
Here is the start method of the main program:
Here is the sensor reading method. hc165.read works just fine in the repeat loop above, but bombs when i run it from pub get...
This is the HC165 code... (Thanks to Microcontrolled for that!)
Thanks all in advance. I have been scratching my head over this one for a week or so already.
Here is the start method of the main program:
pub start dira[motorin1..motorcsb]:=%11101110 'motor pin output exceb csa/b DutyCycleA := DutyCycleB := 50 outa[motorENA]:=1 'turn it on outa[motorENB]:=1 'turn it on period:=50 PWM.Start 'sound and motor control pst.start(115_200,pst#DEFAULT) 'debug cognew(dubug,@stack) 'debug cognew(get,@stackb) 'get most sensors dira[speaker]:=%1 'enable speaker brownout 'startup sound clk_scale := clkfreq / 500_000 'set clk_scale based on system clock MM2125.start(MMxpin, MMypin) 'Initialize Mx2125 waitcnt(clkfreq/10 + cnt) 'wait for things to settle MM2125.setlevel 'normalize position hc165.start(hc165SHLD,hc165CLK,hc165CLKINH,hc165SER) 'start line reader HM55B.start(compassEnable,compassClock,compassData) 'start compass repeat ilf := hc165.read
Here is the sensor reading method. hc165.read works just fine in the repeat loop above, but bombs when i run it from pub get...
pub get repeat 'xbeedata := xb.rxDECtime(100) distance := ping.Millimeters(PINGPin) 'ilf := hc165.read 'unable to run in same cog? why? mmx := MM2125.Mx 'get RAW x value mmy := MM2125.My 'get RAW y value mmra := MM2125.ro 'Get raw value for acceleration mmra := mmra / clk_scale 'convert raw acceleration value to mg's mmt := MM2125.theta 'Get raw 32-bit deg mmt := mmt >> 24 'scale 32-bit value to an 8-bit Binary Radian mmt := (mmt * 45)/32 'Convert Binary radians into Degrees mmxt := MM2125.MxTilt mmyt := MM2125.MyTilt RawHeading := HM55B.Theta ' Read RAW 13-bit Angle CorrectHeading := Calibrate.Correct(RawHeading) ' Calibrate Correct Heading Deg := CorrectHeading * 45 / 1024 ' Convert 13-Bit Angle to Deg ' Note: This only makes it easier for us Humans to read
This is the HC165 code... (Thanks to Microcontrolled for that!)
VAR byte data byte SHLD,CLK,CLKINH,SER word chipcount PUB Start(_SHLD,_CLK,_CLKINH,_SER) SHLD := _SHLD CLK := _CLK CLKINH := _CLKINH SER := _SER dira[SHLD]~~ dira[CLK]~~ dira[CLKINH]~~ dira[SER]~ PUB Read return ReadExplicit(SER) PUB ReadExplicit(serial_pin) | i outa[CLKINH]~~ outa[SHLD]~ outa[CLK]~ outa[SHLD]~~ outa[CLK]~~ waitcnt(clkfreq/300 + cnt) outa[CLK]~ outa[CLKINH]~ 'repeat i from 1 to 8 repeat 8 outa[CLK]~~ data := data << 1 + ina[serial_pin] outa[CLK]~ waitcnt(clkfreq/1000 + cnt) return data
Thanks all in advance. I have been scratching my head over this one for a week or so already.
Comments
I think you would need MUCH stackb space for your get method...
-Tommy
but I think you may not need PST, and FullDuplexSerial.. at the same time.
You are correct. FDS is not used right now as the XBee object is turned off. It is called via that object to provide communication services. For debugging I prefer PST Debug, it offers some really cool functionally. I may be able to replace the FDS object used in the XBee code with debug light, but since PST Debug will be commented out when i go mobile with the robot i probably wont bother.
I haven't gotten any further with my issue yet. Ill look into the lock functions today and see if something there is useful.