Shop OBEX P1 Docs P2 Docs Learn Events
Line follower (28034) with 74hc165n — Parallax Forums

Line follower (28034) with 74hc165n

rogersydrogersyd Posts: 223
edited 2012-03-11 05:12 in Robotics
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:
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

  • TtailspinTtailspin Posts: 1,326
    edited 2012-03-10 06:54
    Need to see all of the code in this case, Want to see how big stack, and stackb are,
    I think you would need MUCH stackb space for your get method...


    -Tommy
  • rogersydrogersyd Posts: 223
    edited 2012-03-10 08:10
    Archive attached. Thanks for having a look. When I double the stack space available for the cog running the method the issue persists which has me going in another direction. Perhaps the debug method is stepping on the variable when it attempts to read it? Ill have to break out the books and look into the more closely. There is probably something silly I am over looking.
  • TtailspinTtailspin Posts: 1,326
    edited 2012-03-10 22:52
    Rogersyd, I am not familiar with PST Debug LITE, I have not tried to use this.
    but I think you may not need PST, and FullDuplexSerial.. at the same time.
    OBJ
    '  motor       : "UK1122"
      Ser         : "FullDuplexSerial"             'cog1 started in XB (listed in this obj section fyi)
      MM2125      : "Memsic2125_v1.2"              'cog2
      HM55B       : "HM55B Compass Module Asm"     'cog3
      Calibrate   : "HM55B Compass Calibration"    'no cog
      PWM         : "PWM_32_V4.spin"               'cog4
      ping        : "ping.spin"                    'no cog
      pst         : "PST Debug LITE"               'no cog
    '  XB          : "XBee_Object_2"                'no cog uses FDS cog
      hc165       : "165"                          'no cog
                                                   'cog5 debug cog
                                                   'cog6 get sensor data cog
    
  • rogersydrogersyd Posts: 223
    edited 2012-03-11 05:12
    Hi Ttailspin,

    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.
Sign In or Register to comment.