ADwin Data Acquisition and Control
CHESTERLAND OH—November 16, 2011
In automotive or other vehicle applications, it’s often desirable to read data from one or more sensors providing an analog voltage output and to transmit this data via the CANbus; this way it can be read along with other data being broadcast by an ECU by a single data logging device. ADwin data acquisition systems provide an ideal platform to implement a simple solution for this. These stand-alone real-time data acquisition and control systems feature analog, digital, CANbus, and Serial I/O for use in research, manufacturing, test stand, aerospace and automotive applications.
Figure 1 shows a basic flow chart for a program to read and output data.
ADwin data acquisition and control systems are available in several different models with different analog input capabilities, but they are all suitable for this application when outfitted with the CANbus interface option. The flexibility of the open programming environment of ADwin systems makes it especially easy to read and scale the data. High level functions and built-in message structures allow the generation and transmission of CAN messages with just a few simple statements.
The ADwin operating system is an event-based environment which allows periodic message generation without the need for special timing routines. In the example below, the GLOBALDELAY statement sets the event loop to execute every millisecond to read and transmit the data. In this example the data is being broadcast, but it is quite easy to configure the system to use polled message transmission. In this case, the CAN interface can be configured to look for a particular message ID and generate an interrupt to trigger the event loop and send the data.
Other powerful features of the ADwin systems are the built-in high level functions and their ability to freely program calculations with very little overhead. In the example below, it is obvious how easy it is to read the A/D converter; a single instruction returns the current input value. Likewise, scaling calculations can be done with a single, intuitive equation. These capabilities enable more complex operations such as averaging, filtering, and statistical operations. Internal routines which handle casting operations make it easy to manipulate integer, floating point and binary data transparently.
The ADwin architecture provides for transparent shared data between the internal operating environment of the ADwin system and an attached PC. For debugging, this greatly simplifies monitoring the values of variable via the PAR (integer) and FPAR (floating point) shared data. The environment also provides for data arrays to enable charting and logging.
The following sample program is for an ADwin-Pro system with a Pro-Ain-32/16, 16 bit analog input card and a Pro-CAN-2, 2 channel high speed CAN interface card.
‘* ADWIN-PRO MODULE ADDRESS DEFINITIONS
#DEFINE modAIN32_16 1 ‘Define address of analog input module
#DEFINE modCAN2 1 ‘Define address of CAN interface module
#DEFINE CAN_CH1 1 ‘Define CAN channel
‘* DEFINITION OF PAR VALUES
#DEFINE RAW_ADC PAR_1 ‘Temporary variable for raw A/D conversion
‘* DEFINITION OF FPAR VALUES
#DEFINE OFFSET FPAR_1 ‘Sensor zero offset for engineering units
#DEFINE GAIN FPAR_2 ‘Sensor gain for engineering units
#DEFINE SCALE FPAR_3 ‘Scale factor for CAN message
#DEFINE PRESSURE FPAR_4 ‘Sensor value in engineering units
DIM CANDATA AS LONG ‘Sensor value for CAN message
GLOBALDELAY = 40000 ‘Update rate in ticks = 1 msec.
INIT_CAN(modCAN2, CAN_CH1) ‘* Initialize CAN Controller
FPAR_2 = SET_CAN_BAUDRATE(modCAN2, CAN_CH1, 250000) ‘For J1939=350 kBit
‘PGN 65263 is for oil pressure, send as J1939, 29 bit identifier of 018FEEF
EN_TRANSMIT(modCAN2, CAN_CH1, 1, 018FEEF00h, 1)
GAIN = 100.0 ‘0-10V out is 0-100 PSI
OFFSET = 0.0 ‘default offset is 0 PSI
SCALE = 4.0 ‘Std. scale factor for message is 4
‘ Read ADC, convert counts to pressure and scale based on CAN std.
PRESSURE = (((RAW_ADC – 32767)/32767)* GAIN) – OFFSET
CANDATA = PRESSURE * SCALE
PAR_2 = CANDATA ‘Debug
‘ Build CAN Message – pressure is in byte 4 so pad leading bytes with FF
CAN_MSG = 0FFh
CAN_MSG = 0FFh
CAN_MSG = 0FFh
CAN_MSG= CANDATA ‘ BYTE 4 = ENGINE OIL PRESSURE
CAN_MSG = 0FFh ‘ Add trailing pad byte
CAN_MSG = 6 ‘ message length is 6 bytes
TRANSMIT(modCAN2, CAN_CH1, 1)
For further information on the ADwin data acquisition and control systems, other data acquisition devices , or to find the ideal solution for your application-specific needs, contact a CAS Data Logger Applications Specialist at (800) 956-4437 or visit the website at www.DataLoggerInc.com.
CAS DataLoggers, Inc.
12628 Chillicothe Road
Chesterland, Ohio 44026