Skip to content
Snippets Groups Projects
Commit 7c27009c authored by Flax's avatar Flax
Browse files

STM32L011K4 : configured ADC as software trigger, updated ADC init, added...

STM32L011K4 : configured ADC as software trigger, updated ADC init, added temporary transfer function for temperature measure, updated HMI menu.
parent c58c240b
No related branches found
No related tags found
No related merge requests found
......@@ -108,9 +108,12 @@
/* ADC --------------------------------------------------------*/
#define mREGAdcHandle ADC1
#define mREDAdcEnable() (LL_ADC_Enable(mREGAdcHandle))
#define mREGAdcIsReady() (bool)(LL_ADC_IsActiveFlag_ADRDY(mREGAdcHandle) == 1U)
#define mREGAdcStartConversion() (LL_ADC_REG_StartConversion(mREGAdcHandle))
#define mREGAdcStopConversion() (LL_ADC_REG_StopConversion(mREGAdcHandle))
#define mREGAdcReadValue() (LL_ADC_REG_ReadConversionData12(mREGAdcHandle))
#define mREGAdc
/* PWM --------------------------------------------------------*/
#define mREGPwmSetCompareValue(val) (LL_TIM_OC_SetCompareCH1(TIM2, (uint32_t)val))
......
......@@ -44,5 +44,6 @@ extern bool REGSPTStbySet (uint16_t temp_spt_u16);
extern uint16_t REGSPTStbyGet (void);
extern uint16_t REGTempGet (void);
extern uint16_t REGTempPhysDeg (void);
#endif /* INC_TEMPERATUREREGULATION_H_ */
......@@ -203,6 +203,7 @@ static void HmiUpdateDisplay (void)
break;
case HMI_EVENT_INPUT_CLIC_LONG:
// Go to normal mode
REGOffReset();
display_mode_current_E = HMI_DISPLAY_MODE_TEMP;
break;
default:
......@@ -425,10 +426,14 @@ static void HmiUpdateDisplay (void)
/**************************************/
case HMI_DISPLAY_MODE_TEMP:
// Display actual tip temperature
DISPUpdateValueNumber(REGTempGet());
DISPUpdateValueNumber(REGTempPhysDeg());
display_param_cnt_u16 = cHMIDisplayTitleTime;
if (REGIsStandby())
if (REGIsOff())
{
display_mode_current_E = HMI_DISPLAY_MODE_OFF;
}
else if (REGIsStandby())
{
display_mode_current_E = HMI_DISPLAY_MODE_STANDBY;
}
......@@ -447,7 +452,7 @@ static void HmiUpdateDisplay (void)
break;
case HMI_EVENT_INPUT_CLIC_LONG:
// Switch OFF
display_mode_current_E = HMI_DISPLAY_MODE_OFF;
REGOffSet();
break;
default:
break;
......
......@@ -218,7 +218,7 @@ static void MX_ADC_Init(void)
/** Common config
*/
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_EXT_TIM21_CH2;
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_SINGLE;
ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
......@@ -235,7 +235,6 @@ static void MX_ADC_Init(void)
ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE;
LL_ADC_Init(ADC1, &ADC_InitStruct);
LL_ADC_REG_SetTriggerEdge(ADC1, LL_ADC_REG_TRIG_EXT_FALLING);
/* Enable ADC internal voltage regulator */
LL_ADC_EnableInternalRegulator(ADC1);
......
......@@ -60,7 +60,7 @@ void MAINStop (void)
void MAINCyclicTask (void)
{
HMICyclicTask();
//REGCyclicTask();
REGCyclicTask();
SAVCyclicTask();
if (cnt_u32 < 1000)
......
......@@ -27,6 +27,17 @@
#define cRegPIDInteg (10)
#define cRegPIDDeriv (10)
// Temperature measure transfer function parameters
// OPA gain : 681
// Input divider bridge gain : 100k / (100k + 5k6) = 0.946969
// On legacy Arduino code : gain = 0.39, offset = 23.9, resolution 10 bits
// Translated to 12 bits : 0.0975 ~= 100 / 1024
#define ADC_TO_TEMP_GAIN_NUM (100U)
#define ADC_TO_TEMP_GAIN_DEN (1024U)
#define ADC_TO_TEMP_OFFSET (24U)
#define cREGAdcErrorThres (4090U)
// ===============
// Local variables
// ===============
......@@ -40,6 +51,7 @@ static uint16_t RegTempMeas_U16[2U];
static uint16_t RegTempMeasBuffer_U16A[2U];
static int32_t RegPwmDyc_S32;
static uint32_t RegPwmDyc_U32;
static uint16_t RegTempDeg_U16;
// PID
static int32_t RegEpsilon_S32A[2U];
......@@ -68,7 +80,8 @@ void REGInit (void)
void REGStart (void)
{
mREGAdcStartConversion();
mREDAdcEnable();
// mREGAdcStartConversion();
}
void REGStop (void)
......@@ -78,12 +91,28 @@ void REGStop (void)
void REGCyclicTask (void)
{
// Read ADC input
RegTempMeasBuffer_U16A[1] = mREGAdcReadValue();
if (mREGAdcIsReady())
{
// Trigger conversion
mREGAdcStartConversion();
// Read ADC input
RegTempMeasBuffer_U16A[1] = mREGAdcReadValue();
if (RegTempMeasBuffer_U16A[1] >= cREGAdcErrorThres)
{
// Error
}
}
else
{
// ADC not ready
RegTempMeasBuffer_U16A[1] = 0xFFFF;
}
// Calculate average
RegTempMeasBuffer_U16A[0] += RegTempMeasBuffer_U16A[1];
RegTempMeasBuffer_U16A[0] >> 1U;
RegTempMeasBuffer_U16A[0] = RegTempMeasBuffer_U16A[0] >> 1U;
RegTempMeas_U16[1] = RegTempMeas_U16[0]; // Memorise previous value
RegTempMeas_U16[0] = RegTempMeasBuffer_U16A[0];
......@@ -111,6 +140,10 @@ void REGCyclicTask (void)
// Set PWM output duty cycle
mREGPwmSetCompareValue(RegPwmDyc_U32);
// 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);
}
bool REGIsError (void)
......@@ -189,3 +222,8 @@ uint16_t REGSPTStbyGet (void)
{
return RegTempSPTStby_U16;
}
uint16_t REGTempPhysDeg (void)
{
return (RegTempDeg_U16);
}
#MicroXplorer Configuration settings - do not modify
ADC.ExternalTrigConv=ADC_EXTERNALTRIGCONV_T21_CC2
ADC.ExternalTrigConvEdge=ADC_EXTERNALTRIGCONVEDGE_FALLING
ADC.ExternalTrigConv=ADC_SOFTWARE_START
ADC.ExternalTrigConvEdge=ADC_EXTERNALTRIGCONVEDGE_NONE
ADC.IPParameters=SamplingTime,ExternalTrigConv,ExternalTrigConvEdge
ADC.SamplingTime=ADC_SAMPLETIME_19CYCLES_5
CAD.formats=
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment