Monday, February 20, 2012

Day Twenty-Five

Had meeting today on what needed to get done this week. I'm going to continue working on incorporating the Z-channel to show direction of movement, with A- and B-channels doing the counting. I think.

Edit: Scratch the Z-channel; it wont tell direction. Moved onto a tangent. Found a Quadrature_Encoder program that can control 16 encoders at once. I'm using its example code to fashion a usable program from it.


{{
* File: ReadEncWithQuad.Spin
* Name: Palak Shah
* Date: February 20, 2012
*
* Desc: Attempt to read the values recorded by the microcontroller 
*       as inputted by the encoder. 
}}
CON
  _xinfreq = 5_000_000
  _clkmode = xtal1 + pll16x


OBJ
  Encoder : "Quadrature Encoder"
  FDSP : "FullDuplexSerialPlus"


VAR
  long Pos[6]  'Create buffer for 5 encoders (plus room for delta 
               'position support of 1st encoder)
  long AbsPos, Delta1


PUB Init
  Encoder.Start(20, 5, 1, @Pos) 
               'Start continuous two-encoder reader (encoders 
               'connected to pins 20-26)
  
PUB Main
  Comm


  repeat
    AbsPos := Pos[0]                 'Read each encoder's absolute position
    Delta1 := Encoder.ReadDelta(0)   'Read 1st encoder's delta position 
                                     ' (value since last read)
    Output


PUB Comm
  FDSP.Start (31,30,0,57600)
  waitcnt(clkfreq * 3 + cnt)
  FDSP.tx(16)
  FDSP.str(String("'Encoder Reader' by Palak Shah"))
  FDSP.tx (13)
  FDSP.tx (13)


PUB Output
  FDSP.bin(AbsPos, 16)
  FDSP.tx (13)
  FDSP.bin(Delta1, 16)
  FDSP.tx (13)  

No comments:

Post a Comment