Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SolderStationMk2_SW
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
Container Registry
Model registry
Operate
Environments
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
Flax
SolderStationMk2_SW
Commits
1f291497
Commit
1f291497
authored
1 year ago
by
Flax
Browse files
Options
Downloads
Patches
Plain Diff
STM32L011K4 : updated temperature regulation.
parent
6743590f
No related branches found
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
SolderStationMk2_NucleoSTM32L011K4/Core/Src/temperatureRegulation.c
+36
-13
36 additions, 13 deletions
...ionMk2_NucleoSTM32L011K4/Core/Src/temperatureRegulation.c
with
36 additions
and
13 deletions
SolderStationMk2_NucleoSTM32L011K4/Core/Src/temperatureRegulation.c
+
36
−
13
View file @
1f291497
...
...
@@ -38,6 +38,8 @@
#define cREGAdcErrorThres (4090U)
#define cREGAdcToTempFilter (200U)
// ===============
// Local variables
// ===============
...
...
@@ -52,10 +54,13 @@ static uint16_t RegTempMeasBuffer_U16A[2U];
static
int32_t
RegPwmDyc_S32
;
static
uint32_t
RegPwmDyc_U32
;
static
uint16_t
RegTempDeg_U16
;
static
uint16_t
RegTempDegFilt_U16
;
static
uint16_t
RegTempFiltCnt_U16
;
// PID
static
int32_t
RegEpsilon_S32A
[
2U
];
// ==========================
// Local functions prototypes
// ==========================
...
...
@@ -81,7 +86,6 @@ void REGInit (void)
void
REGStart
(
void
)
{
mREDAdcEnable
();
// mREGAdcStartConversion();
}
void
REGStop
(
void
)
...
...
@@ -102,6 +106,7 @@ void REGCyclicTask (void)
if
(
RegTempMeasBuffer_U16A
[
1
]
>=
cREGAdcErrorThres
)
{
// Error
RegErrorState_B
=
true
;
}
}
else
...
...
@@ -116,25 +121,35 @@ void REGCyclicTask (void)
RegTempMeas_U16
[
1
]
=
RegTempMeas_U16
[
0
];
// Memorise previous value
RegTempMeas_U16
[
0
]
=
RegTempMeasBuffer_U16A
[
0
];
// Convert to degrees
RegTempDeg_U16
=
(
uint16_t
)(((((
uint32_t
)
ADC_TO_TEMP_GAIN_NUM
*
(
uint32_t
)(
RegTempMeas_U16
[
0
]))
/
(
uint32_t
)
ADC_TO_TEMP_GAIN_DEN
)
+
(
uint32_t
)
ADC_TO_TEMP_OFFSET
)
&
(
uint32_t
)
0x0000FFFF
);
// PID
RegEpsilon_S32A
[
1
]
=
RegEpsilon_S32A
[
0
];
// Memorise previous value
RegEpsilon_S32A
[
0
]
=
RegTempSPT_U16
-
RegTemp
Meas
_U16
[
0
]
;
RegEpsilon_S32A
[
0
]
=
RegTempSPT_U16
-
RegTemp
Deg
_U16
;
RegPwmDyc_S32
=
(
RegEpsilon_S32A
[
0
]
*
cRegPIDProp
)
+
((
RegEpsilon_S32A
[
0
]
-
RegEpsilon_S32A
[
1
])
*
cRegPIDDeriv
)
+
((
(
RegEpsilon_S32A
[
0
]
+
RegEpsilon_S32A
[
1
])
>>
1U
)
*
cRegPIDInteg
);
+
((
RegEpsilon_S32A
[
0
]
+
RegEpsilon_S32A
[
1
])
*
cRegPIDInteg
);
//
Only keep positive values
if
(
Reg
PwmDyc_S32
>
0
)
//
Check regulation state before processing the output PWM
if
(
(
Reg
ErrorState_B
==
false
)
&&
(
RegOffState_B
==
false
)
)
{
RegPwmDyc_U32
=
RegPwmDyc_S32
;
}
else
if
(
RegPwmDyc_S32
<
(
uint32_t
)
cREGPwmMax
)
{
RegPwmDyc_U32
=
(
uint32_t
)
cREGPwmMax
;
if
(
RegPwmDyc_S32
>
0
)
{
// Only keep positive values
RegPwmDyc_U32
=
RegPwmDyc_S32
;
}
else
if
(
RegPwmDyc_S32
>
(
int32_t
)
cREGPwmMax
)
{
RegPwmDyc_U32
=
(
uint32_t
)
cREGPwmMax
;
}
else
{
RegPwmDyc_U32
=
0U
;
}
}
else
{
{
// Shut the PWM down
RegPwmDyc_U32
=
0U
;
}
...
...
@@ -143,7 +158,15 @@ void REGCyclicTask (void)
// Calculate physical temperature
// Transfer function
RegTempDeg_U16
=
(
uint16_t
)(((((
uint32_t
)
ADC_TO_TEMP_GAIN_NUM
*
(
uint32_t
)(
RegTempMeas_U16
[
0
]))
/
(
uint32_t
)
ADC_TO_TEMP_GAIN_DEN
)
+
(
uint32_t
)
ADC_TO_TEMP_OFFSET
)
&
(
uint32_t
)
0x0000FFFF
);
if
(
RegTempFiltCnt_U16
<
cREGAdcToTempFilter
)
{
RegTempFiltCnt_U16
++
;
}
else
{
// Sub-sampling for cleaner display
RegTempFiltCnt_U16
=
0U
;
RegTempDegFilt_U16
=
RegTempDeg_U16
;
}
}
bool
REGIsError
(
void
)
...
...
@@ -204,7 +227,7 @@ uint16_t REGSPTGet (void)
uint16_t
REGTempGet
(
void
)
{
return
RegTemp
Meas
_U16
[
0
]
;
return
RegTemp
DegFilt
_U16
;
}
bool
REGSPTStbySet
(
uint16_t
temp_spt_u16
)
...
...
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