Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb Temperature Control
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Pascal Engeler
RBComb Temperature Control
Commits
b449a73b
Commit
b449a73b
authored
1 year ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
Changed to interrupt driven design
parent
bee6ba64
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
firmware/pid_playground/pid_playground.ino
+24
-51
24 additions, 51 deletions
firmware/pid_playground/pid_playground.ino
with
24 additions
and
51 deletions
firmware/pid_playground/pid_playground.ino
+
24
−
51
View file @
b449a73b
...
...
@@ -4,6 +4,7 @@
#include
<ad7124_registers.hpp>
#include
<spi_selecta.hpp>
#include
<temp_table.hpp>
#include
<DueTimer.h>
#define SPIRATE 84000000/32
...
...
@@ -55,9 +56,20 @@ void update_pid(double error, double* pid, const double* kpid, double& output){
}
}
/*Timekeeping*/
unsigned
long
t0
;
unsigned
long
t1
;
/*Set up Timer Interrupt Infrastructure*/
volatile
bool
printRq
=
false
;
const
long
printRqPeriod
=
750000
;
//print every 750ms
volatile
bool
pidUpdRq
=
false
;
const
long
pidUpdRqPeriod
=
750000
;
//update pid every 750ms
void
handlerPrint
(){
printRq
=
true
;
//set print request flag
}
void
handlerPid
(){
pidUpdRq
=
true
;
//set pid update request flag
}
/*Printing Buffer*/
char
printBuf
[
256
];
...
...
@@ -136,8 +148,10 @@ void setup() {
Spi_selecta
::
deselect_device
();
t0
=
micros
();
t1
=
micros
();
/*Start Interrupt Timers*/
Timer
.
getAvailable
().
attachInterrupt
(
handlerPid
).
start
(
pidUpdRqPeriod
);
delay
(
350
);
//delay the two timers by roughly half a period to balance load
Timer
.
getAvailable
().
attachInterrupt
(
handlerPrint
).
start
(
printRqPeriod
);
}
void
loop
()
{
...
...
@@ -156,7 +170,8 @@ void loop() {
double
current_temperature
=
data_to_temperature
(
adc1_data
);
//Update PID
if
(
micros
()
>
t0
+
750000
){
//This only runs every 750ms
if
(
pidUpdRq
){
pidUpdRq
=
false
;
//clear request flag
pid_output
=
0.
;
update_pid
(
target_temperature
-
current_temperature
,
pid_arr
,
kpid_arr
,
pid_output
);
//Update PWM Output
...
...
@@ -164,43 +179,10 @@ void loop() {
Ltc6992
::
set_level
(
pid_output
);
//Ltc6992::set_level(0.42);
}
t0
=
micros
();
}
}
Spi_selecta
::
deselect_device
();
/*
Spi_selecta::select_device(&adc_2);
if(adc_2.data_available()){
uint32_t status_channel1 = adc_2.read_register(REG_Status, 1);
adc2_data = adc_2.get_data();
uint32_t status_channel2 = adc_2.read_register(REG_Status, 1);
uint32_t adc2_data_backup = adc2_data;
unsigned channel = static_cast<unsigned>(adc2_data & 0x000000FF);
adc2_data = ((adc2_data >> 8) & 0x00FFFFFF);
if(channel == (channel & 3)){ //channel must be an element of {0, 1, 2, 3}
adc2_temps[channel] = data_to_temperature(adc2_data);
Serial.print("Valid Channel: ");
Serial.print(channel);
Serial.print(" (");
Serial.print(status_channel1, HEX);
Serial.print(", ");
Serial.print(status_channel2, HEX);
Serial.print("), Data: 0x");
Serial.print(adc2_data_backup, HEX);
Serial.print("\n");
}
else{//something's fishy
Serial.print("Erroneous Channel: ");
Serial.print(channel);
Serial.print(", Data: 0x");
Serial.print(adc2_data_backup, HEX);
Serial.print("\n");
}
}
Spi_selecta::deselect_device();
*/
Spi_selecta
::
select_device
(
&
adc_2
);
if
(
adc_2
.
data_available
()){
...
...
@@ -219,23 +201,14 @@ void loop() {
if
(
status_channel1
<
4
){
adc2_temps
[
status_channel1
]
=
data_to_temperature
(
adc2_data
);
}
/*
Serial.print("Valid Channel: ");
Serial.print(status_channel1, HEX);
Serial.print(", Data: 0x");
Serial.print(adc2_data_backup, HEX);
Serial.print(", Error: ");
Serial.print(error, HEX);
Serial.print("\n");
*/
}
Spi_selecta
::
deselect_device
();
if
(
micros
()
>
t1
+
750100
){
/*print every 750ms*/
/*Format: T_loop T_ool_1 T_ool_2 T_ool_3 PID*/
if
(
printRq
){
printRq
=
false
;
/*Format: T_loop T_ool_1 T_ool_2 T_ool_3 PID P I D*/
sprintf
(
printBuf
,
"Tloop:%f,Tool1:%f,Tool2:%f,Tool3:%f,Tool4:%f,PID:%f,P:%f,I:%f,D:%f
\n
"
,
data_to_temperature
(
adc1_data
),
adc2_temps
[
0
],
adc2_temps
[
1
],
adc2_temps
[
2
],
adc2_temps
[
3
],
pid_output
,
pid_arr
[
0
],
pid_arr
[
1
],
pid_arr
[
2
]);
Serial
.
print
(
printBuf
);
t1
=
micros
();
}
}
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