Merge branch 'main' into masterproject

This commit is contained in:
Julia Pfitzer 2023-08-16 14:42:46 +02:00 committed by GitHub
commit 98561b40d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 29 deletions

View file

@ -5,6 +5,8 @@
#include "commands/TuneMatch.h"
#include "commands/Homing.h"
#include "commands/SetVoltages.h"
#include "commands/MeasureReflection.h"
#define DEBUG
@ -17,6 +19,7 @@ FrequencySweep frequencySweep;
TuneMatch tuneMatch;
Homing homing;
SetVoltages setVoltages;
MeasureReflection measureReflection;
// Frequency Settings
#define FREQUENCY_STEP 100000U // 100kHz frequency steps for initial frequency sweep
@ -53,10 +56,10 @@ void setup()
commandManager.registerCommand('d', &tuneMatch);
commandManager.registerCommand('h', &homing);
commandManager.registerCommand('v', &setVoltages);
commandManager.registerCommand('m', &measureReflection);
pinMode(MISO_PIN, INPUT_PULLUP); // Seems to be necessary for SPI to work
// Setup fo the tuning stepper
tuner.DRIVER.begin(); // Initiate pins
tuner.DRIVER.rms_current(400); // Set stepper current to 400mA.
@ -149,22 +152,6 @@ void loop()
// approximate call
// CAREFULL -> if the coil has no proper matching in the frequency range this will not work! Only use this for testing -> otherwise use the automated 'decide' call.
/*if (command == 'a')
else if (command == 'r')
{
float frequency_MHz = input_line.substring(1).toFloat();
uint32_t frequency = validateInput(frequency_MHz);
if (frequency == 0)
return;
float reflection_loss = calculateRL(frequency);
printInfo("For frequency:");
printInfo(frequency);
printInfo("RL is:");
printInfo(reflection_loss);
// optimize Matching
}
else if (command == 'm')
{
printInfo("Optimize Matching around frequency:");

View file

@ -0,0 +1,44 @@
#include "Utilities.h"
#include "MeasureReflection.h"
void MeasureReflection::execute(String input_line)
{
int AVERAGES = 16;
return_loss = 0;
phase = 0;
printInfo("Measure Reflection");
// Get the float after the r character which is the frequency value where the reflection measurment should be performed
float frequency_MHz = input_line.substring(1).toFloat();
uint32_t frequency = validateInput(frequency_MHz);
if (frequency == 0)
{
printInfo("Invalid frequency input.");
return;
}
// First set the frequency
setFrequency(frequency);
// Measure the reflection at the given frequency
return_loss = readReflection(AVERAGES);
phase = readPhase(AVERAGES);
}
void MeasureReflection::printResult()
{
// Print the results which are then read by the autotm module
char identifier = 'r';
char delimiter = 'p';
String text = String(identifier) + String(return_loss) + String(delimiter) + String(phase);
Serial.println(text);
}
void MeasureReflection::printHelp()
{
Serial.println("Measure reflection command");
Serial.println("Syntax: r<frequency in MHz>");
Serial.println("Example: r100");
Serial.println("This will measure the reflection at 100 MHz");
}

View file

@ -0,0 +1,21 @@
#ifndef MEASUREREFLECTION_H
#define MEASUREREFLECTION_H
#include "Command.h"
/**
* @brief This class is used to perform a frequency sweep
*/
class MeasureReflection : public Command
{
public:
void execute(String input_line) override;
void printResult() override;
void printHelp() override;
private:
int return_loss;
int phase;
};
#endif

View file

@ -1,22 +1,22 @@
#include "Utilities.h"
#include "TuneMatch.h"
void TuneMatch::execute(String input_line){
float target_frequency_MHz = input_line.substring(1).toFloat();
uint32_t target_frequency = validateInput(target_frequency_MHz);
if (target_frequency == 0)
return;
void TuneMatch::execute(String input_line)
{
float target_frequency_MHz = input_line.substring(1).toFloat();
uint32_t target_frequency = validateInput(target_frequency_MHz);
if (target_frequency == 0)
return;
uint32_t startf = 35000000U;
uint32_t stopf = 110000000U;
uint32_t stepf = 100000U;
printInfo("Tuning and Matching to target frequency in MHz (automatic mode):");
printInfo(target_frequency_MHz);
uint32_t startf = 35000000U;
uint32_t stopf = 110000000U;
uint32_t stepf = 100000U;
printInfo("Tuning and Matching to target frequency in MHz (automatic mode):");
printInfo(target_frequency_MHz);
uint32_t resonance_frequency = automaticTM(target_frequency, startf, stopf, stepf);
uint32_t resonance_frequency = automaticTM(target_frequency, startf, stopf, stepf);
}
uint32_t TuneMatch::automaticTM(uint32_t target_frequency, uint32_t start_frequency, uint32_t stop_frequency, uint32_t frequency_step)
{
uint32_t resonance_frequency = findCurrentResonanceFrequency(start_frequency, stop_frequency, frequency_step);