Verstärkungsfaktor kann kalibriert werden (aktuell nur per Konsole und vordefinierten Eingangspannungen/-strömen)

This commit is contained in:
Carsten Keller 2024-06-09 17:58:14 +02:00
parent ca97def69c
commit b939c2fd71
Signed by: carsten
GPG Key ID: DF06343A3A9B8868
3 changed files with 99 additions and 15 deletions

View File

@ -64,8 +64,11 @@ extern "C" void DMA1_Channel1_IRQHandler(void) /* DMA1 Channel 1
namespace ElektronischeLast namespace ElektronischeLast
{ {
iADC::iADC(void) iADC::iADC(float voltage_gain, float current_gain)
{ {
this->voltage_gain = voltage_gain;
this->current_gain = current_gain;
/**ADC1 GPIO Configuration /**ADC1 GPIO Configuration
PA0 ------> ADC1_IN0 PA0 ------> ADC1_IN0
PA1 ------> ADC1_IN1 PA1 ------> ADC1_IN1
@ -222,7 +225,7 @@ namespace ElektronischeLast
*/ */
std::uint32_t iADC::get_current(void) std::uint32_t iADC::get_current(void)
{ {
const float factor = 3.3f / 4096.0f * 1000.0f * 4.0f / 1.08f; const float factor = 3.3f / 4096.0f * 1000.0f * this->current_gain;
return factor * current; return factor * current;
} }
/** /**
@ -242,8 +245,21 @@ namespace ElektronischeLast
* @return Spannung in mV * @return Spannung in mV
*/ */
std::uint32_t iADC::get_voltage(void) std::uint32_t iADC::get_voltage(void)
{ //22,48484848484 {
const float factor = /*(100000.0f + 4700.0f) / 4700.0f*/22.484848484848f * 3.3f / 4096.0f * 1000.0f; const float factor = this->voltage_gain * 3.3f / 4096.0f * 1000.0f;
return factor * voltage; return factor * voltage;
} }
std::uint32_t iADC::get_current_raw(void)
{
return current;
}
std::uint32_t iADC::get_temperature_raw(void)
{
return temperature;
}
std::uint32_t iADC::get_voltage_raw(void)
{
return voltage;
}
} }

View File

@ -15,12 +15,17 @@ namespace ElektronischeLast
class iADC class iADC
{ {
public: public:
iADC(void); iADC(float voltage_gain, float current_gain);
~iADC(void); ~iADC(void);
std::uint32_t get_current(void); std::uint32_t get_current(void);
std::uint32_t get_temperature(void); std::uint32_t get_temperature(void);
std::uint32_t get_voltage(void); std::uint32_t get_voltage(void);
std::uint32_t get_current_raw(void);
std::uint32_t get_temperature_raw(void);
std::uint32_t get_voltage_raw(void);
private: private:
float voltage_gain;
float current_gain;
}; };
} }

View File

