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

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // BV4508 - I2C ADC** NOTE default address on this is 0x62 // This is a library of words inteded for this device it is an I2C // device. The user should set the device address // using the word 4508-default. // 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/I2C/i2c.flb" sid=103 // #URL-Lib "http://pin1.org/forthlib/flb/I2C/bvsys.flb"

// CONSTANTS: // device variable is in bvsys.lib


Full Contents of File

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// BV4508 - I2C ADC** NOTE default address on this is 0x62
// This is a library of words inteded for this device it is an I2C
// device. The user should set the device address
// using the word 4508-default.
// 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/I2C/i2c.flb" sid=103
// #URL-Lib "http://pin1.org/forthlib/flb/I2C/bvsys.flb"

// CONSTANTS:
// device variable is in bvsys.lib

// These are simple commands following the device commands.
: a1 ( 0-9 -- )   device  s  1  sb  sb  p  ;    // set channel
: a2 ( -- )   device  s  2  sb  p  ;    // do conversion
: a3 ( -- stat )   device  s  3  sb  device  1+  rs  rl  p  ;    // conversion status
: a4 ( -- result16 )   device  s  4  sb  device  1+  rs 
                rn  &100  *
                rl  +
                p  ;          // result of conversion
: a5 ( 0|1 -- )   device  s  5  sb  sb  p  ;    // enable / disable adc
: a6 ( 0|1 -- )   device  s  6  sb  sb  p  ;    // 1 enables autoscan
: a7 ( chan -- res16 )   device  s  7  sb  2  *  sb  device  1+  rs 
                rn  &100  *
                rl  +
                p  ;          // result of channel
: a8 ( del -- )   device  s  8  sb  sb  p  ;    // set acquisition delay
: a9 ( ch -- value16 )   device  s  9  sb  2  *  sb  device  1+  rs
                // this has minus o/p within 16 bit result
                rn  &100  *
                rl  +
                dup  &7fff  >  // -ve result
                if  &ffff0000  +  then  // convert to 32 bit
                p  ;          // differential result
: aa ( 0|1 -- )   device  s  10  sb  sb  p  ;    // set justification
: ab ( 0|1 -- )   device  s  11  sb  sb  p  ;    // set voltage ref
: ac ( 0-2 -- )   device  s  12  sb  sb  p  ;    // set conversion clock speed
 

: 4508-default&62  bv-init  i2cfull  ;