rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
SimplePwm Class Reference

#include <pwm_generator_logic.h>

Inheritance diagram for SimplePwm:
Inheritance graph
[legend]
Collaboration diagram for SimplePwm:
Collaboration graph
[legend]

Public Member Functions

 SimplePwm ()
 
 SimplePwm (const char *name)
 
void setSimplePwmDutyCycle (float dutyCycle) override
 
- Public Member Functions inherited from PwmConfig
 PwmConfig ()
 
void weComplexInit (Scheduler *executor, MultiChannelStateSequence const *seq, pwm_cycle_callback *pwmCycleCallback, pwm_gen_callback *callback)
 
void setFrequency (float frequency)
 
void handleCycleStart ()
 
efitick_t togglePwmState ()
 
void stop ()
 
void applyPwmValue (OutputPin *output, int stateIndex, int channelIndex=0)
 

Data Fields

MultiChannelStateSequenceWithData< 2 > seq
 
hardware_pwmhardPwm = nullptr
 
- Data Fields inherited from PwmConfig
Schedulerm_executor = nullptr
 
pwm_mode_e mode
 
bool isStopRequested = false
 
const charm_name
 
OutputPinoutputPins [PWM_PHASE_MAX_WAVE_PER_PWM]
 
MultiChannelStateSequence const * multiChannelStateSequence = nullptr
 
int dbgNestingLevel
 
scheduling_s scheduling
 
pwm_config_safe_state_s safe
 
pwm_cycle_callbackm_pwmCycleCallback = nullptr
 
pwm_gen_callbackm_stateChangeCallback = nullptr
 

Detailed Description

Definition at line 115 of file pwm_generator_logic.h.

Constructor & Destructor Documentation

◆ SimplePwm() [1/2]

SimplePwm::SimplePwm ( )

Definition at line 24 of file pwm_generator_logic.cpp.

25{
26 seq.waveCount = 1;
27 seq.phaseCount = 2;
28}
MultiChannelStateSequenceWithData< 2 > seq

◆ SimplePwm() [2/2]

SimplePwm::SimplePwm ( const char name)

Definition at line 30 of file pwm_generator_logic.cpp.

30 : SimplePwm() {
31 m_name = name;
32}
const char * m_name

Member Function Documentation

◆ setSimplePwmDutyCycle()

void SimplePwm::setSimplePwmDutyCycle ( float  dutyCycle)
overridevirtual

This method allows you to change duty cycle on the fly

Parameters
dutyCyclevalue between 0 and 1 See also setFrequency

Implements IPwm.

Definition at line 49 of file pwm_generator_logic.cpp.

49 {
50 if (isStopRequested) {
51 // we are here in order to not change pin once PWM stop was requested
52 return;
53 }
54 if (std::isnan(dutyCycle)) {
55 warning(ObdCode::CUSTOM_DUTY_INVALID, "%s spwd:dutyCycle %.2f", m_name, dutyCycle);
56 return;
57 } else if (dutyCycle < 0) {
58 warning(ObdCode::CUSTOM_DUTY_TOO_LOW, "%s dutyCycle too low %.2f", m_name, dutyCycle);
59 dutyCycle = 0;
60 } else if (dutyCycle > 1) {
61 warning(ObdCode::CUSTOM_PWM_DUTY_TOO_HIGH, "%s duty too high %.2f", m_name, dutyCycle);
62 dutyCycle = 1;
63 }
64
65#if EFI_PROD_CODE
66 if (hardPwm) {
67 hardPwm->setDuty(dutyCycle);
68 return;
69 }
70#endif
71
72 // Handle near-zero and near-full duty cycle. This will cause the PWM output to behave like a plain digital output.
73 if (dutyCycle < ZERO_PWM_THRESHOLD) {
74 mode = PM_ZERO;
75
77 // Manually fire falling edge
78 m_stateChangeCallback(0, this);
79 }
80 } else if (dutyCycle > FULL_PWM_THRESHOLD) {
81 mode = PM_FULL;
82
84 // Manually fire rising edge
85 m_stateChangeCallback(1, this);
86 }
87 } else {
89 seq.setSwitchTime(0, dutyCycle);
90 }
91}
void setSwitchTime(const int phaseIndex, const float value)
pwm_mode_e mode
pwm_gen_callback * m_stateChangeCallback
hardware_pwm * hardPwm
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_DUTY_INVALID
@ CUSTOM_DUTY_TOO_LOW
@ CUSTOM_PWM_DUTY_TOO_HIGH
@ PM_NORMAL
virtual void setDuty(float duty)=0

Referenced by applyIACposition(), TachometerModule::onFastCallback(), Gm4l6xTransmissionController::set32State(), AlternatorController::setOutput(), Generic4TransmissionController::setPcState(), setPwmDuty(), and updateVrThresholdPwm().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ hardPwm

hardware_pwm* SimplePwm::hardPwm = nullptr

Definition at line 121 of file pwm_generator_logic.h.

Referenced by setSimplePwmDutyCycle().

◆ seq

Definition at line 120 of file pwm_generator_logic.h.

Referenced by setSimplePwmDutyCycle(), and SimplePwm().


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