mirror of
https://github.com/nqrduck/ATM.git
synced 2024-11-25 11:32:28 +00:00
Improved speed of frequency sweep.
This commit is contained in:
parent
bd46b8ae9f
commit
359152620a
3 changed files with 58 additions and 60 deletions
|
@ -362,7 +362,7 @@ void AD5593R::configure_ADCs(bool *channels)
|
|||
}
|
||||
}
|
||||
|
||||
float AD5593R::read_ADC(byte channel)
|
||||
float AD5593R::read_ADC(byte channel, int averages)
|
||||
{
|
||||
if (config.ADCs[channel] == 0)
|
||||
{
|
||||
|
@ -376,8 +376,6 @@ float AD5593R::read_ADC(byte channel)
|
|||
AD5593R_PRINTLN("Vref, or ADC_max is not defined");
|
||||
return -2;
|
||||
}
|
||||
if (_a0 > -1)
|
||||
digitalWrite(_a0, LOW);
|
||||
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(_ADAC_ADC_SEQUENCE);
|
||||
|
@ -385,20 +383,31 @@ float AD5593R::read_ADC(byte channel)
|
|||
Wire.write(byte(1 << channel));
|
||||
Wire.endTransmission();
|
||||
|
||||
int sum = 0;
|
||||
for (int i = 0; i < averages; i++)
|
||||
{
|
||||
if (_a0 > -1)
|
||||
gpio_set_level((gpio_num_t)_a0, LOW);
|
||||
|
||||
Wire.beginTransmission(_i2c_address);
|
||||
Wire.write(_ADAC_ADC_READ);
|
||||
Wire.endTransmission();
|
||||
|
||||
unsigned int data_bits = 0;
|
||||
delayMicroseconds(10);
|
||||
|
||||
Wire.requestFrom(int(_i2c_address), int(2), int(1));
|
||||
unsigned int data_bits = 0;
|
||||
if (Wire.available())
|
||||
data_bits = (Wire.read() & 0x0f) << 8;
|
||||
if (Wire.available())
|
||||
data_bits = data_bits | Wire.read();
|
||||
|
||||
sum += (data_bits);
|
||||
|
||||
if (_a0 > -1)
|
||||
digitalWrite(_a0, HIGH);
|
||||
float data = _ADC_max * (data_bits) / 4095;
|
||||
gpio_set_level((gpio_num_t)_a0, HIGH);
|
||||
}
|
||||
float data = _ADC_max * sum / 4095 / averages;
|
||||
|
||||
AD5593R_PRINT("Channel ");
|
||||
AD5593R_PRINT(channel);
|
||||
|
|
|
@ -43,18 +43,18 @@ https://github.com/LukasJanavicius
|
|||
#endif
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
//////Classes//////
|
||||
class AD5593R {
|
||||
class AD5593R
|
||||
{
|
||||
public:
|
||||
|
||||
// This configuration structure contains arrays of booleans,
|
||||
// each array follows the form [channel0,...,channel7]
|
||||
// where a 1 indicates the channel should be configured as the name implies
|
||||
// for example an array ADCs[8] = {1,1,0,0,0,0,0,0} will configure channels 0 and 1 as ADCs.
|
||||
// a declaration of this structure should be defined in your code, and passed into configure().
|
||||
// You should not double assign pins, as only the first declaration will be assigned.
|
||||
struct configuration {
|
||||
struct configuration
|
||||
{
|
||||
bool ADCs[8]; // ADC pins
|
||||
bool DACs[8]; // DAC pins
|
||||
bool GPIs[8]; // input pins
|
||||
|
@ -63,7 +63,8 @@ public:
|
|||
configuration config;
|
||||
|
||||
// This structure contains arrays of
|
||||
struct Read_write_values {
|
||||
struct Read_write_values
|
||||
{
|
||||
float ADCs[8];
|
||||
float DACs[8];
|
||||
bool GPI_reads[8];
|
||||
|
@ -111,17 +112,15 @@ public:
|
|||
// configures the selected channel as a ADC
|
||||
void configure_ADC(byte channel);
|
||||
|
||||
|
||||
void configure_ADCs(bool *channels);
|
||||
|
||||
// Reads the voltage value of a given ADC channel, returns the Voltage if the write is completed
|
||||
// if the function returns -1 if the specified channel is not an ADC,
|
||||
// and if no reference voltage is specified a -2 will be returned.
|
||||
float read_ADC(byte channel);
|
||||
float read_ADC(byte channel, int averages = 1);
|
||||
|
||||
float *read_ADCs();
|
||||
|
||||
|
||||
void configure_GPI(byte channel);
|
||||
void configure_GPIs(bool *channels);
|
||||
|
||||
|
@ -131,8 +130,6 @@ public:
|
|||
bool *read_GPIs();
|
||||
void write_GPOs(bool *pin_states);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
// By passing in the configuration structure this function assigns the functionality
|
||||
|
@ -172,7 +169,6 @@ private:
|
|||
// These structures are adapted from
|
||||
// https://github.com/MikroElektronika/HEXIWEAR/blob/master/SW/Click%20Examples%20mikroC/examples/ADAC/library/__ADAC_Driver.h
|
||||
|
||||
|
||||
int _num_of_channels = 8;
|
||||
|
||||
int _a0;
|
||||
|
|
|
@ -121,19 +121,12 @@ void setFrequency(uint32_t frequency)
|
|||
|
||||
int readReflection(int averages)
|
||||
{
|
||||
int reflection = 0;
|
||||
for (int i = 0; i < averages; i++)
|
||||
// We multiply by 1000 to get the result in millivolts
|
||||
reflection += (adac.read_ADC(0) * 1000);
|
||||
return reflection / averages;
|
||||
return (adac.read_ADC(MAGNITUDE, averages) * 1000);
|
||||
}
|
||||
|
||||
int readPhase(int averages)
|
||||
{
|
||||
int phase = 0;
|
||||
for (int i = 0; i < averages; i++)
|
||||
phase += (adac.read_ADC(1) * 1000);
|
||||
return phase / averages;
|
||||
return (adac.read_ADC(PHASE, averages) * 1000);
|
||||
}
|
||||
|
||||
int sumReflectionAroundFrequency(uint32_t center_frequency)
|
||||
|
|
Loading…
Reference in a new issue