dritten ADC-Kanel (Spannung) hinzugefügt und trigger.Timing überarbeitet.
This commit is contained in:
parent
37e3672072
commit
af2a74390a
@ -15,24 +15,28 @@
|
||||
typedef struct
|
||||
{
|
||||
std::uint16_t current;
|
||||
std::uint16_t voltage;
|
||||
std::uint16_t temperature;
|
||||
}ADC_Samples_t;
|
||||
|
||||
static ADC_Samples_t samples[10];
|
||||
static std::uint16_t current;
|
||||
static std::uint16_t voltage;
|
||||
static std::uint16_t temperature;
|
||||
|
||||
extern "C" void DMA1_Channel1_IRQHandler(void) /* DMA1 Channel 1 */
|
||||
{
|
||||
uint32_t tmp_current = 0U;
|
||||
uint32_t tmp_temp = 0U;
|
||||
uint32_t tmp_volt = 0U;
|
||||
if(LL_DMA_IsActiveFlag_HT1(DMA1))
|
||||
{
|
||||
LL_DMA_ClearFlag_HT1(DMA1);
|
||||
for(uint32_t i = 0U; i < (sizeof(samples)/sizeof(samples[0])) / 2U; i++)
|
||||
for(uint32_t i = 0U; i < (sizeof(samples) / sizeof(samples[0])) / 2U; i++)
|
||||
{
|
||||
tmp_current += samples[i].current;
|
||||
tmp_temp += samples[i].temperature;
|
||||
tmp_volt += samples[i].voltage;
|
||||
}
|
||||
}
|
||||
else if(LL_DMA_IsActiveFlag_TC1(DMA1))
|
||||
@ -42,6 +46,7 @@ extern "C" void DMA1_Channel1_IRQHandler(void) /* DMA1 Channel 1
|
||||
{
|
||||
tmp_current += samples[i].current;
|
||||
tmp_temp += samples[i].temperature;
|
||||
tmp_volt += samples[i].voltage;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -51,8 +56,10 @@ extern "C" void DMA1_Channel1_IRQHandler(void) /* DMA1 Channel 1
|
||||
}
|
||||
tmp_current /= ((sizeof(samples)/sizeof(samples[0])) / 2U);
|
||||
tmp_temp /= ((sizeof(samples)/sizeof(samples[0])) / 2U);
|
||||
tmp_volt /= ((sizeof(samples)/sizeof(samples[0])) / 2U);
|
||||
current = (current + tmp_current) / 2U;
|
||||
temperature = (temperature + tmp_temp) / 2U;
|
||||
voltage = (voltage + tmp_volt) / 2U;
|
||||
}
|
||||
|
||||
namespace ElektronischeLast
|
||||
@ -74,6 +81,9 @@ namespace ElektronischeLast
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_1;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
|
||||
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/* Enable ADC internal voltage regulator */
|
||||
LL_ADC_EnableInternalRegulator(ADC1);
|
||||
/* Delay for ADC internal voltage regulator stabilization. */
|
||||
@ -142,7 +152,7 @@ namespace ElektronischeLast
|
||||
LL_ADC_REG_InitTypeDef ADC_REG_InitStruct =
|
||||
{
|
||||
.TriggerSource = LL_ADC_REG_TRIG_EXT_TIM1_TRGO2,
|
||||
.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS,
|
||||
.SequencerLength = LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS,
|
||||
.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE,
|
||||
.ContinuousMode = LL_ADC_REG_CONV_SINGLE,
|
||||
.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED,
|
||||
@ -152,7 +162,7 @@ namespace ElektronischeLast
|
||||
LL_ADC_SetOverSamplingScope(ADC1, LL_ADC_OVS_DISABLE);
|
||||
LL_ADC_SetTriggerFrequencyMode(ADC1, LL_ADC_CLOCK_FREQ_MODE_HIGH);
|
||||
LL_ADC_REG_SetTriggerEdge(ADC1, LL_ADC_REG_TRIG_EXT_RISING);
|
||||
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_COMMON_1, LL_ADC_SAMPLINGTIME_12CYCLES_5);
|
||||
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_COMMON_1, LL_ADC_SAMPLINGTIME_160CYCLES_5);
|
||||
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
@ -163,6 +173,10 @@ namespace ElektronischeLast
|
||||
*/
|
||||
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_1);
|
||||
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_6);
|
||||
|
||||
/* Poll for ADC channel configuration ready */
|
||||
while (LL_ADC_IsActiveFlag_CCRDY(ADC1) == 0)
|
||||
{
|
||||
@ -173,11 +187,11 @@ namespace ElektronischeLast
|
||||
|
||||
LL_TIM_InitTypeDef TIM_InitStruct =
|
||||
{
|
||||
.Prescaler = 32,
|
||||
.Prescaler = 63U, /* =1MHz Timer-Input */
|
||||
.CounterMode = LL_TIM_COUNTERMODE_UP,
|
||||
.Autoreload = 386,
|
||||
.Autoreload = 199UL,
|
||||
.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1,
|
||||
.RepetitionCounter = 0,
|
||||
.RepetitionCounter = 0UL,
|
||||
};
|
||||
LL_TIM_Init(TIM1, &TIM_InitStruct);
|
||||
LL_TIM_DisableARRPreload(TIM1);
|
||||
@ -199,13 +213,32 @@ namespace ElektronischeLast
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @details Die Auflösung beträgt 0,8mV pro Bit.
|
||||
* Rmess = 1Ohm => 1mv pro 1mA
|
||||
* Imess = Imess1 + Imess2 + Imess3 + Imess 4
|
||||
* @return Strom in mA
|
||||
*/
|
||||
std::uint32_t iADC::get_current(void)
|
||||
{
|
||||
return current;
|
||||
const float factor = 3.3f / 4096.0f * 1000.0f * 4.0f;
|
||||
return factor * current;
|
||||
}
|
||||
|
||||
std::uint32_t iADC::get_temperature(void)
|
||||
{
|
||||
return temperature;
|
||||
}
|
||||
/**
|
||||
* @brief Gemessene Spannung der zu belastenden Quelle.
|
||||
* @details Die Auflösung beträgt 0,8mV pro Bit.
|
||||
* Uin = (R1 + R2)/ R2 * Uout => (100k + 4,7k) / 4,7k * Uout
|
||||
* Uout = ADC * 0,8mV
|
||||
* @return Spannung in mV
|
||||
*/
|
||||
std::uint32_t iADC::get_voltage(void)
|
||||
{
|
||||
const float factor = (100000.0f + 4700.0f) / 4700.0f * 3.3f / 4096.0f * 1000.0f;
|
||||
return factor * voltage;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace ElektronischeLast
|
||||
~iADC(void);
|
||||
std::uint32_t get_current(void);
|
||||
std::uint32_t get_temperature(void);
|
||||
std::uint32_t get_voltage(void);
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user