Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
bake_out_ctrl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
bake_out_ctrl
Commits
2f018a8e
Commit
2f018a8e
authored
7 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
--> refactor state
parent
c752a039
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bake_out_ctrl/bake_out_ctrl.ino
+77
-37
77 additions, 37 deletions
bake_out_ctrl/bake_out_ctrl.ino
with
77 additions
and
37 deletions
bake_out_ctrl/bake_out_ctrl.ino
+
77
−
37
View file @
2f018a8e
...
...
@@ -14,7 +14,9 @@
#define BREAKTEMP 10.0
#define BREAKDEVTEMP 5.0 // max deviation before fail
#define MAXVOLT 10
#define MAXVOLT 10.0
#define CTRLFACTOR 0.2
#define MINTOSECOND 60
#define HOURTOSECOND 3600
...
...
@@ -121,10 +123,14 @@ unsigned long get_rel_seconds() {
}
float
get_current_temperature
()
{
float
val
=
0.0
;
float
val
=
analogRead
(
CONTROLLINO_AI12
);
float
ct
=
val
/
1023.0
*
MAXTEMP
;
//map(val, 0, 1023, 0.0, MAXTEMP);
Serial
.
print
(
"temperature is: "
);
Serial
.
print
(
ct
);
Serial
.
println
(
" C
\n
"
);
val
=
analogRead
(
CONTROLLINO_AI12
);
return
val
/
1023.0
*
MAXTEMP
;
//map(val, 0, 1023, 0.0, MAXTEMP);
return
ct
;
}
/*
...
...
@@ -143,7 +149,7 @@ unsigned long get_t3(){
}
char
get_current_state
()
{
char
state
=
'n'
;
//u<n>defined
char
state
=
'n'
;
//u<n>defined
unsigned
long
rel_time
=
get_rel_seconds
();
unsigned
long
abs_time
=
get_abs_seconds
();
...
...
@@ -167,6 +173,11 @@ char get_current_state() {
state
=
'e'
;
// <e>nd hold
}
}
Serial
.
print
(
"current state is (w: waiting for start time, u:ramp up, b: bake out, d:ramp down, e: end hold): "
);
Serial
.
print
(
state
);
Serial
.
println
(
"
\n
"
);
return
state
;
}
...
...
@@ -174,19 +185,39 @@ void set_indicators() {
char
state
=
get_current_state
();
switch
(
state
){
case
'
n
'
:
case
'
w
'
:
digitalWrite
(
CONTROLLINO_D0
,
true
);
digitalWrite
(
CONTROLLINO_D1
,
false
);
digitalWrite
(
CONTROLLINO_D2
,
false
);
digitalWrite
(
CONTROLLINO_D3
,
false
);
digitalWrite
(
CONTROLLINO_D4
,
false
);
break
;
case
'u'
:
digitalWrite
(
CONTROLLINO_D0
,
false
);
digitalWrite
(
CONTROLLINO_D1
,
true
);
digitalWrite
(
CONTROLLINO_D2
,
false
);
digitalWrite
(
CONTROLLINO_D3
,
false
);
digitalWrite
(
CONTROLLINO_D4
,
false
);
break
;
case
'b'
:
digitalWrite
(
CONTROLLINO_D0
,
false
);
digitalWrite
(
CONTROLLINO_D1
,
false
);
digitalWrite
(
CONTROLLINO_D2
,
true
);
digitalWrite
(
CONTROLLINO_D3
,
false
);
digitalWrite
(
CONTROLLINO_D4
,
false
);
break
;
case
'd'
:
digitalWrite
(
CONTROLLINO_D0
,
false
);
digitalWrite
(
CONTROLLINO_D1
,
false
);
digitalWrite
(
CONTROLLINO_D2
,
false
);
digitalWrite
(
CONTROLLINO_D3
,
true
);
digitalWrite
(
CONTROLLINO_D4
,
false
);
break
;
case
'e'
:
digitalWrite
(
CONTROLLINO_D0
,
false
);
digitalWrite
(
CONTROLLINO_D1
,
false
);
digitalWrite
(
CONTROLLINO_D2
,
false
);
digitalWrite
(
CONTROLLINO_D3
,
false
);
digitalWrite
(
CONTROLLINO_D4
,
true
);
break
;
}
...
...
@@ -220,21 +251,32 @@ float get_target_temperature() {
target_temp
=
TARGETTEMPEND
;
break
;
}
Serial
.
print
(
"temperature should: "
);
Serial
.
print
(
target_temp
);
Serial
.
println
(
" C
\n
"
);
return
target_temp
;
}
void
set_break_temperature
(
bool
s
)
{
digitalWrite
(
CONTROLLINO_D6
,
s
);
digitalWrite
(
CONTROLLINO_RELAY_00
,
!
s
);
}
void
set_under_temperature
(
bool
s
)
{
digitalWrite
(
CONTROLLINO_D7
,
s
);
digitalWrite
(
CONTROLLINO_D6
,
s
);
digitalWrite
(
CONTROLLINO_RELAY_00
,
!
s
);
}
void
set_over_temperature
(
bool
s
)
{
digitalWrite
(
CONTROLLINO_D8
,
s
);
// open R0 (Klemme1-2)
digitalWrite
(
CONTROLLINO_D7
,
s
);
digitalWrite
(
CONTROLLINO_RELAY_00
,
!
s
);
}
void
set_max_temperature
(
bool
s
)
{
digitalWrite
(
CONTROLLINO_D9
,
s
);
// open R0 (Klemme1-2)
digitalWrite
(
CONTROLLINO_D7
,
s
);
digitalWrite
(
CONTROLLINO_RELAY_00
,
!
s
);
}
float
get_rel_heatpower
(
float
targ_temp
,
float
curr_temp
)
{
...
...
@@ -267,29 +309,33 @@ float get_rel_heatpower(float targ_temp, float curr_temp) {
set_under_temperature
(
false
);
p
=
d
/
BREAKDEVTEMP
;
}
return
p
;
}
void
write_info_serial
(
char
st
,
unsigned
long
se
,
float
ct
,
float
tt
,
float
hp
)
{
Serial
.
print
(
"current state is (w: waiting for start time, u:ramp up, b: bake out, d:ramp down, e: end hold): "
);
Serial
.
print
(
st
);
Serial
.
println
(
"
\n
"
);
Serial
.
print
(
"temperature is: "
);
Serial
.
print
(
ct
);
Serial
.
println
(
" C
\n
"
);
Serial
.
print
(
"
temperature should
: "
);
Serial
.
print
(
tt
);
Serial
.
print
ln
(
" C
\n
"
);
Serial
.
print
(
"
heat power target
: "
);
Serial
.
print
(
p
);
Serial
.
print
(
"
\n
"
);
Serial
.
print
(
"abs. time is: "
);
Serial
.
print
(
se
);
Serial
.
println
(
"sec
\n
"
);
return
p
;
}
Serial
.
print
(
"heat power target: "
);
Serial
.
print
(
hp
);
Serial
.
print
(
"
\n\n\n\n\n\n\n\n\n
"
);
void
set_voltage
()
{
char
s
=
get_current_state
();
if
(
s
==
'u'
||
s
==
'b'
||
s
==
'd'
||
s
==
'e'
)
{
float
ct
=
get_current_temperature
();
float
tt
=
get_target_temperature
();
float
hp
=
get_rel_heatpower
(
tt
,
ct
);
float
v
=
hp
*
MAXVOLT
*
CTRLFACTOR
;
float
V
=
v
/
MAXVOLT
*
255
;
analogWrite
(
CONTROLLINO_AO0
,
V
);
analogWrite
(
CONTROLLINO_AO1
,
V
);
Serial
.
print
(
"control voltage (0..255): "
);
Serial
.
print
(
v
);
Serial
.
print
(
" ("
);
Serial
.
print
(
V
);
Serial
.
print
(
")"
);
Serial
.
print
(
"
\n
"
);
}
}
void
net_read
(){
...
...
@@ -357,15 +403,9 @@ String net_exec(String cmd, String param) {
void
loop
()
{
char
st
=
get_current_state
();
unsigned
long
se
=
get_rel_seconds
();
float
ct
=
get_current_temperature
();
float
tt
=
get_target_temperature
();
float
hp
=
get_rel_heatpower
(
tt
,
ct
);
net_read
();
set_voltage
();
set_indicators
();
write_info_serial
(
st
,
se
,
ct
,
tt
,
hp
);
net_read
();
delay
(
1000
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment