Sigma-delta Module

Since Origin / Contributor Maintainer Source
2016-02-20 Espressif example, Arnim Läuger Arnim Läuger sigma_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
    thigh = (prescale + 1) / 80 µs
    tperiod = thigh * 256 / target
  • 128 < target < 256
    tlow = (prescale + 1) / 80 µs
    tperiod = tlow * 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

-- 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