@ -21,15 +21,22 @@
using namespace ElektronischeLast; using namespace ElektronischeLast;
static void do_icall(iADC& adc);
static void do_ucall(iADC& dac);
uint16_t set_solltrom (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount); uint16_t set_solltrom (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount);
uint16_t set_dutyCyle (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount); uint16_t set_dutyCyle (CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount);
uint16_t ist_werte(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount); uint16_t ist_werte(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount);
uint16_t set_ucall(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount);
uint16_t set_icall(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount);
static CLI_Command_t commands[] = static CLI_Command_t commands[] =
{ {
{ "isoll", "Zielstrom für Last", set_solltrom }, { "isoll", "Zielstrom für Last", set_solltrom },
{ "ist", "Zeige Istwerte an [-r für wiederholende Anzeige]", ist_werte }, { "ist", "Zeige Istwerte an [-r für wiederholende Anzeige]", ist_werte },
{ "fan", "Setze Tastverhältnis für Lüfter", set_dutyCyle }, { "fan", "Setze Tastverhältnis für Lüfter", set_dutyCyle },
{ "icall", "Starte Strom Kalibrierung", set_icall },
{ "ucall", "Starte Spannungs Kalibrierung", set_ucall }
}; };
static std::uint32_t i_soll = 0U; static std::uint32_t i_soll = 0U;
@ -49,6 +56,7 @@ static uint32_t strom;
static uint32_t spannung; static uint32_t spannung;
static uint32_t temperatur; static uint32_t temperatur;
static uint32_t geschwindigkeit; static uint32_t geschwindigkeit;
static enum { normal, icall, ucall } modus;
int main (void) int main (void)
{ {
@ -57,7 +65,7 @@ int main (void)
CLI_Init(commands, sizeof(commands)/sizeof(commands[0])); CLI_Init(commands, sizeof(commands)/sizeof(commands[0]));
LED led = LED(500U); LED led = LED(500U);
iDAC dac = iDAC(); iDAC dac = iDAC();
iADC adc = iADC(); iADC adc = iADC(22.272125f, 3.685331f);
FanControl fan = FanControl(); FanControl fan = FanControl();
std::uint32_t last_tick = systick; std::uint32_t last_tick = systick;
@ -73,16 +81,27 @@ int main (void)
if(last_tick != systick) if(last_tick != systick)
{ {
last_tick = systick; last_tick = systick;
dac_value = (uint32_t)PIDController_Update(&pid, i_soll, adc.get_current()); switch(modus)
dac.write(iDAC::CHANNEL_1, dac_value); {
case icall:
do_icall(adc);
break;
case ucall:
do_ucall(adc);
break;
case normal:
default:
dac_value = (uint32_t)PIDController_Update(&pid, i_soll, adc.get_current());
dac.write(iDAC::CHANNEL_1, dac_value);
fan.run(adc.get_temperature()); fan.run(adc.get_temperature());
strom = adc.get_current();
spannung = adc.get_voltage();
temperatur = adc.get_temperature();
geschwindigkeit = fan.get_speed();
strom = adc.get_current();
spannung = adc.get_voltage();
temperatur = adc.get_temperature();
geschwindigkeit = fan.get_speed();
break;
}
serial_cyclic(); serial_cyclic();
} }
} }
@ -131,7 +150,9 @@ uint16_t ist_werte(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t
char buffer[64]; char buffer[64];
if(newline) if(newline)
{ {
pfvOutFunction("\n"); buffer[0] = '\n';
buffer[1] = '\0';
pfvOutFunction(buffer);
} }
snprintf(buffer, sizeof(buffer), "\rI: %5" PRIu32 "mA U: %5" PRIu32 "mV T: %3" PRIu32 "°C V: %4" PRIu32 "RPM", snprintf(buffer, sizeof(buffer), "\rI: %5" PRIu32 "mA U: %5" PRIu32 "mV T: %3" PRIu32 "°C V: %4" PRIu32 "RPM",
strom, spannung, temperatur, geschwindigkeit); strom, spannung, temperatur, geschwindigkeit);
@ -158,3 +179,45 @@ uint16_t set_dutyCyle (CLI_OutFunction pfvOutFunction, char *acCommands[], uint1
pfvOutFunction(buf); pfvOutFunction(buf);
return 0; return 0;
} }
uint16_t set_ucall(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount)
{
spannung = 0UL;
strom = 0UL;
modus = ucall;
return 0U;
}
uint16_t set_icall(CLI_OutFunction pfvOutFunction, char *acCommands[], uint16_t u16ArgCount)
{
spannung = 0UL;
strom = 0UL;
modus = icall;
return 0U;
}
static void do_icall(iADC& adc)
{
strom += adc.get_current_raw();
spannung++;
if(spannung == 1000UL)
{
float current_gain = 1.0f / ((float)strom / 1000.0f * 3.3f / 4096.0f);
printf("\r\nStromverstärkung: %f", current_gain);
modus = normal;
spannung = 0UL;
strom = 0UL;
}
}
static void do_ucall(iADC& adc)
{
spannung += adc.get_voltage_raw();
strom++;
if(strom == 1000UL)
{
float voltage_gain = 15.0f / ((float)spannung / 1000.0f * 3.3f / 4096.0f);
printf("\r\nSpannungsverstärkung: %f", voltage_gain);
modus = normal;
spannung = 0UL;
strom = 0UL;
}
}