Quick Start Guide    Motion Basic Overview     Using the Motion Basic User Interface      Language Reference

Motion Basic Functions and Subroutines

Motion Basic includes an assortment of functions and subroutines, mostly related to operating the PIC-SERVO, the PIC-STEP and the PIC-I/O controllers.  Both functions and subroutines may take a list of parameters in parentheses  (e.g. homing(1, 35)).   Functions, however, also return a value which can be either assigned to a variable or used in an expression.  The following table summarizes each subroutine and function, and provides a link to a more detailed description.

 

General Purpose Functions

getchar Returns asynchronous user input
geterr Returns number of communications errors
getnminit Initializes NMC network and returns number of modules found
getstat Returns status byte
gettype Returns module type
getver Returns module version
peek Returns contents of processer memory address
retrieve Returns contents of Motion Basic memory address
testbit Tests if specified data bit is set

General Purpose Subroutines

nmreset Resets all modules to their power up state
poke Writes data to processor memory address
refresh Refreshes module status data
store Writes data to a Motion Basic memory address

PIC-SERVO Functions

getad Returns A/D input value
gethome Returns home position
getpos Returns current position
getsvaux Returns auxiliary status byte
getsverr Returns position error
getsvvel Returns current velocity

PIC-SERVO Subroutines

homing Sets the homing parameters for capturing the home position
resetpos Resets the position counter to 0
stopmot Used to stop a motor.  Also used to enable/disable the amplifier
svcbits Clears the latched status bits
svgain Sets operating parameters
svtraj Sets motion data for position, velocity,  and PWM moves
waitmove Waits until move is complete
PIC-STEP Functions
getad Returns the A/D input value
gethome Returns home position
getpos Returns the current position
getstin Returns the inputs value
PIC-STEP Subroutines
homing Sets the homing parameters for capturing the home position
resetpos Resets the position counter to 0
stopmot Used to stop a motor.  Also used to enable/disable the amplifier
stoutput Sets general purpose output pins and internal amplifier
stparam Sets operating parameters
sttraj Sets motion data for position and velocity moves
waitmove Waits until move is complete
PIC-I/O Functions
getioad Returns the A/D input value
getioin Returns the inputs value
gettmr Returns timer/counter value
PIC-I/O Subroutines
iodir Sets direction of I/O pins
iooutput Sets I/O output pin value
iopwm Sets the PWM output values
iotimer Sets the timer/counter mode of operation

 

getchar()  # Returns asynchronous user input
Parameters
none
Returns
key ASCII value of last key pressed, or -1 if no key pressed
Example
10  X = getchar()         # get user input
    if X <> -1 goto 20    # break out of user code if key pressed
        ###               # put user code here
    goto 10               # go to start of user code loop
20      ###               # put process key code here   
Description
Users can asynchronously send a character over the RS232 or USB port while a Motion Basic program is running.  The character is saved and may be retrieved at a later time by getchargetchar returns the ASCII value of the last character received, or -1 if no character has been received since the last time getchar was called .  Note that if multiple characters are sent, getchar returns only the most recent one received.

Back To Top

 

geterr(reset)  # Returns number of communications errors
Parameters
reset 1 - reset communications error count to 0
0 - do not reset
Returns
errors Number of communications errors
Example
X = geterr(1)    # store number com errors in X, then reset error count to 0
Description
Motion Basic counts the number of PIC-SERVO, PIC-STEP, and PIC--I/O communications errors.  geterr returns the number of communications errors.  To reset the number of communications to 0, call geterr with the reset parameter set to 1.  Under normal operation, there should be no communications errors.

Back To Top

 

getnminit()  # Initializes NMC network and returns number of modules found
Parameters
none
Returns
nummod Number of modules found
Example
N = getnminit()    # Init NMC network, and store number modules in N
Description
getnminit initializes the NMC network, and returns the number of PIC-SERVO, PIC-STEP, and PIC-I/O modules found.

Back To Top

 

getstat(addr)  # Returns status byte
Parameters
addr Module address (1-8)
Returns
status PIC-SERVO Status Byte Definition (see PIC-SERVO data sheet)
Bit 1 - Move done
Bit 2 - Checksum error
Bit 3 - Current limiting has occurred (must clear with svcbits)
Bit 4 - Motor power on
Bit 5 - Position error exceeds position error limit (must clear with svcbits).  Note: the PID servo
                 must be enabled using stopmot before this bit can be cleared using svcbits.
Bit 6 - Limit switch 1 value
Bit 7 - Limit switch 2 value
Bit 8 - Homing in progress
PIC-STEP Status Byte Definition (see PIC-STEP data sheet)
Bit 1 - Motor is moving
Bit 2 - Checksum error
Bit 3 - Amplifier enable output is HIGH
Bit 4 - Power sense input is HIGH
Bit 5 - Motor at speed
Bit 6 - Velocity mode enabled
Bit 7 - Trapezoidal mode enabled
Bit 8 - Homing in progress
PIC-I/O Status Byte Definition (see PIC-I/O data sheet)
Bit 2 - Checksum error
Example
10   refresh(1)                      # refresh module 1 status data
    X = getstat(1)                   # get the status byte
    if testbit(X, 8) = 1 goto 10     # loop while homing bit set
        ###                          # homing completed code goes here
Description
getstat returns a module's status byte.   The status byte consists of a set of status bits corresponding to status information such as check sum error or homing in progress.  The status information returned depends on the module type -  see the PIC-SERVO, PIC-STEP, and PIC-I/O data sheets for a more detailed description of the status byte bit field definitions.

Back To Top

 

gettype(addr)  # Returns the module type
Parameters
addr Module address (1-8)
Returns
type 0 - PIC-SERVO module
2 - PIC-I/O module
3 - PIC-STEP module
Example
X = gettype(1)    # get the module type
Description
gettype returns the module type.

Back To Top

 

getver(addr)  # Returns the module version
Parameters
addr Module address (1-8)
Returns
version Version of PIC-SERVO, PIC-STEP, or PIC-I/O module
Example
X = getver(1)    # get the module version
Description
getver returns the module version.

Back To Top

 

peek(addr)  # Returns contents of processor data memory
Parameters
addr Data memory address (0 - 4095)
Returns
mem Contents of specified memory address
Example
print "ADCON1 = ",  peek(4033)    # print contents of ADCON1 register
Description
peek returns the contents of the specified address in PIC18F2610 data memory.  PIC18F2610 data memory is composed of Special Function Registers (SFRs) used for control and status of the controller and peripheral functions, and General Purpose Registers (GPRs) used for data storage and user application scratchpad operations.  See the PIC18F2610 Data Sheet for more information on the data memory map of the SFR's.

Back To Top

 

retrieve(addr)  # Returns contents of Motion Basic memory address
Parameters
addr Memory address (0 - 249)
Returns
mem 32 bit integer value stored at the specified memory address
Example
X = retrieve(182)  # retrieve from EEPROM the value stored at location 182
Description
retrieve returns the contents stored in the specified address in Motion Basic EEPROM memory.  Motion Basic programs have access to 1000 bytes of EEPROM memory (room for 250 32-bit integers) for permanently storing data using the store subroutine.  Data written to EEPROM memory is permanently stored until it is overwritten by store, or erased by the Motion Basic User Interface using the 'Erase Memory' button.

Back To Top

 

testbit(data, bit)  # Tests if specified data bit is set
Parameters
data Data to test
bit Bit to test (1 - 32)
Returns
set Returns 1 if the specified bit is set, otherwise 0
Example
10   refresh(1)                       # refresh status data
    X = getstat(1)                    # get status byte
    if testbit(X, 6) <> 1 goto 10     # loop until Limit 1 is set
        ###                           # code to process Limit 1
Description
testbit is a utility function used to test if a data bit is set.  The most common use of testbit is to test if a bit is set in a modules' status byte.

Back To Top

 

nmreset()  # Resets all modules to their power up state
Parameters
none
Example
nmreset()     # reset all modules
Description
nmreset resets all modules to their power up state.  It is typically used just before ending a program.

Back To Top

 

