Link here

Power I/O C Demo


This demonstration program is included to provide an example of instrumentation using the Power I/O Wildcard. This C language demo show 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-1 C Code to control the Power I/O Module.

// *********************************************************************
// FILE NAME:   powerio.c
// ---------------------------------------------------------------------
// 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.
//
// *********************************************************************
 
 
#include <mosaic\allqed.h>         // Include QED header files
 
#ifndef __GNUC__
#include "../../libraries/include/io_access.h"
#include "../../libraries/include/io_access.c"
#endif
 
// NOTE: YOU MUST MAKE SURE THAT THIS CONSTANT CORRESPONDS TO YOUR MODULE SELECT JUMPERS!
// For example, to access the Wildcard at address 4:
//    remove both module select jumper caps and mount the card on Wildcard Module Bus 1
#define WPWR_MODULE_NUM 4
// Note: if you are using a QScreen or Handheld, accessing a wildcard at module address 0
// is not allowed; this module address is reserved for the GUI on the QScreen and Handheld.
 
 
 
#define OUTPUT_OFFSET 0x00
#define INPUT_OFFSET  0x01
 
 
// module_num = the hardware jumper setting described in Table 1-2.
// valid module numbers are 0 to 7.
// bit = a bit mask with 1’s in the position of bits to be set.
void SetOutput( uchar bit, uchar module_num )
{
  IOSetBits(bit, OUTPUT_OFFSET, module_num);
}
 
// module_num = the hardware jumper setting described in Table 1-2.
// valid module numbers are 0 to 7.
// bit = a bit mask with 1’s in the position of bits to be cleared.
void ClearOutput( uchar bit, uchar module_num )
{
  IOClearBits(bit, OUTPUT_OFFSET, module_num);
}
 
// module_num = the hardware jumper setting described in Table 1-2.
// valid module numbers are 0 to 7.
uchar ReadOutput( uchar module_num )
{
  uchar output_status;
  output_status = IOFetchChar( OUTPUT_OFFSET, module_num );
  return( output_status );
}
 
// module_num = the hardware jumper setting described in Table 1-2.
// valid module numbers are 0 to 7.
uchar ReadInput( uchar module_num )
{
  uchar input_status;
  input_status = IOFetchChar( INPUT_OFFSET, module_num );
  return( input_status );
}
 
int main( void )
{
    uchar input;
    int i;
 
    printf("\npress enter to turn on the first output.\n");
    Key();
   SetOutput( 0x1, WPWR_MODULE_NUM );  // turn on 1st output
   printf("press enter to turn on the second output.\n");
    Key();
   SetOutput( 0x2, WPWR_MODULE_NUM );  // turn on 2nd output
   printf("press enter to turn on the third output.\n");
    Key();
   SetOutput( 0x4, WPWR_MODULE_NUM );  // turn on 3rd output
   printf("press enter to turn on the forth output.\n");
    Key();
   SetOutput( 0x8, WPWR_MODULE_NUM );  // turn on 4th output
 
    // since we have set the first four bits high, the result should be 0x0F
 
     printf("the outputs report a state of: 0x%02X (should be 0x0F)\n", ReadOutput(WPWR_MODULE_NUM) );
 
   printf("press enter to turn on the fifth output.\n");
    Key();
   SetOutput( 0x10, WPWR_MODULE_NUM );  // turn on 5th output
   printf("press enter to turn on the sixth output.\n");
    Key();
   SetOutput( 0x20, WPWR_MODULE_NUM );  // turn on 6th output
   printf("press enter to turn on the seventh output.\n");
    Key();
   SetOutput( 0x40, WPWR_MODULE_NUM );  // turn on 7th output
   printf("press enter to turn on the eighth output.\n");
    Key();
   SetOutput( 0x80, WPWR_MODULE_NUM );  // turn on 8th output
 
   // with all outputs on, the result should be 0xFF
   printf("the outputs report a state of: 0x%02X (should be 0xFF)\n", ReadOutput(WPWR_MODULE_NUM) );
 
    printf("press enter to turn off the first output.\n");
    Key();
   ClearOutput( 0x1, WPWR_MODULE_NUM );  // turn off 1st output
   printf("press enter to turn off the second output.\n");
    Key();
   ClearOutput( 0x2, WPWR_MODULE_NUM );  // turn off 2nd output
   printf("press enter to turn off the third output.\n");
    Key();
   ClearOutput( 0x4, WPWR_MODULE_NUM );  // turn off 3rd output
   printf("press enter to turn off the forth output.\n");
    Key();
   ClearOutput( 0x8, WPWR_MODULE_NUM );  // turn off 4th output
   printf("press enter to turn off the fifth output.\n");
    Key();
   ClearOutput( 0x10, WPWR_MODULE_NUM );  // turn off 5th output
   printf("press enter to turn off the sixth output.\n");
    Key();
   ClearOutput( 0x20, WPWR_MODULE_NUM );  // turn off 6th output
   printf("press enter to turn off the seventh output.\n");
    Key();
   ClearOutput( 0x40, WPWR_MODULE_NUM );  // turn off 7th output
   printf("press enter to turn off the eighth output.\n");
    Key();
   ClearOutput( 0x80, WPWR_MODULE_NUM );  // turn off 8th output
 
   // read digital inputs
   printf("------------------------------------------\n");
   printf("press enter to read all four inputs.\n");
    Key();
   input = ReadInput( WPWR_MODULE_NUM );  // read all inputs at once
 
   printf("Input:   State:\n");
 
   // loop 4 times, each time shifting input to the right
   // if the lsb is true, then that input was HIGH
   for( i = 1; i <= 4; i++ )
   {
        // print the number and some spaces
        printf(" %d        ", i);
 
        if( input & 0x1 )
            printf("HIGH\n");
        else
            printf("LOW\n");
 
        input = input >> 1;  //shift for next loop
    }
 
    return 0;
}



See more examples → Power I/O Forth Demo
Power I/O Wildcard User Guide

 
This page is about: DC Load Control C Example, Isolated Heavy Duty I/O – C example cycles through Opto isolated DC current sinking outputs. DC Current, opto isolated, current sink, input, output, shift, power i/o
 
 
Navigation