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
dcc269a9
Commit
dcc269a9
authored
7 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
ini co
parents
No related branches found
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
+237
-0
237 additions, 0 deletions
bake_out_ctrl/bake_out_ctrl.ino
with
237 additions
and
0 deletions
bake_out_ctrl/bake_out_ctrl.ino
0 → 100644
+
237
−
0
View file @
dcc269a9
#include
<SPI.h>
#include
<Controllino.h>
#include
<Ethernet.h>
#define MAXTEMP 195
#define TEMPSLOPEPERHOUR 30
#define HOLDTIMEHOUR 1
#define TARGETTEMPHIGH 180
#define TARGETTEMPEND 100
#define ROOMTEMP 23
#define BREAKTEMP 10
#define MAXVOLT 10
#define MINTOSECOND 60
#define HOURTOSECOND 3600
#define DAYTOSECOND 86400
/*
^
|
| Alarm D10, R1
T in C |
|--- MAXTEMP ----------------------------- MAXTEMP ----------
|
|
| xxxxxxxxxxxxxxxxxxxx TARGETTEMPHIGH
| xx | xx
| xx | xx
| xxx | xx
| xx| TEMPSLOPE xx
| xx | +-------xx TARGETTEMPEND
| xx |
| xx |
| xx |
| xx TEMPSLOPE
| xx |
| xx----------+
| x
|
|
|--- BREAKTEMP --------------------------- BREAKTEMP ---------
|
| Alarm DO0, R0
|
+|--t0--------------t1--------------------t2-----t3-------------------->
+
t in h
*/
// serial ---
#define BAUD 9600
// tcp ---
#define PORT 9009
byte
mac
[]
=
{
0x00
,
0x50
,
0x56
,
0x1E
,
0x38
,
0x35
};
IPAddress
ip
(
192
,
168
,
98
,
134
);
EthernetServer
server
(
PORT
);
String
cmd
,
param
;
// 0-10V out ---
int
analogOutPercent0
=
0
;
// initial value 0-100 percent
// 0-10V in
int
measureAI0
=
0
;
/*
unsigned long: 0 to 4,294,967,295 (2^32 - 1)
d.h. nie länger als:
> 2^32/60/60/24/365
[1] 136.1925 Jahre ausheizen!
*/
unsigned
long
get_abs_seconds
()
{
int
day
=
Controllino_GetDay
();
int
hour
=
Controllino_GetHour
();
int
minute
=
Controllino_GetMinute
();
int
second
=
Controllino_GetSecond
();
return
second
+
minute
*
MINTOSECOND
+
hour
*
HOURTOSECOND
+
day
*
DAYTOSECOND
;
}
int
get_current_temperature
()
{
int
val
=
0
;
val
=
analogRead
(
CONTROLLINO_AI12
);
return
map
(
val
,
0
,
1023
,
0
,
MAXTEMP
);
}
int
get_t1
(){
return
(
TARGETTEMPHIGH
-
ROOMTEMP
)
/
TEMPSLOPEPERHOUR
*
HOURTOSECOND
;
}
int
get_t2
(){
int
t1
=
get_t1
();
return
t1
+
HOLDTIMEHOUR
*
HOURTOSECOND
;
}
int
get_t3
(){
int
t2
=
get_t2
();
return
t2
+
(
TARGETTEMPHIGH
-
TARGETTEMPEND
)
/
TEMPSLOPEPERHOUR
*
HOURTOSECOND
;
}
/*
t1...t3: see drawing
*/
char
get_current_state
()
{
char
state
=
'n'
;
//u<n>defined
int
current_time
=
get_abs_seconds
();
int
t1
=
get_t1
();
int
t2
=
get_t2
();
int
t3
=
get_t3
();
if
(
current_time
<
t1
)
{
state
=
'u'
;
// ramp <u>p
}
if
(
current_time
>
t1
&&
current_time
<
t2
)
{
state
=
'b'
;
// <b>akeout
}
if
(
current_time
>
t2
&&
current_time
<
t3
)
{
state
=
'd'
;
// ramp <d>own'
}
if
(
current_time
>
t3
)
{
state
=
'e'
;
// <e>nd hold
}
return
state
;
}
void
set_indicators
(
int
current_seconds
)
{
char
state
=
get_current_state
();
switch
(
state
){
case
'n'
:
digitalWrite
(
CONTROLLINO_D0
,
true
);
break
;
case
'u'
:
digitalWrite
(
CONTROLLINO_D1
,
true
);
break
;
case
'b'
:
digitalWrite
(
CONTROLLINO_D2
,
true
);
break
;
case
'd'
:
digitalWrite
(
CONTROLLINO_D3
,
true
);
break
;
case
'e'
:
digitalWrite
(
CONTROLLINO_D4
,
true
);
break
;
}
}
int
get_target_temperature
()
{
int
curr_temp
=
get_current_temperature
();
int
t1
=
get_t1
();
int
t2
=
get_t2
();
int
t3
=
get_t3
();
int
curr_time
=
get_abs_seconds
();
int
target_temp
=
0
;
char
state
=
get_current_state
();
switch
(
state
){
case
'n'
:
break
;
case
'u'
:
target_temp
=
ROOMTEMP
+
TEMPSLOPEPERHOUR
*
curr_time
/
HOURTOSECOND
;
break
;
case
'b'
:
target_temp
=
TARGETTEMPHIGH
;
break
;
case
'd'
:
target_temp
=
TARGETTEMPHIGH
-
TEMPSLOPEPERHOUR
*
(
curr_time
-
t2
)
/
HOURTOSECOND
;
break
;
case
'e'
:
target_temp
=
TARGETTEMPEND
;
break
;
}
return
target_temp
;
}
int
get_voltage
(
int
target_temp
,
int
current_temp
)
{
float
volt
=
0.0
;
int
diff
=
target_temp
-
current_temp
;
if
(
diff
<
0
)
{
volt
=
0.0
;
}
else
{
//volt = ---
}
return
volt
;
}
void
setup
()
{
// ini serial ---
Serial
.
begin
(
BAUD
);
// ini tcp server ---
Ethernet
.
begin
(
mac
,
ip
);
server
.
begin
();
// ini realtime clock
Controllino_RTC_init
(
0
);
Controllino_SetTimeDate
(
0
,
0
,
0
,
0
,
0
,
0
,
0
);
// set initial values to the RTC chip
pinMode
(
CONTROLLINO_AO0
,
OUTPUT
);
pinMode
(
CONTROLLINO_AO1
,
OUTPUT
);
pinMode
(
CONTROLLINO_AI12
,
INPUT
);
pinMode
(
CONTROLLINO_AI13
,
INPUT
);
}
void
loop
()
{
int
analogOut
=
0
;
// 0 - 255 to be set
long
int
analogOutVoltage
=
0
;
// 0 - 10 000 mV to be set
long
int
analogOutCurrent
=
0
;
// 0 - 20 000 uA to be set
int
curr_temp
=
get_current_temperature
();
int
target_temp
=
get_target_temperature
();
char
state
=
get_current_state
();
int
abs_s
=
get_abs_seconds
();
float
volt
=
get_voltage
(
target_temp
,
curr_temp
);
Serial
.
print
(
"Temperature is: "
);
Serial
.
print
(
curr_temp
);
Serial
.
println
(
" C
\n
"
);
Serial
.
print
(
"Temperature should: "
);
Serial
.
print
(
target_temp
);
Serial
.
println
(
" C
\n
"
);
Serial
.
print
(
"abs. time is: "
);
Serial
.
print
(
abs_s
);
Serial
.
println
(
" s
\n
"
);
Serial
.
print
(
"current state is: "
);
Serial
.
print
(
state
);
Serial
.
print
(
"
\n
"
);
Serial
.
print
(
"voltage will be: "
);
Serial
.
print
(
volt
);
Serial
.
print
(
"
\n\n\n\n\n\n\n\n\n
"
);
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