Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MarlinKimbra
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
MarlinKimbra
Commits
a1f074de
Commit
a1f074de
authored
May 11, 2016
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add fast PWM for cooler
parent
9947f434
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
23 deletions
+48
-23
temperature.cpp
MK/module/temperature/temperature.cpp
+48
-23
No files found.
MK/module/temperature/temperature.cpp
View file @
a1f074de
...
@@ -99,6 +99,10 @@ float current_temperature_cooler = 0.0;
...
@@ -99,6 +99,10 @@ float current_temperature_cooler = 0.0;
unsigned
char
soft_pwm_bed
;
unsigned
char
soft_pwm_bed
;
unsigned
char
soft_pwm_cooler
;
unsigned
char
soft_pwm_cooler
;
void
setPwmCooler
(
unsigned
char
pwm
);
unsigned
char
getPwmCooler
(
bool
soft
=
true
);
#if ENABLED(BABYSTEPPING)
#if ENABLED(BABYSTEPPING)
volatile
int
babystepsTodo
[
3
]
=
{
0
};
volatile
int
babystepsTodo
[
3
]
=
{
0
};
#endif
#endif
...
@@ -266,6 +270,25 @@ static void updateTemperaturesFromRawValues();
...
@@ -266,6 +270,25 @@ static void updateTemperaturesFromRawValues();
//================================ Functions ================================
//================================ Functions ================================
//===========================================================================
//===========================================================================
void
setPwmCooler
(
unsigned
char
pwm
)
{
soft_pwm_cooler
=
pwm
>>
1
;
#if ENABLED(FAST_PWM_COOLER)
analogWrite
(
COOLER_PIN
,
pwm
);
#endif
}
unsigned
char
getPwmCooler
(
bool
soft
=
true
)
{
if
(
soft
)
return
soft_pwm_cooler
;
#if ENABLED(FAST_PWM_COOLER)
return
analogRead
(
COOLER_PIN
);
#else
return
soft_pwm_cooler
*
2
;
#endif
}
void
autotempShutdown
()
{
void
autotempShutdown
()
{
#if ENABLED(AUTOTEMP)
#if ENABLED(AUTOTEMP)
if
(
autotemp_enabled
)
{
if
(
autotemp_enabled
)
{
...
@@ -325,8 +348,10 @@ void autotempShutdown() {
...
@@ -325,8 +348,10 @@ void autotempShutdown() {
if
(
temp_controller
==
-
1
)
if
(
temp_controller
==
-
1
)
soft_pwm_bed
=
bias
=
d
=
MAX_BED_POWER
/
2
;
soft_pwm_bed
=
bias
=
d
=
MAX_BED_POWER
/
2
;
else
if
(
temp_controller
<
-
1
)
else
if
(
temp_controller
<
-
1
)
{
soft_pwm_cooler
=
bias
=
d
=
MAX_COOLER_POWER
/
2
;
bias
=
d
=
MAX_COOLER_POWER
/
2
;
setPwmCooler
(
MAX_COOLER_POWER
);
}
else
else
soft_pwm
[
temp_controller
]
=
bias
=
d
=
PID_MAX
/
2
;
soft_pwm
[
temp_controller
]
=
bias
=
d
=
PID_MAX
/
2
;
...
@@ -358,8 +383,8 @@ void autotempShutdown() {
...
@@ -358,8 +383,8 @@ void autotempShutdown() {
if
(
running
&&
((
input
>
temp
&&
temp_controller
>=
-
1
)
||
(
input
<
temp
&&
temp_controller
<
-
1
)))
{
if
(
running
&&
((
input
>
temp
&&
temp_controller
>=
-
1
)
||
(
input
<
temp
&&
temp_controller
<
-
1
)))
{
if
(
ms
>
t2
+
5000UL
)
{
if
(
ms
>
t2
+
5000UL
)
{
running
=
false
;
running
=
false
;
if
(
temp_controller
<
-
1
)
if
(
temp_controller
<
-
1
)
soft_pwm_cooler
=
(
bias
-
d
)
>>
1
;
setPwmCooler
((
bias
-
d
))
;
else
if
(
temp_controller
<
0
)
else
if
(
temp_controller
<
0
)
soft_pwm_bed
=
(
bias
-
d
)
>>
1
;
soft_pwm_bed
=
(
bias
-
d
)
>>
1
;
else
else
...
@@ -420,7 +445,7 @@ void autotempShutdown() {
...
@@ -420,7 +445,7 @@ void autotempShutdown() {
#endif
#endif
#if ENABLED(PIDTEMPCOOLER)
#if ENABLED(PIDTEMPCOOLER)
if
(
temp_controller
<
-
1
)
if
(
temp_controller
<
-
1
)
s
oft_pwm_cooler
=
(
bias
+
d
)
>>
1
;
s
etPwmCooler
((
bias
+
d
))
;
#endif
#endif
cycles
++
;
cycles
++
;
if
(
temp_controller
<
-
1
)
if
(
temp_controller
<
-
1
)
...
@@ -975,27 +1000,27 @@ void manage_temp_controller() {
...
@@ -975,27 +1000,27 @@ void manage_temp_controller() {
#if ENABLED(PIDTEMPCOOLER)
#if ENABLED(PIDTEMPCOOLER)
float
pid_output
=
get_pid_output_cooler
();
float
pid_output
=
get_pid_output_cooler
();
s
oft_pwm_cooler
=
current_temperature_cooler
>
COOLER_MINTEMP
&&
current_temperature_cooler
<
COOLER_MAXTEMP
?
(
int
)
pid_output
>>
1
:
0
;
s
etPwmCooler
(
current_temperature_cooler
>
COOLER_MINTEMP
&&
current_temperature_cooler
<
COOLER_MAXTEMP
?
(
int
)
pid_output
:
0
)
;
#elif ENABLED(COOLER_LIMIT_SWITCHING)
#elif ENABLED(COOLER_LIMIT_SWITCHING)
// Check if temperature is within the correct band
// Check if temperature is within the correct band
if
(
current_temperature_cooler
>
COOLER_MINTEMP
&&
current_temperature_cooler
<
COOLER_MAXTEMP
)
{
if
(
current_temperature_cooler
>
COOLER_MINTEMP
&&
current_temperature_cooler
<
COOLER_MAXTEMP
)
{
if
(
current_temperature_cooler
>=
target_temperature_cooler
+
COOLER_HYSTERESIS
)
if
(
current_temperature_cooler
>=
target_temperature_cooler
+
COOLER_HYSTERESIS
)
s
oft_pwm_cooler
=
MAX_COOLER_POWER
>>
1
;
s
etPwmCooler
(
MAX_COOLER_POWER
)
;
else
if
(
current_temperature_cooler
<=
target_temperature_cooler
-
COOLER_HYSTERESIS
)
else
if
(
current_temperature_cooler
<=
target_temperature_cooler
-
COOLER_HYSTERESIS
)
s
oft_pwm_cooler
=
0
;
s
etPwmCooler
(
0
)
;
}
}
else
{
// NEXTIME XXX here we have to manage hw pwm?
else
{
s
oft_pwm_cooler
=
0
;
s
etPwmCooler
(
0
)
;
WRITE_COOLER
(
LOW
);
WRITE_COOLER
(
LOW
);
}
}
#else // COOLER_LIMIT_SWITCHING
#else // COOLER_LIMIT_SWITCHING
// Check if temperature is within the correct range
// Check if temperature is within the correct range
if
(
current_temperature_cooler
>
COOLER_MINTEMP
&&
current_temperature_cooler
<
COOLER_MAXTEMP
)
{
if
(
current_temperature_cooler
>
COOLER_MINTEMP
&&
current_temperature_cooler
<
COOLER_MAXTEMP
)
{
s
oft_pwm_cooler
=
current_temperature_cooler
>
target_temperature_cooler
?
MAX_COOLER_POWER
>>
1
:
0
;
s
etPwmCooler
(
current_temperature_cooler
>
target_temperature_cooler
?
MAX_COOLER_POWER
:
0
)
}
}
else
{
else
{
s
oft_pwm_cooler
=
0
;
s
etPwmCooler
(
0
)
;
WRITE_COOLER
(
LOW
);
WRITE_COOLER
(
LOW
);
}
}
#endif
#endif
...
@@ -1631,8 +1656,8 @@ void disable_all_coolers() {
...
@@ -1631,8 +1656,8 @@ void disable_all_coolers() {
#if HAS(TEMP_COOLER)
#if HAS(TEMP_COOLER)
target_temperature_cooler
=
0
;
target_temperature_cooler
=
0
;
s
oft_pwm_cooler
=
0
;
s
etPwmCooler
(
0
)
;
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
WRITE_COOLER
(
LOW
);
WRITE_COOLER
(
LOW
);
#endif
#endif
#endif
#endif
...
@@ -1790,7 +1815,7 @@ ISR(TIMER0_COMPB_vect) {
...
@@ -1790,7 +1815,7 @@ ISR(TIMER0_COMPB_vect) {
#if HAS(HEATER_BED)
#if HAS(HEATER_BED)
ISR_STATICS
(
BED
);
ISR_STATICS
(
BED
);
#endif
#endif
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
ISR_STATICS
(
COOLER_DEV
);
ISR_STATICS
(
COOLER_DEV
);
#endif
#endif
...
@@ -1826,9 +1851,9 @@ ISR(TIMER0_COMPB_vect) {
...
@@ -1826,9 +1851,9 @@ ISR(TIMER0_COMPB_vect) {
soft_pwm_BED
=
soft_pwm_bed
;
soft_pwm_BED
=
soft_pwm_bed
;
WRITE_HEATER_BED
(
soft_pwm_BED
>
0
?
1
:
0
);
WRITE_HEATER_BED
(
soft_pwm_BED
>
0
?
1
:
0
);
#endif
#endif
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
soft_pwm_
cooler
=
soft_pwm_cooler
;
soft_pwm_
COOLER_DEV
=
soft_pwm_cooler
;
WRITE_COOLER
(
soft_pwm_
cooler
>
0
?
1
:
0
);
WRITE_COOLER
(
soft_pwm_
COOLER_DEV
>
0
?
1
:
0
);
#endif
#endif
#if ENABLED(FAN_SOFT_PWM)
#if ENABLED(FAN_SOFT_PWM)
soft_pwm_fan
=
fanSpeedSoftPwm
/
2
;
soft_pwm_fan
=
fanSpeedSoftPwm
/
2
;
...
@@ -1869,8 +1894,8 @@ ISR(TIMER0_COMPB_vect) {
...
@@ -1869,8 +1894,8 @@ ISR(TIMER0_COMPB_vect) {
#if HAS(HEATER_BED)
#if HAS(HEATER_BED)
if
(
soft_pwm_BED
<
pwm_count
)
WRITE_HEATER_BED
(
0
);
if
(
soft_pwm_BED
<
pwm_count
)
WRITE_HEATER_BED
(
0
);
#endif
#endif
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
if
(
soft_pwm_
cooler
<
pwm_count
)
WRITE_COOLER
(
0
);
if
(
soft_pwm_
COOLER_DEV
<
pwm_count
)
WRITE_COOLER
(
0
);
#endif
#endif
#if ENABLED(FAN_SOFT_PWM)
#if ENABLED(FAN_SOFT_PWM)
...
@@ -1953,7 +1978,7 @@ ISR(TIMER0_COMPB_vect) {
...
@@ -1953,7 +1978,7 @@ ISR(TIMER0_COMPB_vect) {
#if HAS(HEATER_BED)
#if HAS(HEATER_BED)
_SLOW_PWM_ROUTINE
(
BED
,
soft_pwm_bed
);
// BED
_SLOW_PWM_ROUTINE
(
BED
,
soft_pwm_bed
);
// BED
#endif
#endif
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
_SLOW_PWM_SOURINT
(
COOLER_DEV
,
soft_pwm_cooler
);
// COOLER
_SLOW_PWM_SOURINT
(
COOLER_DEV
,
soft_pwm_cooler
);
// COOLER
#endif
#endif
...
@@ -1972,7 +1997,7 @@ ISR(TIMER0_COMPB_vect) {
...
@@ -1972,7 +1997,7 @@ ISR(TIMER0_COMPB_vect) {
#if HAS(HEATER_BED)
#if HAS(HEATER_BED)
PWM_OFF_ROUTINE
(
BED
);
// BED
PWM_OFF_ROUTINE
(
BED
);
// BED
#endif
#endif
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
PWM_OFF_ROUTINE
(
COOLER_DEV
);
// COOLER
PWM_OFF_ROUTINE
(
COOLER_DEV
);
// COOLER
#endif
#endif
...
@@ -2044,7 +2069,7 @@ ISR(TIMER0_COMPB_vect) {
...
@@ -2044,7 +2069,7 @@ ISR(TIMER0_COMPB_vect) {
#if HAS(HEATER_BED)
#if HAS(HEATER_BED)
if
(
state_timer_heater_BED
>
0
)
state_timer_heater_BED
--
;
if
(
state_timer_heater_BED
>
0
)
state_timer_heater_BED
--
;
#endif
#endif
#if HAS(COOLER_DEV)
#if HAS(COOLER_DEV)
&& !ENABLED(FAST_PWM_COOLER)
if
(
state_timer_heater_COOLER_DEV
>
0
)
state_timer_heater_COOLER_DEV
--
;
if
(
state_timer_heater_COOLER_DEV
>
0
)
state_timer_heater_COOLER_DEV
--
;
#endif
#endif
}
// (pwm_count % 64) == 0
}
// (pwm_count % 64) == 0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment