PWM Mode


Overview

This mode is used to precisely generate PWM signal. PWM signal is the endless chain of identical rectangular pulses. In other words, PWM signal is periodical signal, each cycle is a rectangular pulse. PWM signal is composed of low-level signal and high-level signal.

Available Commands

Command Sub Command Description
set mode output pwm set mode: pwm
div ms set unit: millisecond
us set unit: microsecond
output od open-drain
pp push-pull
low output LOW
high output HIGH
invert 0 not invert output
1 invert output
count [T1] [T2] set output timing parameters
trigger from ht0 set trigger target: ht0
php set trigger target: none
reset - reset
get state get current state
div get division rate
start - start
stop - stop

Set Count Values

In output PWM mode, this command is used to specify the low-level duration and high-level duration. The unit of time is specified in "set div" command.

Command Syntax
set count pid_ioctl($pid, "set count T1 T2");

Valid values for T1 and T2 in pulse mode are as follows:

Division Available Count Values
T1 1 ~ 32763
T2 1 ~ 32763
T1 + T2 2 ~ 32764

This command must be used before timer starts. If not, an error is generated.
The figure below shows waveform of PWM signal

ht_set_pwm_01

※ Duty cycle = T1 / (T1 + T2)
※ Frequency = 1 / (T1 + T2)

Set Output [low/high]

This command immediately forces HT pin to LOW or HIGH.

Command Syntax Description
set output low pid_ioctl($pid, "set output low"); Set HT pin to LOW
set output high pid_ioctl($pid, "set output high"); Set HT pin to HIGH

Note that if invert mode is enabled, this command will force HT pin to the state that is invert of normal operation.

Set Output [od/pp]

This command set output type of HT pin

Command Syntax Description
set output pp pid_ioctl($pid, "set output pp"); Set output type to push-pull
set output od pid_ioctl($pid, "set output od"); Set output type to open-drain

If the command is not used, the output type of HT pin is push-pull by default.

Set Output Invert [0/1]

This command is used to enable/disable invert mode.

Command Syntax Description
set output invert 0 pid_ioctl($pid, "set output invert 0"); disbale invert mode
set output invert 1 pid_ioctl($pid, "set output invert 1"); enable invert mode

When invert mode is enabled:

ht_set_pwm_03

Invert mode is disabled by default.

Example of PWM Mode

example of PWM mode

<?php
$pid = pid_open("/mmap/ht0");           // open HT 0
pid_ioctl($pid, "set div us");          // set unit: microsecond
pid_ioctl($pid, "set mode output pwm"); // set mode: PWM mode
pid_ioctl($pid, "set count 1 1");       // set count values: 1, 1
pid_ioctl($pid, "start");               // start HT
usleep(50);
pid_ioctl($pid, "stop");                // stop HT
pid_close($pid);
?>

The figure below shows waveform of the example above.

ht_set_pwm_02