Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

mcu/encoder.c File Reference

#include "encoder.h"
#include "registers.h"

Go to the source code of this file.

Defines

#define ctrlH_dataL   (1 << 0)
#define writeL   (1 << 1)
#define chipsel_U9L_U8H   (1 << 2)
#define readL   (1 << 3)
#define axis_XL_YH   (1 << 4)
#define encDATA_DDR   DDRP
#define encDATA   PORTP
#define encCONTROL_DDR   DDRDLC
#define encCONTROL   PORTDLC
#define DATA   0
#define CTRL   4

Functions

static void delay (void)
 Simple function to add delay when doing bus reads or writes.
void encOut (unsigned char port, unsigned char val)
 Write an 8 bit value to one of the encoder chip registers .
unsigned char encIn (unsigned char port)
 Reads an 8 bit value from the one of the encoder registers.
void encLoadPR (unsigned char port, unsigned long val)
 load first 24 bits of val into the preset register (PR)
void encStart (void)
 Initialize for both encoder chips.
unsigned long encRead (unsigned char port)
 Reads a the count of a specific encoder.


Define Documentation

#define axis_XL_YH   (1 << 4)
 

Definition at line 34 of file encoder.c.

Referenced by encIn(), and encOut().

#define chipsel_U9L_U8H   (1 << 2)
 

Definition at line 32 of file encoder.c.

Referenced by encIn(), and encOut().

#define CTRL   4
 

Definition at line 55 of file encoder.c.

Referenced by encIn(), encLoadPR(), encOut(), encRead(), and encStart().

#define ctrlH_dataL   (1 << 0)
 

Definition at line 30 of file encoder.c.

Referenced by encIn(), and encOut().

#define DATA   0
 

Definition at line 54 of file encoder.c.

Referenced by encLoadPR(), and encRead().

#define encCONTROL   PORTDLC
 

Definition at line 39 of file encoder.c.

Referenced by encIn(), and encOut().

#define encCONTROL_DDR   DDRDLC
 

Definition at line 38 of file encoder.c.

Referenced by encStart().

#define encDATA   PORTP
 

Definition at line 37 of file encoder.c.

Referenced by encIn(), and encOut().

#define encDATA_DDR   DDRP
 

Definition at line 36 of file encoder.c.

Referenced by encIn(), encOut(), and encStart().

#define readL   (1 << 3)
 

Definition at line 33 of file encoder.c.

Referenced by encIn(), and encOut().

#define writeL   (1 << 1)
 

Definition at line 31 of file encoder.c.

Referenced by encIn(), and encOut().


Function Documentation

static void delay void   )  [inline, static]
 

Simple function to add delay when doing bus reads or writes.

Author:
<Derek>

Definition at line 48 of file encoder.c.

Referenced by encIn(), encOut(), and RTAI_PROTO().

unsigned char encIn unsigned char  port  ) 
 

Reads an 8 bit value from the one of the encoder registers.

Long Description if necessary.

Parameters:
<port> <encoder register="" to="" read="" from>="">
Returns:
<8bit value that was read>
Author:
<Derek>

Definition at line 130 of file encoder.c.

References axis_XL_YH, BACK, chipsel_U9L_U8H, CTRL, ctrlH_dataL, delay(), encCONTROL, encDATA, encDATA_DDR, LEFT, readL, and writeL.

Referenced by encRead().

void encLoadPR unsigned char  port,
unsigned long  val
 

load first 24 bits of val into the preset register (PR)

Since data can be moved to the LS7266 only 8bits at a time the preset register acts as a 24 bit temporary buffer. Three bytes are loaded into the preset register and then the 24 bit value can be moved into the 24 enocder count register, or the clock prescaler. (This function only loads the PR, moving the value to another register is up to you)

Parameters:
<port> <encoder preset register to load (0-3}>
<value> <lower 24 of value are loaded into PR>
Returns:
<on return="" the="" pr="" is="" loaded="" with="" value>="">
Author:
<Derek>

Definition at line 184 of file encoder.c.

References CTRL, DATA, and encOut().

Referenced by encStart().

void encOut unsigned char  port,
unsigned char  val
 

Write an 8 bit value to one of the encoder chip registers .

The port allows you to select chip, axis, and register the value will be loaded into. The enocoder board has two LS7266 IC's, that are address seperately. Each LS7266 IC has two identical register sets (axis's) that allow it two keep track of two encoder inputs. Either the data register one of the control registers can be selected. When writing one of the control registers the 5th and 6th bit of the data value (val) determine which control register to write

bit 6 | bit 5 | control register 0 0 RLD (reset and load signal decoders) 0 1 IOR (input/output control register) 1 0 CMR (counter mode register) 1 1 IDR (index control register)

Parameters:
<port> <register to="" write="" to>="">
<val> <8bit value to write>
Author:
<Derek>

Definition at line 84 of file encoder.c.

References axis_XL_YH, BACK, chipsel_U9L_U8H, CTRL, ctrlH_dataL, delay(), encCONTROL, encDATA, encDATA_DDR, LEFT, readL, and writeL.

Referenced by encLoadPR(), encRead(), and encStart().

unsigned long encRead unsigned char  port  ) 
 

Reads a the count of a specific encoder.

Each encoder count is a 24 signed number. For the port use the <FRONT, BACK, RIGHT, LEFT> constants in encoder.h For Example, to get the value of the front left encoder use: encRead(FRONT + RIGHT);

<port> <which encoder to read (0-3)>

Returns:
<24 bit encoder count value>
Author:
<Derek>

Definition at line 297 of file encoder.c.

References CTRL, DATA, encIn(), and encOut().

Referenced by main().

void encStart void   ) 
 

Initialize for both encoder chips.

Each chip handles two encoder inputs each. There are many setting options, see the spec sheet for the encoders before changing anything.

Parameters:
<nothing> 
Returns:
<nothing>
Author:
<Derek>

Definition at line 216 of file encoder.c.

References BACK, CTRL, encCONTROL_DDR, encDATA_DDR, encLoadPR(), encOut(), FRONT, LEFT, and RIGHT.

Referenced by main().


Generated on Fri Sep 1 14:25:55 2006 for Raptor by  doxygen 1.4.4