Link here

Power I/O Forth Demo


This demonstration program is included to provide an example of instrumentation using the Power I/O Wildcard. This Forth language demo shows how simple it is to use the 8 opto-isolated current-sinking MOSFET outputs provided by the Power I/O Wildcard. The example program first initializes the DC solid state relays (SSR). Then a the outputs are individually turned on and off in sequence. The 4 inputs are then read and printed out to the serial terminal. This gives you a simple example of how to use this card.

Listing 1-2 Forth Code to control the Power I/O Module.

\ *********************************************************************
\ FILE NAME:   powerio.4TH
\ ---------------------------------------------------------------------
\ AUTHOR:      BEN MORSE
\ DATE:        5/7/2009
\ VERSION:     1.0
\ ---------------------------------------------------------------------
\ This is the driver code for the Power I/O Wildcard.
\ This code:
\     -Turns each output on.
\     -Returns the state of the ouputs.
\     -Turns each output off.
\     -Returns the state of the inputs.
\ ---------------------------------------------------------------------
\ Important user words:
\ SetOutput:             Turn the specified output ON
\ ClearOutput:           Turn the specified output OFF
\ ReadOutput:            Returns the state of all outputs.
\ ReadInput:             Returns the state of all 4 inputs.
\ WPWR_MODULE_NUM        this constant MUST match hardware jumper settings!
\ ---------------------------------------------------------------------
\
\ Disclaimer: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
\             ANY WARRANTIES OR REPRESENTATIONS EXPRESS OR IMPLIED,
\             INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES
\             OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
\
\ *********************************************************************
 
BASE @ HEX
FIND WHICH.MAP          \ WHICH.MAP does not exist in the V6.xx kernel.
IFTRUE                  \ Do this only for page-swapping platforms, ie V4.xx
  EXECUTE  0=           ( -- standard.map? ) \ run which.map
  IFTRUE 4 PAGE.TO.RAM  \ if in standard.map, transfer to download map
         5 PAGE.TO.RAM
         6 PAGE.TO.RAM
         DOWNLOAD.MAP
  ENDIFTRUE             \ nesting is allowed if ends are sequential
ENDIFTRUE
 
FIND USE.PAGE   \ only in V4.xx kernels
IFTRUE
    XDROP         ( -- ) \ drop xcfa
    4 USE.PAGE    \ comment this out if memory map is already set up
ENDIFTRUE
 
\ the following line includes a do-nothing file if kernel V6.xx is used
\ (ie, if IO.C@, IO.C!, etc. are already defined):
#include "..\..\libraries\include\QED_QCard_IO.4th"
 
F WIDTH !                              \ Set width of names stored in dictionary
 
ANEW PWR.CODE                            \ Forget marker for easy re-loading.
 
 
00 CONSTANT OUTPUT_OFFSET
01 CONSTANT INPUT_OFFSET
 
\ bit = a bit mask with 1’s in the position of the bits to be set.
\ module_num = the hardware jumper setting described in Table 1-2.
\ Valid module numbers are 0 to 7.
: SETOUTPUT ( b1/b2 -- | b1 = bit, b2 = module_num )
locals{ &module &bit }
  &bit OUTPUT_OFFSET &module IO.SET.BITS
;
 
\ bit = a bit mask with 1’s in the position of bits to be cleared.
\ module_num = the hardware jumper setting described in Table 1-2.
\ Valid module numbers are 0 to 7.
: CLEAROUTPUT ( b1/b2 -- | b1 = bit, b2 = module_num )
locals{ &module &bit }
  &bit OUTPUT_OFFSET &module IO.CLEAR.BITS
;
 
\ module_num = the hardware jumper setting described in Table 1-2.
\ Valid module numbers are 0 to 7.
: READOUTPUT ( b1 -- b2 | b1 = module_num, b2 = output_status )
  OUTPUT_OFFSET SWAP IO.C@
;
 
\ module_num = the hardware jumper setting described in Table 1-2.
\ Valid module numbers are 0 to 7.
: READINPUT ( b1 -- b2 | b1 = module_num, b2 = input_status )
  INPUT_OFFSET SWAP IO.C@
;
 
 
: TEST.MOD ( byte -- \ byte = module.no )
LOCALS{ &module.no }
 
BASE @ HEX
 
CR ." press enter to turn on the first output."
KEY  DROP
1 &module.no SETOUTPUT \ turn on 1st output
CR ." press enter to turn on the second output."
KEY  DROP
2 &module.no SETOUTPUT \ turn on 2nd output
CR ." press enter to turn on the third output."
KEY  DROP
4 &module.no SETOUTPUT \ turn on 3rd output
CR ." press enter to turn on the forth output."
KEY  DROP
8 &module.no SETOUTPUT \ turn on 4th output
 
CR ." the outputs report a state of: 0x"
&module.no READOUTPUT . ." (should be 0xF)"
 
CR ." press enter to turn on the fifth output."
KEY  DROP
10 &module.no SETOUTPUT \ turn on 5th output
CR ." press enter to turn on the sixth output."
KEY  DROP
20 &module.no SETOUTPUT \ turn on 6th output
CR ." press enter to turn on the seventh output."
KEY  DROP
40 &module.no SETOUTPUT \ turn on 7th output
CR ." press enter to turn on the eighth output."
KEY  DROP
80 &module.no SETOUTPUT \ turn on 8th output
 
CR ." the outputs report a state of: 0x"
&module.no READOUTPUT . ." (should be 0xFF)"
 
 
CR ." press enter to turn off the first output."
KEY  DROP
1 &module.no CLEAROUTPUT \ turn off 1st output
CR ." press enter to turn off the second output."
KEY  DROP
2 &module.no CLEAROUTPUT \ turn off 2nd output
CR ." press enter to turn off the third output."
KEY  DROP
4 &module.no CLEAROUTPUT \ turn off 3rd output
CR ." press enter to turn off the forth output."
KEY  DROP
8 &module.no CLEAROUTPUT \ turn off 4th output
CR ." press enter to turn off the fifth output."
KEY  DROP
10 &module.no CLEAROUTPUT \ turn off 5th output
CR ." press enter to turn off the sixth output."
KEY  DROP
20 &module.no CLEAROUTPUT \ turn off 6th output
CR ." press enter to turn off the seventh output."
KEY  DROP
40 &module.no CLEAROUTPUT \ turn off 7th output
CR ." press enter to turn off the eighth output."
KEY  DROP
80 &module.no CLEAROUTPUT \ turn off 8th output
 
CR ." ------------------------------------------"
CR ." press enter to read all four inputs."
KEY  DROP
&module.no READINPUT DUP DUP DUP
CR ." Input:   State:"
 
CR ."  1        "
1 AND       \ Compare digital input with hex 0x1
IF                    \ input is high
  ." HIGH"
ELSE                \ turn relay on
  ." LOW"
ENDIF
 
CR ."  2        "
2 AND             \ Compare input with hex 0x2
IF                    \ input is high
  ." HIGH"
ELSE                \ turn relay on
  ." LOW"
ENDIF
 
CR ."  3        "
4 AND       \ Compare input with hex 0x4
IF                    \ input is high
  ." HIGH"
ELSE                \ turn relay on
  ." LOW"
ENDIF
 
CR ."  4        "
8 AND       \ Compare input with hex 0x8
IF                    \ input is high
  ." HIGH"
ELSE                \ turn relay on
  ." LOW"
ENDIF
CR
BASE !
;
 
 
 
FIND WHICH.MAP
IFTRUE EXECUTE
        IFTRUE 4 PAGE.TO.FLASH
               5 PAGE.TO.FLASH
               6 PAGE.TO.FLASH STANDARD.MAP
        ENDIFTRUE
ENDIFTRUE
BASE !
 
SAVE



More Examples → Power I/O C Demo
Power I/O Wildcard User Guide

 
 
 
Navigation
 
Registration on or use of this site constitutes acceptance of our User Agreement and Privacy Policy. Purchase of Mosaic's products constitutes acceptance of the End User License Agreement, Sales Terms and Conditions, and Life Support policy. Mosaic’s products are not authorized for use as components in life support or medical devices. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Mosaic Industries, Inc. Mosaic and other product names are trademarked and should be capitalized when reproduced. You are encouraged to link to pages of this site.

© Mosaic Industries, Inc. All rights reserved.