To use this file copy and paste this:    // #URL-lib "http://pin1.org/forthlib/flb/IASI2/BV4113-motor.flb"   into BV Terminal 3 or here to download.

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BV4113 - IASI stepper motor driver 'a' // This will load as a stand alone file or can be used as a library // providing the parent file includes the files in the REQUIRES // section // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

// HISTORY: // Jan 2009 *Preliminary // *not complete only has step and a few other commands

// REQUIRES: // #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=0 // #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb" sid=101 // #URL-lib "http://pin1.org/forthlib/flb/General/strings.flb" // #URL-lib "http://pin1.org/forthlib/flb/IASI2/IASI2-motor.flb"

// CONSTANTS: integer i-motor-adr // set this before using


Full Contents of File

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// BV4113 - IASI stepper motor driver 'a'
// This will load as a stand alone file or can be used as a library
// providing the parent file includes the files in the REQUIRES
// section
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

// REQUIRES:
// #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb" sid=0
// #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb" sid=101
// #URL-lib "http://pin1.org/forthlib/flb/General/strings.flb"
// #URL-lib "http://pin1.org/forthlib/flb/IASI2/IASI2-motor.flb"

// HISTORY:
// Jan 2009 *Preliminary
// *not complete only has step and a few other commands

// CONSTANTS:
integer  i-motor-adr          // set this before using

// ---------------------------------------------------------------
// changes address of motor
: i-set-motor-adr ( adr -- )
        =>  i-motor-adr
; 
     
// ---------------------------------------------------------------
// Initialise device to an address, reports back number of devices
// connected
: i-init-motor ( adr -- x )
        i-set-motor-adr
        i-connect
;                       

// ---------------------------------------------------------------
// Digital channel set
// sets channel a or b to either input or ouput
// channel 1=a, any=b
// output any=in, 1=out
// example to set channel b to input: 2 0 m-setdigit
: m-setdigit { channel output -- }
        i-motor-adr  emit1  [char]  d  emit1  // all need this
        channel  1  = 
        if
                [char]  a  emit1  [char]  -  emit1
                output  1  =
                if
                          [char]  o  emit1  cr1  i-send
                else       
                          [char]  i  emit1  cr1  i-send
                then
        else                 
                [char]  b  emit1  [char]  -  emit1
                output  1  =
                if
                          [char]  o  emit1  cr1  i-send
                else       
                          [char]  i  emit1  cr1  i-send
                then
        then
;
// ---------------------------------------------------------------
// digital channel set to 1 or 0
// channel 1=a, any=b
// set 1=1 any=0
: m-digit { channel set -- }
        i-motor-adr  emit1  [char]  d  emit1  // all need this
        channel  1  = 
        if
                set  1  =
                [char]  a  emit1
                if
                        [char]  1  emit1  cr1  i-send
                else
                        [char]  0  emit1  cr1  i-send
                then
      else                 
                set  1  =
                [char]  b  emit1
                if
                        [char]  1  emit1  cr1  i-send
                else
                        [char]  0  emit1  cr1  i-send
                then
      then
;

// ---------------------------------------------------------------
// gets value of channel a or b
// channel 1=a
// does not use * option to return binary, uses i-gn instead
// returns 1 or 0
: m-get { channel -- 1 or 0, valid }
        i-cbuff
        i-motor-adr  emit1  [char]  d  emit1  // all need this
        channel  1  =
        if
                [char]  a  emit1
        else
                [char]  b  emit1
        then
        cr1  i-send  i-gn  drop
;                       
// ---------------------------------------------------------------
// analogue channel can return either absolute value or a percentage
// percent=1 will return a percent value
: m-analogue { percent -- }  
        i-cbuff
        i-motor-adr  emit1  [char]  v  emit1  // send ad command
        percent  1  =
        if
                [char]  p  emit1
        then
        cr1  i-send  i-gn  drop
;                       

// ---------------------------------------------------------------
// steps
// steps -1=continuous, any other value nu,ber of steps
// direction 1 or 0
: m-step { steps direction -- }
        i-motor-adr  emit1  // all need this
        steps  -1  =
        if
                [char]  r  emit1  // driection
                direction  48  +  // convert to ascii
                emit1  cr1  i-send  // direction set
                i-motor-adr  emit1  // again for continuous step
                [char]  c  emit1  cr1  i-send
        else
                [char]  n  emit1
                direction  48  +  // convert to ascii
                emit1  cr1
        then       
;
                               
// ---------------------------------------------------------------
// stop
: m-stop ( -- )
        i-motor-adr  emit1  [char]  x  emit1  cr1
;

// ---------------------------------------------------------------
// speed
: m-speed { speed -- }
        i-motor-adr  emit1  [char]  s  emit1
        speed  iu.  cr1
;
       
// ---------------------------------------------------------------
// mode
// 1=full, 0(any)=half
: m-mode { mode -- }
        i-motor-adr  emit1  [char]  h  emit1
        mode  1  =
        if
                [char]  f  emit1
        else
                [char]  h  emit1
        then
        cr1               
;