Back to Nodemcu Firmware

Sigma-delta Module

docs/modules/sigma-delta.md

latest2.5 KB
Original Source

Sigma-delta Module

SinceOrigin / ContributorMaintainerSource
2016-02-20Espressif example, Arnim LäugerArnim Läugersigma_delta.c

This module provides access to the sigma-delta component. It's a hardware signal generator that can be routed to any of the GPIOs except pin 0.

The signal generation is controlled by the setprescale() and settarget() functions.

  • 0 < target <= 128

    t<sub>high</sub> = (prescale + 1) / 80 µs

    t<sub>period</sub> = t<sub>high</sub> * 256 / target

  • 128 < target < 256

    t<sub>low</sub> = (prescale + 1) / 80 µs

    t<sub>period</sub> = t<sub>low</sub> * 256 / (256 - target)

  • target = 0

    signal stopped at low

Fixed frequency PWM at ~312.5 kHz is availble with the setpwmduty() function.

sigma_delta.close()

Stops signal generation and reenables GPIO functionality at the specified pin.

Syntax

sigma_delta.close(pin)

Parameters

pin 1~12, IO index

Returns

nil

sigma_delta.setprescale()

Sets the prescale value.

Syntax

`sigma_delta.setprescale(value)

Parameters

value prescale 1 to 255

Returns

nil

See also

sigma_delta.settarget()

sigma_delta.setpwmduty()

Operate the sigma-delta module in PWM-like mode with fixed base frequency.

Syntax

sigma_delta.setpwmduty(ratio)

Parameters

ratio 0...255 for duty cycle 0...100%, 0 stops the signal at low

Returns

nil

Example

lua
-- attach generator to pin 2
sigma_delta.setup(2)
-- set 50% duty cycle ratio (and implicitly start signal)
sigma_delta.setpwmduty(128)
-- stop
sigma_delta.setpwmduty(0)
-- resume with ~99.6% ratio
sigma_delta.setpwmduty(255)
-- stop and detach generator from pin 2
sigma_delta.close(2)

sigma_delta.settarget()

Sets the target value.

Syntax

sigma_delta.settarget(value)

Parameters

value target 0 to 255

Returns

nil

See also

sigma_delta.setprescale()

sigma_delta.setup()

Stops the signal generator and routes it to the specified pin.

Syntax

sigma_delta.setup(pin)

Parameters

pin 1~12, IO index

Returns

nil