To use this file copy and paste this:
// #URL-lib "http://pin1.org/forthlib/flb/General/AtoD.flb" into BV Terminal 3
or here to download.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// A to D code for using the built in
// a to d converters, provides some simple routines for using
// the LCP ARM ADC facility. This only covers channel 0
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// REQUIRES:
// #URL-lib "http://pin1.org/forthlib/flb/General/pinsel.flb"
// #URL-lib "http://pin1.org/forthlib/flb/General/soft1.flb"
// CONSTANTS:
// ADC Registers
&e0034000 constant AD0CR
&e0034004 constant AD0GDR
&e0034028 constant ADDR6
// division constant for A to D, creates a constant
// cdiv based on PCLK
pclk 3500000 / constant CDIV
Full Contents of File
&e0034000  constant  AD0CR
&e0034004  constant  AD0GDR
&e0034028  constant  ADDR6 
pclk  3500000 
: <0>getad
        begin
                AD0GDR  @
                &80000000  and
        until
        AD0GDR  @  6  rshift 
        &3ff  and                       
;
: <0>AtoD
        1  swap  lshift     
        CDIV  8  lshift  + 
        &01200000             
        +
        AD0CR  !
        getad
;       
: <0>Vin@
        AtoD               
        3226  *           
        1000  u
        swap  500  >  if  1+  then 
;