-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for target #795
Comments
Hi @Micilera , I'm now looking into this trying to find an explanation for that logic. if (first_loop) residency_start_ms += (TEMP_RESIDENCY_TIME) * 1000UL; Without it, everything should work as expected, am I right? |
The first loop, when setting the temperature, stretches to allow time for the thermal resistance to accumulate heat before checking whether or not there is a rise in temperature... |
@Micilera , you can have a look here: it's the commit that introduced that logic in Marlin a year ago. Commit message says:
I hope this can help you understand better... |
Sirs,
static uint32_t millis_counter = 100000; // Starting value. Any value is ok
uint32_t millis(void) {
return millis_counter;
}
uint32_t tick(void) {
return ++millis_counter;
}
void Heater::test_timer()
{
long_timer_t residency_start_timer;
uint32_t t_before, t_after;
bool b_running, b_pending;
tick();
residency_start_timer.start((TEMP_RESIDENCY_TIME) * 1000UL);
t_before = millis();
do
{
tick();
b_running = residency_start_timer.isRunning();
b_pending = residency_start_timer.pending((TEMP_RESIDENCY_TIME) * 1000);
} while ((b_running == false) || (b_pending == true));
t_after = millis();
printf("Time elapsed: %lu b_running %d b_pending %d\n", t_after-t_before, b_running, b_pending);
} ...and the output is:
Please made a look at your class timer: if (ms <= ms + period_ms) { // If not an overflow, this test is always true, as all unsigned numbers.
if ((now >= ms + period_ms) || (now < ms)) expired = true; // Second condition ?????
}
else if ((now >= ms + period_ms) && (now < ms)) expired = true; and please think a little bit about this logic. Hope that all of the above could be helpful. |
Sorry I didn't want to put the text in bold. |
The timer class can be called short or long, this is to save ram space for some timers.
Now when timer is short, ms and period_ms is short. now is same uint16 and it's equal to millis(), for example millis() = 120000, now is equal 54565 if ((54565 >= 60000 + 15000) && (54565 < 60000) expired= true Sorry for my bad english. The short timer class is used to see if a maximum of 65535 milliseconds then 65 seconds have passed. |
Sirs,
and this is the answer: Time elapsed: 1 b_running 1 b_pending 0 ================================================= |
@Micilera just a quick message to tell you I fixed your comment above 👍 |
Sirs, Now it is time for you to remove the flag 'first loop' from the WaitToTarget() for the following reasons:
|
v4.3.9
Please look at the method Heater::wait_for_target().
I can't understand the logic.
In the following there are some scenarios:
0) Setup is: TEMP_RESIDENCY_TIME = 10, TEMP_WINDOW = 1, HOTEND_HYSTERESIS 2
B) residency_start_ms is zero
C) So the temperature error temp_diff 0.9 is less than TEMP_WINDOW
D) The timer is set to: residency_start_ms = now+10s because is the very first time
E) The second loop, target_temperature = 250, current_temperature = 249.0,
F) The temperature error is inside the histeresis range, so the timer is not touch
G) The exit condition of the loop is relative to now vs. (residency_start_ms + 10)
H) So the timeout is 20s, because residency_start_ms was set 10s ahead.
B) residency_start_ms is zero
C) So the temperature error temp_diff is NOT less than TEMP_WINDOW
D) The timer is not set
E) The second loop, , target_temperature = 250, current_temperature = 249.1,
F) residency_start_ms is zero
G) So the temperature error temp_diff 0.9 is less than TEMP_WINDOW
H) The timer is set to: residency_start_ms = now because it is no more the very first time
I) Suppose that the temperature will not change
L) So the timeout is 10s.
M) Why two different timeouts just because the very first time the temperature are a little bit different?
E) The second loop, target_temperature = 250, current_temperature = 247.9,
F) The temperature error is outside the histeresis range, so the timer is set residency_start_ms = now
G) The third loop, target_temperature = 250, current_temperature = 249.0 and will not change
H) The temperature error is inside the histeresis range, so the timer is not touch
I) The exit condition of the loop is relative to now vs. (residency_start_ms + 10)
L) So the timeout is 10s. The timeout is less that the timeout of scenario 1
where the temperature are much closer to the target.
The above are only some undesiderable behaviours of this logic. Could you please explain?
The text was updated successfully, but these errors were encountered: