beautypg.com

4 encoder functions – Sensoray 2410 API User Manual

Page 34

background image

Sensoray 24xx Programming Guide

30

Model 2426 Multi-Function I/O Module

7.4 Encoder Functions

7.4.1 s2426_ReadEncoderCounts()

Function:

Read the encoder counter.

Prototype:

BOOL s2426_ReadEncoderCounts( SESSION sess, u32 *err, u32 *counts, u32 *timestamp );

Returns:

True if the operation was successful, otherwise False is returned and

err

will contain the associated error code.

Notes:

Upon exit,

counts

will contain a snapshot of the encoder counter.

Example:

// Get current counts from counter.

u32 err = ERR_NONE;
u32 counts;

if

( !s2426_ReadEncoderCounts( sess, &err, &counts, NULL ) )

printf( "Error: %s\n", s24xx_ErrorText(err) );

Example:

// Get counts and timestamp.

u32 err = ERR_NONE;
u32 counts;
u32 tstamp;

if

( !s2426_ReadEncoderCounts( sess, 12, 3, &counts, &tstamp ) )

printf( "Error: %s\n", s24xx_ErrorText(err) );

else

printf( "counts=%d at t=%d microseconds\n", counts, tstamp );

7.4.2 s2426_WriteEncoderMode()

Function:

Program the encoder interface operating mode.

Prototype:

BOOL s2426_WriteEncoderMode( SESSION sess, u32 *err, u32 clock, u32 preload );

Returns:

True if the operation was successful, otherwise False is returned and

err

will contain the associated error code.

Argument

Description

sess

Session handle obtained from

s24xx_SessionOpen()

.

err

Pointer to error code. See Section 4.3.1 for details.

counts

Pointer to buffer that is to receive the counts.

timestamp

Pointer to buffer that will receive the timestamp. The timestamp is a snapshot of the
I/O module’s system timer at the moment

counts

is sampled. Set to NULL if the

timestamp is not needed. See section 5.6 for more information about timestamps.

Argument

Description

sess

Session handle obtained from

s24xx_SessionOpen()

.

err

Pointer to error code. See Section 4.3.1 for details.

clock

Counter clock mode. Specify one of these values:

NONQUADRATURE -

single clock phase (e.g., tachometer)

QUADRATURE_X1 -

quadrature clock (e.g., encoder), count at clock frequency

QUADRATURE_X2 -

quadrature clock, count at two times the clock frequency

QUADRATURE_X4 -

quadrature clock, count at four times the clock frequency

preload

Specifies whether an active edge on the index input will cause the counter to be parallel
loaded from the preload register. Specify one of these values:

ENC_PRELOAD_DISABLE -

index active edge does not cause counts change

ENC_PRELOAD_ENABLE -

index active edge causes counts to change to preload value