poke(addr, data)  # Writes data to processor memory address
Parameters
addr Data memory address (0 - 4095)
data Data to write (0 - 255)
Example
poke(4033, 15)    # write 15 to the ADCON1 register
Description
poke writes data to the specified address in PIC18F2610 data memory.  PIC18F2610 data memory is composed of Special Function Registers (SFRs) used for control and status of the controller and peripheral functions, and General Purpose Registers (GPRs) used for data storage and user application scratchpad operations.   This function is provided for advanced applications which need access to the unused features of the PIC18F2610 processor.  Special knowledge is required for the use of this function.  Incorrect use of this function can damage your hardware.  See the PIC18F2610 Data Sheet for more information on the SFR memory map.

Back To Top

 

refresh(addr)  # Refreshes module status data
Parameters
addr Module address (1 - 6)
Example
refresh(1)        # refresh module status data
X = getstat(1)    # get module status data
Description
refresh reads the current status data from a module (such as status byte, current position,   home position, etc.) and stores it in Motion Basic where is can be used by functions such as getstat, getpos, and gethome.  Most of the "get..." functions return status data stored with the last call to refresh.   To get the most current status data, call refresh before calling any of these functions.

Back To Top

 

store(addr, data)  # Writes data to a Motion Basic memory address
Parameters
addr Memory address (0 - 249)
data Data to store
Example
store(10, -5000)    # store -5000 in memory location 10
Description
store writes a 32-bit integer value to the specified address in Motion Basic EEPROM memory.  Motion Basic programs have access to 1000 bytes of EEPROM memory (room for 250 32-bit integers) for permanently storing data.  Data written to EEPROM memory is permanently stored until it is overwritten by store,  or erased by the Motion Basic User Interface using the 'Erase Memory' button..

Back To Top

 

getad(addr)  # Returns A/D input value

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
ad A/D input value (0 - 255)
Example
refresh(1)      # refresh status data
X = getad(1)    # get the A/D input value
Description
getad returns the PIC-SERVO or PIC-STEP A/D input value.  On PIC-SERVO boards, this value corresponds to the amplifier output current.  On PIC-STEP boards, this value is corresponds to the voltage on the THERM input pin.  See the PIC-SERVO and PIC-STEP board data sheets for more information.

Back To Top

 

gethome(addr)  # Returns home position

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
home Home position (-2147483648 to +2147483647)
Example
refresh(1)        # refresh status data
X = gethome(1)    # get the home position
Description
gethome returns the home position of a PIC-SERVO or PIC-STEP module.

Back To Top

 

getpos(addr)  # Returns current position

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
pos Current position (-2147483648 to +2147483647)
Example
refresh(1)       # refresh status data
X = getpos(1)    # get the current position
Description
getpos returns the current position of a PIC-SERVO or PIC-STEP module.

Back To Top

 

getsvaux(addr)  # Returns auxiliary status byte

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
auxstat PIC-SERVO Auxiliary Status Byte Definition (see PIC-SERVO data sheet)
Bit 1 - Encoder index input value
Bit 2 - Position counter overflow/underflow (must clear with svcbits)
Bit 3 - Position servo enabled
Bit 4 - 1 = Motor accelerating, 0 = motor decelerating (undefined while slewing)
Bit 5 - Motor slewing (constant velocity or stopped)
Bit 6 - Servo overrun (must clear with svcbits)
Bit 7 - Path mode in progress
Bit 8 - Not used
Example
10 refresh(1)                  # refresh status data
X = getsvaux(1)                # get the auxiliary status byte
if testbit(X,5) = 1 goto 10    # loop while motor is slewing
Description
getsvaux returns the PIC-SERVO auxiliary status byte.

Back To Top

 

getsverr(addr)  # Returns position error

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
err Position error (-32768 to +32767)
Example
refresh(1)         # refresh status data
X = getsverr(1)    # get the position error
Description
getsverr returns the PIC-SERVO position error.  The position error is the difference between the current position and the target position.

Back To Top

 

getsvvel(addr)  # Returns current velocity

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
vel Current velocity (-32768 to +32767)
Example
refresh(1)         # refresh status data
X = getsvvel(1)    # get the current velocity
Description
getsvvel returns the PIC-SERVO current velocity.  Note that the velocity returned by getsvvel differs from the commanded velocity by a scale factor of 65536.

Back To Top

 

homing(addr, hmode)  # Set homing parameters

