USB-IO Interface Adapter GPIO-24. Programmers Reference Manual.


3.1.7. GPIO_SET_PWM_CFG

Byte 0 Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 Byte 7
GPIO_ SET _PWM _CFG (0x07) ECHO
  • PORT;

  • ON

MASK T0L T0H T1L T1H

The GPIO_SET_PWM_CFG command configures pulse width modulation (PWM) settings for specified IO pins.

IO pins have to be switched to PWM mode using the GPIO_SET_CFG command. GPIO_SET_PWM_CFG command can be used prior to GPIO_SET_CFG. If IO pin is already in PWM mode, the settings are applied immediately.

PWM mode is configured specifying the high time (T1) and low time (T0) in ms. These values can vary from 1 ms to 65.535 seconds (65535 ms).

Figure 3.2. PWM mode

PWM mode

Command is an 8-byte array of the following format:

Byte 0: GPIO_SET_PWM_CFG (0x07)
This byte contains command identifier (command type). It should be set to 0x07.
Byte 1: ECHO
This byte can be used to associate a response received from GPIO-24 adapter with specific command. Response will contain exactly the same value in its echo byte.
Byte 2: PORT
GPIO PORT:
  • 0 - GPIO PORT A
  • 1 - GPIO PORT B
  • 2 - GPIO PORT C
Byte 3: MASK
Data mask to use when modifying IO pin output values. The mask value allows modification of the specific pins, leaving rest of the pins unchanged. Only the pins with mask bit set to 1 will be affected.
Byte 4: T0L
Least significant byte (low byte) of low time in ms.
Byte 5: T0H
Most significant byte (high byte) of low time in ms.
Byte 6: T1L
Least significant byte (low byte) of high time in ms.
Byte 7: T1H
Most significant byte (high byte) of high time in ms.

For convenience GPIO_SET_PWM_CFG_CMD structure is declared in reports.h file:

typedef struct _GPIO_SET_PWM_CFG_CMD
{
   unsigned char id; //  = GPIO_SET_PWM_CFG;
   unsigned char echo;
   unsigned char on: 4;
   unsigned char port: 4;
   unsigned char mask;
   unsigned short t0;
   unsigned short t1;
} __PACKED_ATTR GPIO_SET_PWM_CFG_CMD, *PGPIO_SET_PWM_CFG_CMD;

GPIO-24 adapter sends GPIO_SET_PWM_CFG response after command execution.