This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

Timer0 .. 4

Timer, PWM (mwx::periph_timer)
    Timers have two functions: generating software interrupts at specified intervals and producing PWM output at specified intervals. The TWELITE wireless module provides five timers, from 0 to 4.

    Although the embedded object names are Timer0..4, this page refers to them as TimerX.

    Methods

    setup()

    void setup()

    Initializes the timer. This call allocates the required memory area.

    begin()

    void begin(uint16_t u16Hz, bool b_sw_int = true, bool b_pwm_out = false)

    Starts the timer. The first parameter specifies the timer frequency in Hz. If the second parameter is set to true, software interrupts are enabled. If the third parameter is set to true, PWM output is enabled.

    end()

    void end()

    Stops the timer operation.

    available()

    inline bool available()

    Becomes true in the loop() immediately after a timer interrupt occurs, and turns false after the loop() finishes.

    change_duty()

    void change_duty(uint16_t duty, uint16_t duty_max = 1024)

    Sets the duty cycle. The first parameter specifies the duty value (a smaller value brings the average waveform level closer to GND, while a larger value brings it closer to Vcc). The second parameter specifies the maximum duty value.

    change_hz()

    void change_hz(uint16_t hz, uint16_t mil = 0)

    Sets the timer frequency. The second parameter specifies the fractional part (three decimal places) of the frequency as an integer. For example, to set 10.4 Hz, specify hz=10, mil=400.