Servo

Step

I/O

Parameters
addr Module address (1-8)
hmode 0 - cancel any homing in progress
19 - home on limit1/limit2 change and stop abruptly
35 - home on limit1/limit2 change and stop smoothly
24 - home on index/home change and stop abruptly
40 - home on index/home change and stop smoothly
additional modes - see PIC-SERVO and PIC-STEP data sheets
Example
homing(1, 19)    # set module 1 to home on limit1/limit2 change
                 # and stop abruptly
Description
homing is used for specifying conditions for capturing the home position of a motor, and also for specifying any desired automatic stopping mode for when the home position is found. Common conditions for capturing the homing position are changes in state to the limit1, limit2, and index/home inputs (index input is used on the PIC-SERVO and home input is used on the PIC-STEP). Common stopping modes are stop abruptly and stop smoothly.

Note that the homing subroutine is used only for specifying the home capture conditions only - it does not initiate any motion. When the homing subroutine is issued, the Homing In Progress bit (bit 8) of the status byte will be set. You should then issue a motion command to move towards one of the triggers used for homing. The Homing In Progress  bit (bit 8) will then be cleared when any of the selected homing conditions occur, and the current motor position is stored in the home position register. The home position register can be read using the gethome function.

Once the homing process is complete, you can re-issue the homing subroutine if desired to capture a different home position. Sending a homing subroutine with the control byte equal to zero will cancel any homing in progress and clear the Homing In Progress bit (bit 8).

Back To Top

 

resetpos(addr)  # Resets the position counter to 0

Servo

Step

I/O

Parameters
addr Module address (1-8)
Example
resetpos(1)     # reset the position counter to 0
Description
resetpos resets the PIC-SERVO or PIC-STEP position counter to 0.

Back To Top

 

stopmot(addr, mode)  # Stop the motor using the specified mode.  Also use to enable/disable the amplifier

Servo

Step

I/O

Parameters
addr Module address (1-8)
mode 0 - disable amp, allow motor to coast
1 - enable amp only (This value is used to initialize stepper before motion)
5 - stop abruptly (This value is also used to initialize the PID servo prior to moving)
9 - stop smoothly (decelerate to a stop)
Example
stopmot(1, 5)    # stop PIC-SERVO abruptly, motor will servo to its
                 # current position
Description
stopmot is used to stop the PIC-SERVO or PIC-STEP motor smoothly or abruptly, and to enable or disable the amplifier.  Use of this subroutine is required to enable the amplifier (and for servo modules, the PID servo) prior to moving the motor.

Back To Top

 

svcbits(addr)  # Clears the latched status bits

Servo

Step

I/O

Parameters
addr Module address (1-8)
Example
svcbits(1)     # clears the PIC-SERVO latched status bits
Description
svcbits is used the clear the PIC-SERVO latched status bits.  The PIC-SERVO contains 4 latched status bits:  the current limit and position error bits in the status byte, and the position overflow/underflow and overrun bits in the auxiliary status byte.  Latched status bits are special status bits that flag certain events and stay set until they are cleared by svcbits.  For example, once a latched status bit is set (for example by current limiting), it remains set until it is cleared by svcbits.

Back To Top

 

svgain(addr, kp, kd, ki, il, ol, cl, el, sr, dc, sm)  # Sets servo operating parameters

Servo

Step

I/O

Parameters
addr Module address (1-8)
kp Position gain (0 to 32,767)
kd Derivative gain (0 to 32,767)
ki Integral gain (0 to 32,767)
il Integration limit (0 to 32,767)
ol Output limit (0 to 255)
cl Current limit (0 to 255)
el Position error limit (0 to 32,767)
sr Servo rate divisor (1 to 255)
dc Amplifier deadband compensation (0 to 255)
sm Step rate multiplier (1 to 255)
Example
svgain(1,100,1000,0,0,255,0,4000,1,1,1 )    # set servo operating params
                                            # values shown are a good default
Description
svgain sets the operating parameters for the PIC-SERVO.  The position, integral, and derivative gain values, integration limit, output limit, position error limit, servo rate divisor and amplifier deadband are all described in detail in Section 4.3 PIC-SERVO Control of the PIC-SERVO SC Chip Data Sheet. The step rate multiplier is described in Section 4.4.6 Step and Direction Input Mode.

