PWM

CONSTANTS

pwm.PWM_MAX_VALUE


pwm.setfreq()

Description

initialize pwm generator to run at the specific frequency.

Syntax

pwm.setfreq(freq)

Parameters

freq: 1~500 HZ

Returns

nil

See also

– pwm.start()
– pwm.stop()


pwm.start()

Description

start running pwm at a specific GPIO pin. (need call pwm.commit() to take effect)

Syntax

pwm.start(pin, duty)

Parameters

pin: 0~15, GPIO index
duty: 0 ~ pwm.PWM_MAX_VALUE

Returns

nil

Example

pin=2
i=0
di=1
pwm.setfreq(500)

timer=Timer:new()
timer:setInterval(function()
pwm.start(pin,i+pwm.PWM_MAX_VALUE-10)
pwm.commit()
i=i+di
if (i == 10 or i == 0) then
di = -di;
end
end, 50) –milliseconds

See also

– pwm.commit()
– pwm.stop()


pwm.stop()

Description

stop pwm on a specific GPIO pin. (need call pwm.commit() to take effect)

Syntax

pwm.stop(pin)

Parameters

pin: 0~15, GPIO index

Returns

nil

See also

– pwm.commit()
– pwm.start()

pwm.commit()

Description

commit changes of pwm.start or pwm.stop to take effect.
ATTENTION: don’t call pwm.commit() too fast

Syntax

pwm.commit()

Parameters

Returns

bool: success. If you call pwm.commit() too fast, it may fail and return false.

See also

– pwm.start()
– pwm.stop()