Skip to content

Commit 07090bc

Browse files
author
Richard Unger
committed
Add 1-PWM support to esp32 LEDC driver
1 parent c9ddb99 commit 07090bc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/drivers/hardware_specific/esp32_ledc_mcu.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ void _setHighFrequency(const long freq, const int pin, const int channel){
5353

5454

5555

56+
57+
58+
59+
void* _configure1PWM(long pwm_frequency, const int pinA) {
60+
if(!pwm_frequency || !_isset(pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY; // default frequency 25khz
61+
else pwm_frequency = _constrain(pwm_frequency, 0, _PWM_FREQUENCY_MAX); // constrain to 50kHz max
62+
63+
// check if enough channels available
64+
if ( channel_index + 1 >= LEDC_CHANNELS ) return SIMPLEFOC_DRIVER_INIT_FAILED;
65+
66+
int ch1 = channel_index++;
67+
_setHighFrequency(pwm_frequency, pinA, ch1);
68+
69+
ESP32LEDCDriverParams* params = new ESP32LEDCDriverParams {
70+
.channels = { ch1 },
71+
.pwm_frequency = pwm_frequency
72+
};
73+
return params;
74+
}
75+
76+
77+
78+
79+
80+
81+
82+
5683
void* _configure2PWM(long pwm_frequency, const int pinA, const int pinB) {
5784
if(!pwm_frequency || !_isset(pwm_frequency) ) pwm_frequency = _PWM_FREQUENCY; // default frequency 25khz
5885
else pwm_frequency = _constrain(pwm_frequency, 0, _PWM_FREQUENCY_MAX); // constrain to 50kHz max
@@ -123,6 +150,12 @@ void* _configure4PWM(long pwm_frequency,const int pinA, const int pinB, const in
123150

124151

125152

153+
void _writeDutyCycle1PWM(float dc_a, void* params){
154+
ledcWrite(((ESP32LEDCDriverParams*)params)->channels[0], _constrain(_PWM_RES*dc_a, 0, _PWM_RES));
155+
}
156+
157+
158+
126159
void _writeDutyCycle2PWM(float dc_a, float dc_b, void* params){
127160
ledcWrite(((ESP32LEDCDriverParams*)params)->channels[0], _constrain(_PWM_RES*dc_a, 0, _PWM_RES));
128161
ledcWrite(((ESP32LEDCDriverParams*)params)->channels[1], _constrain(_PWM_RES*dc_b, 0, _PWM_RES));

0 commit comments

Comments
 (0)