The current limit value cl is used to set the allowable current level as described in Section 4.7 Protection Features of the PIC-SERVO SC Chip Data Sheet.  Please refer to the PIC-SERVO SC controller board data sheet to determine the exact values to use for this parameter.  A value of 0 will disable current limiting.

Back To Top

 

svtraj(addr, mode, pos, speed, acc, pwm)  # Sets motion data for velocity, trapezoidal, and PWM moves

Servo

Step

I/O

Parameters
addr Module address (1-8)
mode 151 - Absolute trapezoidal position move
182 - Forward velocity move
246 - Reverse velocity move
136 - Forward PWM move
200 - Reverse PWM move
pos Goal Position in encoder counts (-2,147,483,648 to +2,147,483,647)
vel Velocity data (0 to +83,886,080)
acc Acceleration data (0 to +2,147,483,647)
pwm PWM data (0 to +255)
Example
svtraj(1,151,1500,100000,100,0)    # position move to
                                   # position 1500, with maximum
                                   # velocity of 100000, and
                                   # acceleration of 100
Description
svtraj is used to send motion trajectory information to a PIC-SERVO module. The mode parameter is used to specify the the type of motion - position move, velocity, move, or PWM move.

A trapezoidal position move moves to a goal position at a specified velocity, and with acceleration and deceleration ramping.  The position data is the absolute position (as opposed to relative position) of the motor in encoder counts (4x the number of encoder lines).   The vel parameter specifies the maximum velocity used, and the acc parameter specifies both the rate of acceleration used at the beginning of the motion and the rate of deceleration at the end of the motion.  Note that the pos parameter may be positive or negative but the vel and acc parameters should always be positive.  (The PWM value is ignored for trapezoidal moves.)

A velocity move specifes a change to a new velocity.  The acc parameter specifies the rate of acceleration to the new velocity. Note that the vel and acc parameters are positive values:  use the mode byte to specify a forward or reverse velocity moves.  In velocity moves, the pos and pwm parameters are ignored. 

For both the velocity and trapezoidal profile moves, the vel and acc parameter can be caluclated from:

      vel = RPM x Number of encoder lines x 2.237
      acc = (RPM per sec) x Number of encoder lines x 0.00115

In PWM mode the user can specify the PWM output signal sent directly to the amplifier.   See the PIC-SERVO SC Chip Data Sheet for more information.  In PWM moves, the pos, vel, and acc parameters are ignored.

There are three status bits associated with velocity and trapezoidal profiling: the Move Done in the status byte (see getstat), and the Motor Slewing bit  and the Motor Accelerating/Decelerating bit in the auxiliary status byte (see getsvaux). In velocity moves, the Move Done bit is set when the goal velocity is reached. In position moves, the Move Done bit is set when the servo command position is equal to the final goal position. In both modes, the Motor Slewing bit is set whenever the motor is moving at a constant velocity, and the Motor Accelerating  bit is set when accelerating and cleared when decelerating.

Back To Top

 

waitmove(addr)  # Waits until move is complete

Servo

Step

I/O

Parameters
addr Module address (1-8)
Example
svtraj(1,151,1500,100000,100,0)     # servo move to position 1500
waitmove(1)                         # wait until move is complete
Description
waitmove polls a PIC-SERVO or PIC-STEP controller repeatedly until the current motion is complete.   This command is typically used after a svtraj() or a sttraj() move command to pause program execution until the move is complete. 

Back To Top

 

getstin(addr)  # Returns the inputs value

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
inputs PIC-STEP Inputs Byte Definition (see PIC-STEP data sheet)
Bit 1 - Emergency Stop Input
Bit 2 - IN1 General Purpose Input
Bit 3 - IN2 General Purpose Input
Bit 4 - Limit Switch 1 Input
Bit 5 - Limit Switch 2 Input
Bit 6 - Home Switch Input
Example
refresh(1)                   # refresh status data
X = getstin(1)               # get the current inputs
if testbit(X, 4) goto 10     # test if Limit Switch 1 is set
Description
getstin returns the PIC-STEP inputs byte.  The inputs byte is a bit field consisting of the limit switches, home switch, emergency stop, and general purpose inputs from the PIC-STEP controller.

Back To Top

 

stoutput(addr, outval)  # Sets general purpose output pins for configuring the amplifier

Servo

Step

I/O

Parameters
addr Module address (1-8)
outval 12 - full step mode
14 - half stop mode
additional modes - see PIC-STEP data sheet
Example
stoutput(1, 14)    # set to half step mode
Description
stoutput sets the general purpose output pins OUT1 - OUT5,  and configures the PIC-STEP internal amplifier.  For normal operation (using the PIC-STEP board with internal amplifier), sets the output value to half-step or full-step mode. See the PIC-STEP board data sheet for additional information.   This subroutine must be called before any motion commands to initialize the amplifier.

Back To Top

 

stparam(addr, mode, minspeed, runcur, holdcur, thermlim)  # Sets operating parameters

Servo

Step

I/O

Parameters
addr Module address (1-8)
mode 3 - ignore limit and emergency stop switch, use 1X timing
7 - stop on limit switch, ignore emergency stop switch, use 1X timing
11 - ignore limit switch, stop on emergency stop switch, use 1X timing
15 - stop on limit switch or emergency stop switch, use 1X timing
31 - stop on limit switch or emergency stop switch and turn off motor, use 1X timing
additional modes - see PIC-STEP data sheet
minspeed Minimum stepping speed (1-250)
runcur Running current limit (0-255)
holdcur Holding current limit (0-255)
thermlim Thermal limit (0-255)
Example
stparam(1,15,10,20,10,0)    # set typical PIC-STEP operating parameters
Description
stparam sets the control parameters governing the operation of the PIC-STEP. This command must be issued before any motions can be executed. If this command is issued while the motor is in motion, any changes to the speed mode bits and minimum profile speed will be ignored.

Back To Top

 

sttraj(addr, mode, pos, speed, acc)  # Sets motion data for velocity and position moves

Servo

Step

I/O

Parameters
addr Module address (1-8)
mode 135 - Trapezoidal position move
134 - Forward velocity move
150 - Reverse velocity move
pos Position data (-2,147,483,648 to +2,147,483,647)
vel Velocity data (1 to 250)
acc Acceleration data (1 to 255; larger values = slower acceleration)
Example
sttraj(1,135,1000, 20,15)    # Absolute position move to position 1000,
                             # with maximum velocity of 20, and
                             # acceleration parameter of 15
Description
sttraj is used to send motion trajectory information to a PIC-STEP module. The mode parameter is used to specify the the type of motion - position move or velocity move.

A trapezoidal position move is a move to an absolute (as opposed to relative) goal position at a specified velocity, and with acceleration and deceleration ramping.   Position data is specified in the pos parameter in steps.   The vel parameter specifies the maximum velocity used to make the move in steps per second, and the acc parameter specifies the rate of acceleration used to get to the maximum velocity.  The pos parameter can be either positive or negative  Note that if using 1/2 stepping or microstepping, the actual distance moved will be proportionally shorter.

A velocity move specifes a change to a new velocity.  The new velocity is specified in the vel parameter in steps per second.  The acc parameter specifies the rate of acceleration to the new velocity. Note that the vel and acc parameters are positive values:  use the mode byte to specify a forward or reverse velocity moves.  In velocity moves, the pos parameter is ignored.

The actual step rate is a function of the vel parameter and the timing multiplier (set with stparam):

    step rate (pulses per second) = vel x 25 x timing multiplier

The timing multiplier is typically set to a value of 1, but can also be set to 2, 4 or 8.   Note that if you are using 1/2 stepping or microstepping, the same step rate will produce propotionally slower motion.

The acc parameter is inversely proportional to the acceleration rate.  Increaseing this value will make the motor accelerate more slowly.

There are two status bits associated with velocity and position moves: the Motor Moving bit and the Motor At Speed in the status byte (see getstat).  In velocity moves, the Motor At Speed bit is set when the goal velocity is reached. In position moves, the Motor Moving bit is cleared when the step command position is equal to the final goal position.

Back To Top

 

getioad(addr, adnum)  # Returns A/D input value

Servo

Step

I/O

Parameters
addr Module address (1-8)
adnum Analog input number (1-3)
Returns
ad A/D input value (0 - 255)
Example
refresh(1)            # refresh status data
X = getioad(1, 2)     # get the A/D value from analog input 2
Description
getioad returns the A/D input value from one of the 3 analog inputs from a PIC-I/O controller.  See the PIC-I/O chip data sheet for more information.

Back To Top

 

getioin(addr)  # Returns the inputs value

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
inputs Inputs value  (see PIC-I/O data sheet)
   Bits 1 - 12 correspond to input bits 1 - 12
Example
refresh(1)                      # refresh status data
X = getioin(1)                  # get the inputs value
if testbit(X, 2) = 1 goto 10   # test if I/O bit 2 is HI
if testbit(X, 5) = 0 goto 20   # test if I/O bit 5 is LO
Description
getioin returns the inputs value.  The inputs value is a bit field consisting of the inputs from I/O-1 to I/O-12.

Back To Top

 

gettmr(addr)  # Returns timer/counter value

Servo

Step

I/O

Parameters
addr Module address (1-8)
Returns
val Timer/counter value  (0 to +2,147,483,647)
Example
refresh(1)        # refresh status data
X = gettmr(1)     # get the timer/counter value
Description
gettmr returns the value of a PIC-I/O controller's timer/counter.  See iotimer for more information on the timer/counter.

Back To Top

 

iodir(addr, ionum, iodir)  # Sets direction of I/O pins

Servo

Step

I/O

Parameters
addr Module address (1-8)
ionum I/O bit number (1-12)
iodir I/O direction (0=output, 1=input)
Example
iodir(1, 1, 0)    # set I/O bit 1 direction to output
iodir(1, 2, 1)    # set I/O bit 2 direction to input
Description
iodir sets the direction of the I/O pins. On powerup, all I/O pins are defined as inputs. Make sure that any I/O pins defined as outputs are not connected to the output of another device, or else the PIC-IO or the other device may be damaged.

Back To Top

 

iooutput(addr, ionum, ioval)  # Sets I/O output pin value

Servo

Step

I/O

Parameters
addr Module address (1-8)
ionum I/O bit number (1-12)
ioval Output value (0-1)
Example
iooutput(1, 2, 1)    # set I/O bit 2 to 1
iooutput(1, 8, 0)    # set I/O bit 8 to 0
Description
iooutput sets the value of a PIC-I/O output pin.  iooutput has no effect if it tries to set the value of a I/O pin defined as an input.

Back To Top

 

iopwm(addr, pwm1, pwm2)  # Sets the PWM output values

Servo

Step

I/O

Parameters
addr Module address (1-8)
pwm1 Output value on PWM1 (0-255; 0 = 0% duty cycle, 255 = 100% duty cycle)
pwm2 Output value on PWM2 (0-255; 0 = 0% duty cycle, 255 = 100% duty cycle)
Example
iopwm(1, 64, 128)    # set PWM1 duty cycle to 25%,
                     # and PWM2 duty cycle to 50%
Description
iopwm sets PWM1 and PWM2 output values of a PIC-I/O controller. A value of 0 will turn off the PWM output driver, a value of 255 will turn it on with a 100% duty cycle.

Back To Top

 

iotimer(addr, mode)  # Sets the timer/counter mode of operation

Servo

Step

I/O

Parameters
addr Module address (1-8)
mode 0 - Disable timer/counter
1 - Enable counter mode (with no prescaler)
3 - Enable timer mode (with no prescaler)
additional modes - see PIC-IO data sheet
Example
iotimer(1, 3)    # enable counter mode with no prescaler
Description
iotimer sets the operating mode of a PIC-I/O controller's counter/timer. If in counter mode, each rising edge of I/O bit 10 will be counted. This bit should be set as an input to count external events. In timer mode, the counter counts the PIC-I/O's 5.0 Mhz internal clock.

The counter/timer can also be configured with a prescaler so that it counts only every 2nd, 4th, 8th, etc. event.  Please see the PIC-I/O chip data sheet for details on setting using the prescalar

A call to this function will both set the mode and resets the counter/timer value to zero.

Back To Top