mirror of https://github.com/arendst/Tasmota.git
8.3 fixes for Shutters (Stepper Motors) #8721
PWM control has changed in SDK. CHanged shutter functionality takes into consideration that physically the PWM frequency is minimum 40Hz
This commit is contained in:
parent
fb39378960
commit
252100704c
|
@ -206,7 +206,7 @@ void ShutterInit(void)
|
||||||
Shutter.pwm_frequency[i] = 0;
|
Shutter.pwm_frequency[i] = 0;
|
||||||
Shutter.accelerator[i] = 0;
|
Shutter.accelerator[i] = 0;
|
||||||
analogWriteFreq(Shutter.pwm_frequency[i]);
|
analogWriteFreq(Shutter.pwm_frequency[i]);
|
||||||
analogWrite(Pin(GPIO_PWM1, i), 50);
|
ExecuteCommandPower(Settings.shutter_startrelay[i]+2, 0, SRC_SHUTTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,13 +358,14 @@ void ShutterUpdatePosition(void)
|
||||||
Shutter.accelerator[i] = 0;
|
Shutter.accelerator[i] = 0;
|
||||||
Shutter.pwm_frequency[i] = Shutter.pwm_frequency[i] > 250 ? 250 : Shutter.pwm_frequency[i];
|
Shutter.pwm_frequency[i] = Shutter.pwm_frequency[i] > 250 ? 250 : Shutter.pwm_frequency[i];
|
||||||
analogWriteFreq(Shutter.pwm_frequency[i]);
|
analogWriteFreq(Shutter.pwm_frequency[i]);
|
||||||
analogWrite(Pin(GPIO_PWM1, i), 50);
|
analogWrite(Pin(GPIO_PWM1, i), 1);
|
||||||
Shutter.pwm_frequency[i] = 0;
|
Shutter.pwm_frequency[i] = 0;
|
||||||
analogWriteFreq(Shutter.pwm_frequency[i]);
|
analogWriteFreq(Shutter.pwm_frequency[i]);
|
||||||
while (RtcSettings.pulse_counter[i] < (uint32_t)(Shutter.target_position[i]-Shutter.start_position[i])*Shutter.direction[i]*Shutter.max_pwm_frequency/2000) {
|
while (RtcSettings.pulse_counter[i] < (uint32_t)(Shutter.target_position[i]-Shutter.start_position[i])*Shutter.direction[i]*Shutter.max_pwm_frequency/2000) {
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
analogWrite(Pin(GPIO_PWM1, i), 0);
|
//analogWrite(Pin(GPIO_PWM1, i), 0); // removed with 8. because of reset
|
||||||
|
ExecuteCommandPower(Settings.shutter_startrelay[i]+2, 0, SRC_SHUTTER);
|
||||||
Shutter.real_position[i] = ShutterCounterBasedPosition(i);
|
Shutter.real_position[i] = ShutterCounterBasedPosition(i);
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Real %d, pulsecount %d, start %d"), Shutter.real_position[i],RtcSettings.pulse_counter[i], Shutter.start_position[i]);
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Real %d, pulsecount %d, start %d"), Shutter.real_position[i],RtcSettings.pulse_counter[i], Shutter.start_position[i]);
|
||||||
|
|
||||||
|
@ -428,6 +429,7 @@ void ShutterStartInit(uint32_t i, int32_t direction, int32_t target_pos)
|
||||||
Shutter.pwm_frequency[i] = 0;
|
Shutter.pwm_frequency[i] = 0;
|
||||||
analogWriteFreq(Shutter.pwm_frequency[i]);
|
analogWriteFreq(Shutter.pwm_frequency[i]);
|
||||||
analogWrite(Pin(GPIO_PWM1, i), 0);
|
analogWrite(Pin(GPIO_PWM1, i), 0);
|
||||||
|
//ExecuteCommandPower(Settings.shutter_startrelay[i]+2, 1, SRC_SHUTTER);
|
||||||
RtcSettings.pulse_counter[i] = 0;
|
RtcSettings.pulse_counter[i] = 0;
|
||||||
Shutter.accelerator[i] = Shutter.max_pwm_frequency / (Shutter.motordelay[i]>0 ? Shutter.motordelay[i] : 1);
|
Shutter.accelerator[i] = Shutter.max_pwm_frequency / (Shutter.motordelay[i]>0 ? Shutter.motordelay[i] : 1);
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Ramp up: %d"), Shutter.accelerator[i]);
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SHT: Ramp up: %d"), Shutter.accelerator[i]);
|
||||||
|
@ -460,6 +462,7 @@ void ShutterWaitForMotorStop(uint32_t i)
|
||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
analogWrite(Pin(GPIO_PWM1, i), 0);
|
analogWrite(Pin(GPIO_PWM1, i), 0);
|
||||||
|
ExecuteCommandPower(Settings.shutter_startrelay[i]+2, 0, SRC_SHUTTER);
|
||||||
Shutter.real_position[i] = ShutterCounterBasedPosition(i);
|
Shutter.real_position[i] = ShutterCounterBasedPosition(i);
|
||||||
} else {
|
} else {
|
||||||
ExecuteCommandPower(Settings.shutter_startrelay[i], 0, SRC_SHUTTER);
|
ExecuteCommandPower(Settings.shutter_startrelay[i], 0, SRC_SHUTTER);
|
||||||
|
@ -902,6 +905,9 @@ void CmndShutterPosition(void)
|
||||||
ExecuteCommandPower(Settings.shutter_startrelay[index] +1, new_shutterdirection == 1 ? 0 : 1, SRC_SHUTTER);
|
ExecuteCommandPower(Settings.shutter_startrelay[index] +1, new_shutterdirection == 1 ? 0 : 1, SRC_SHUTTER);
|
||||||
// power on
|
// power on
|
||||||
ExecuteCommandPower(Settings.shutter_startrelay[index], 1, SRC_SHUTTER);
|
ExecuteCommandPower(Settings.shutter_startrelay[index], 1, SRC_SHUTTER);
|
||||||
|
if (SHT_OFF_ON__OPEN_CLOSE_STEPPER == Shutter.mode) {
|
||||||
|
ExecuteCommandPower(Settings.shutter_startrelay[index]+2, 1, SRC_SHUTTER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// now start the motor for the right direction, work for momentary and normal shutters.
|
// now start the motor for the right direction, work for momentary and normal shutters.
|
||||||
|
|
Loading…
Reference in New Issue