Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TimerBasedPwm Class Reference

Single-channel PWM implementation for the ESP8266 that uses the hardware timer resource. More...

#include <TimerBasedPwm.hxx>

Public Member Functions

void enable ()
 Turns on the PWM.
 
void ICACHE_RAM_ATTR owned_isr_handler ()
 interrupt handler (to be called with a this pointer externally stored).
 
void set_off ()
 Turns off the previous output that may have been running.
 
void old_set_state (int pin, long long nsec_period, long long nsec_on)
 Enables the PWM on a specific pin.
 
void pause (long long nsec_pause)
 Pauses updating the PWM for a certain amount of time.
 
void set_state (int pin, long long nsec_period, long long nsec_on)
 Sets the PWM parameters.
 

Static Public Member Functions

static void ICACHE_RAM_ATTR isr_handler (void *)
 Interrupt handler.
 
static void ICACHE_RAM_ATTR new_isr_handler (void *)
 New implementation of the interrupt handler.
 

Static Private Attributes

static uint32_t gpioValue_ = 0
 Bit-shifted value to send to the GPIO output port.
 
static uint32_t clockOn_
 How many clock cycles we should wait after switching ON before swithing OFF.
 
static uint32_t clockOff_
 How many clock cycles we should wait after switching OFF before swithing ON.
 
static bool isOn_
 1 if output is currently on, 0 if it is off.

 

Detailed Description

Single-channel PWM implementation for the ESP8266 that uses the hardware timer resource.

It is very efficient and can support even 20 kHz PWM frequency.

Definition at line 46 of file TimerBasedPwm.hxx.

Constructor & Destructor Documentation

◆ TimerBasedPwm()

TimerBasedPwm::TimerBasedPwm ( )
inline

Definition at line 48 of file TimerBasedPwm.hxx.

Member Function Documentation

◆ enable()

void TimerBasedPwm::enable ( )
inline

Turns on the PWM.

Definition at line 52 of file TimerBasedPwm.hxx.

◆ isr_handler()

static void ICACHE_RAM_ATTR TimerBasedPwm::isr_handler ( void *  )
inlinestatic

Interrupt handler.

Definition at line 62 of file TimerBasedPwm.hxx.

◆ new_isr_handler()

static void ICACHE_RAM_ATTR TimerBasedPwm::new_isr_handler ( void *  )
inlinestatic

New implementation of the interrupt handler.

Definition at line 146 of file TimerBasedPwm.hxx.

◆ old_set_state()

void TimerBasedPwm::old_set_state ( int  pin,
long long  nsec_period,
long long  nsec_on 
)
inline

Enables the PWM on a specific pin.

Parameters
pinis the GPIO number of the pin (0..15)
nsec_periodis the total period length of the output
nsec_onis the time for which the output shall be turned on

Definition at line 96 of file TimerBasedPwm.hxx.

◆ owned_isr_handler()

void ICACHE_RAM_ATTR TimerBasedPwm::owned_isr_handler ( )
inline

interrupt handler (to be called with a this pointer externally stored).

Definition at line 67 of file TimerBasedPwm.hxx.

◆ pause()

void TimerBasedPwm::pause ( long long  nsec_pause)
inline

Pauses updating the PWM for a certain amount of time.

After this function returns the output pins are guaranteed to not be modified for the given amount of time. After the pause the PWM will continue, but whether with low or high is unspecified.

Calling set_state immediately cancels the pause.

Parameters
nsec_pausepause (in nanoseconds) to do. Maximum value is 104 msec

Definition at line 135 of file TimerBasedPwm.hxx.

◆ set_off()

void TimerBasedPwm::set_off ( )
inline

Turns off the previous output that may have been running.

Call set_state to revert.

Definition at line 83 of file TimerBasedPwm.hxx.

◆ set_state()

void TimerBasedPwm::set_state ( int  pin,
long long  nsec_period,
long long  nsec_on 
)
inline

Sets the PWM parameters.

Parameters
pinpin number to PWM.
nsec_periodwhat is the period time of the PWM signal
nsec_onhow much the signal should be HIGH within the period.

Definition at line 168 of file TimerBasedPwm.hxx.

Member Data Documentation

◆ clockOff_

uint32_t TimerBasedPwm::clockOff_
staticprivate

How many clock cycles we should wait after switching OFF before swithing ON.

Definition at line 198 of file TimerBasedPwm.hxx.

◆ clockOn_

uint32_t TimerBasedPwm::clockOn_
staticprivate

How many clock cycles we should wait after switching ON before swithing OFF.

Definition at line 195 of file TimerBasedPwm.hxx.

◆ gpioValue_

uint32_t TimerBasedPwm::gpioValue_ = 0
staticprivate

Bit-shifted value to send to the GPIO output port.

Definition at line 192 of file TimerBasedPwm.hxx.

◆ isOn_

bool TimerBasedPwm::isOn_
staticprivate

1 if output is currently on, 0 if it is off.

Definition at line 200 of file TimerBasedPwm.hxx.


The documentation for this class was generated from the following file: