mirror of
https://github.com/nqrduck/ATM.git
synced 2024-11-25 19:42:30 +00:00
Merge branch 'main' into masterproject
This commit is contained in:
commit
98561b40d5
4 changed files with 81 additions and 29 deletions
21
src/ATM.ino
21
src/ATM.ino
|
@ -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:");
|
||||
|
|
44
src/commands/MeasureReflection.cpp
Normal file
44
src/commands/MeasureReflection.cpp
Normal 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");
|
||||
}
|
21
src/commands/MeasureReflection.h
Normal file
21
src/commands/MeasureReflection.h
Normal 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
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue