3 analog i/o functions – Sensoray 2410 API User Manual
Page 32
Sensoray 24xx Programming Guide
28
Model 2426 Multi-Function I/O Module
7.2.6 s2426_WritePwm()
Function:
Program the PWM ratio for one digital output channel.
Prototype:
BOOL s2426_WritePwm( SESSION sess, u32 *err, u8 chan, u16 ontime, u16 offtime );
Returns:
True if the operation was successful, otherwise False is returned and
err
will contain the associated error code.
Notes:
This function applies to channels operating in PWM mode; it has no affect on channels operating in Standard mode.
The
ontime
and
offtime
arguments specify the amount of time that the channel is to be in the active and inactive
states, respectively. If
ontime
is zero and
offtime
is non-zero then the output will always be inactive. Similarly, if
offtime
is zero and
ontime
is non-zero then the output will always be active. The output state is indeterminate if
both
ontime
and
offtime
are set to zero.
The designated digital output channel will switch to the active state and remain active until
ontime
has elapsed,
then it will switch to the inactive state and remain in that state until
offtime
has elapsed. This sequence will repeat
with the same duty cycle and frequency until one of these events occurs:
• The
ontime
and/or
offtime
is changed by calling
s2426_WritePwm()
.
• The channel’s operating mode is switched from PWM to Standard. The operating mode can be switched under
software control by calling
s2426_SetDoutMode()
or
s24xx_ResetIo()
, and it may also be automatically
switched in response to a module hardware reset.
Example:
// Set the PWM ratio for channel 5: on for 20 ms, off for 30 ms.
u32 err = ERR_NONE;
if
( !s2426_WritePwm( sess, &err, 5, 20, 30 ) )
printf( "Error: %s\n", s24xx_ErrorText(err) );
7.3 Analog I/O Functions
7.3.1 s2426_WriteAout()
Function:
Program the analog output voltage level.
Prototype:
BOOL s2426_WriteAout( SESSION sess, u32 *err, s16 setpoint, BOOL correct );
Returns:
True if the operation was successful, otherwise False is returned and
err
will contain the associated error code.
Example:
// Program analog output to -5V.
u32 err = ERR_NONE;
if
( !s2426_WriteAout( sess, &err, -16384, TRUE ) )
printf( "Error: %s\n", s24xx_ErrorText(err) );
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.
chan
Channel number in the range 0 to 15.
ontime
PWM on time in milliseconds.
offtime
PWM off time in milliseconds.
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.
setpoint
Desired output level: -32768 (-10V) to 32767 (+10V).
correct
Set to True to apply calibration correction, or False to write the setpoint directly to the
analog output interface without modification.