3 utility functions – Sensoray 2410 API User Manual
Page 21
Sensoray 24xx Programming Guide
17
Model 2410 Digital I/O Module
6.2.6 s2410_WritePwm()
Function:
Program the PWM ratio for one DIO channel.
Prototype:
BOOL s2410_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 DIO is to be in the active and inactive
states, respectively. If
ontime
is zero and
offtime
is non-zero then the DIO 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 DIO 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
s2410_WritePwm()
.
• The channel’s operating mode is switched from PWM to Standard. The operating mode can be switched under
software control by calling
s2410_SetDoutMode()
or
s24xx_ResetIo()
, and it may also be automatically
switched in response to a module hardware reset.
Example:
// Configure DIO channel 5 for PWM mode: on for 20 ms, off for 30 ms.
u32 err = ERR_NONE;
s2410_SetDoutMode( sess, &err, 5, DOUT2410_MODE_PWM );
s2410_SetWritePwm( sess, &err, 5, 20, 30 );
if
( err != ERR_NONE )
printf( "Error: %s\n", s24xx_ErrorText(err) );
6.3 Utility Functions
6.3.1 s2410_SetLedBrightness()
Function:
Set the brightness level for all DIO status LEDs.
Prototype:
BOOL s2410_SetLedBrightness( SESSION sess, u32 *err, uint intensity );
Returns:
True if the operation was successful, otherwise False is returned and
err
will contain the associated error code.
Notes:
This can be used to set LED brightness to a comfortable level or to decrease power consumption. DIO status LEDs
can be completely disabled by setting
intensity
to 0. Upon boot-up, the LED intensity defaults to 16 (maximum
intensity).
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 47.
ontime
PWM on time in milliseconds. Range: 0 to 65535.
offtime
PWM off time in milliseconds. Range: 0 to 65535.
Argument
Description
sess
Session handle obtained from
s24xx_SessionOpen()
.
err
Pointer to error code. See Section 4.3.1 for details.
intensity
Brightness level: 0 (always off) to 16 (maximum intensity).