Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Added setPowerLevel function which can be used for frequency bursts
  • Loading branch information
brycecherry75 authored Sep 16, 2022
1 parent da78a8d commit 2085bd8
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# MAX2870
Arduino Library for the MAX2870 Wideband Frequency Synthesizer chip

v1.0.0 First release

v1.0.1 Double buffering of RF frequency divider implemented by default

v1.1.0 Added current frequency read function

v1.1.1 Corrected issue with conversion in ReadCurrentFreq

v1.1.2 Add setPowerLevel function which can be used for frequency bursts

## Introduction

This library supports the MAX2870 from Maxim on Arduinos. The chip is a wideband (23.475 MHz to 6 GHz) Phase-Locked Loop (PLL) and Voltage Controlled Oscillator (VCO), covering a very wide range frequency range
Expand Down Expand Up @@ -52,6 +62,8 @@ setf(*frequency, PowerLevel, AuxPowerLevel, AuxFrequencyDivider, PrecisionFreque

setrf(frequency, R_divider, ReferenceDivisionType): set the reference frequency and reference divider R and reference frequency division type (MAX2870_REF_(UNDIVIDED/HALF/DOUBLE)) - default is 10 MHz/1/undivided - returns an error code

setPowerLevel/setAuxPowerLevel(PowerLevel): set the power level (0 to disable or 1-4) and write to the MAX2870 in one operation - returns an error code

WriteSweepRegs(*regs): high speed write for registers when used for frequency sweep (*regs is uint32_t and size is as per MAX2870_RegsToWrite

ReadSweepRegs(*regs): high speed read for registers when used for frequency sweep (*regs is uint32_t and size is as per MAX2870_RegsToWrite
Expand Down
93 changes: 93 additions & 0 deletions examples/example2870/example2870.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Commands:
REF reference_frequency_in_Hz reference_divider reference_multiplier(UNDIVIDED/DOUBLE/HALF) - Set reference frequency, reference divider and reference doubler/divide by 2
(FREQ/FREQ_P) frequency_in_Hz power_level(0-4) aux_power_level(0-4) aux_frequency_output(DIVIDED/FUNDAMENTAL) frequency_tolerance_in_Hz calculation_timeout_in_mS - set RF frequency (FREQ_P sets precision mode), power level, auxiliary output frequency mode, frequency tolerance (precision mode only), calculation timeout (precision mode only - 0 to disable)
(BURST/BURST_CONT/BURST_SINGLE) on_time_in_uS off time_in_uS count (AUX) - perform a on/off burst on frequency and power level set with FREQ/FREQ_P - count is only used with BURST_CONT - if AUX is used, will burst on the auxiliary output; otherwise, it will burst on the primary output
SWEEP start_frequency stop_frequency step_in_mS(1-32767) power_level(1-4) aux_power_level(0-4) aux_frequency_output(DIVIDED/FUNDAMENTAL) - sweep RF frequency
STEP frequency_in_Hz - set channel step
STATUS - view status of VFO
Expand Down Expand Up @@ -278,6 +279,96 @@ void loop() {
}
}
}
else if (strcmp(field, "BURST") == 0 || strcmp(field, "BURST_CONT") == 0 || strcmp(field, "BURST_SINGLE") == 0) {
bool ContinuousBurst = false;
bool SingleBurst = false;
unsigned long BurstCount;
if (strcmp(field, "BURST_CONT") == 0) {
ContinuousBurst = true;
}
else if (strcmp(field, "BURST_SINGLE") == 0) {
SingleBurst = true;
}
bool AuxOutput = false;
getField(field, 1);
unsigned long BurstOnTime = atol(field);
getField(field, 2);
unsigned long BurstOffTime = atol(field);
getField(field, 3);
if (strcmp(field, "AUX") == 0) {
AuxOutput = true;
}
else if (ContinuousBurst == false && SingleBurst == false) {
BurstCount = atol(field);
getField(field, 4);
if (strcmp(field, "AUX") == 0) {
AuxOutput = true;
}
}
unsigned long OnBurstData[MAX2870_RegsToWrite];
vfo.ReadSweepValues(OnBurstData);
if (AuxOutput == false) {
vfo.setPowerLevel(0);
}
else {
vfo.setAuxPowerLevel(0);
}
unsigned long OffBurstData[MAX2870_RegsToWrite];
vfo.ReadSweepValues(OffBurstData);
Serial.print(F("Burst "));
Serial.print((BurstOnTime / 1000));
Serial.print(F("."));
Serial.print((BurstOnTime % 1000));
Serial.print(F(" mS on, "));
Serial.print((BurstOffTime / 1000));
Serial.print(F("."));
Serial.print((BurstOffTime % 1000));
Serial.println(F(" mS off"));
if (SingleBurst == true) {
vfo.WriteSweepValues(OffBurstData);
if (BurstOffTime <= 16383) {
delayMicroseconds(BurstOffTime);
}
else {
delay((BurstOffTime / 1000));
delayMicroseconds((BurstOffTime % 1000));
}
}
if (ContinuousBurst == false && SingleBurst == false && BurstCount == 0) {
ValidField = false;
}
if (ValidField == true) {
FlushSerialBuffer();
while (true) {
vfo.WriteSweepValues(OnBurstData);
if (BurstOnTime <= 16383) {
delayMicroseconds(BurstOnTime);
}
else {
delay((BurstOnTime / 1000));
delayMicroseconds((BurstOnTime % 1000));
}
vfo.WriteSweepValues(OffBurstData);
if (ContinuousBurst == false && SingleBurst == false) {
BurstCount--;
}
if ((ContinuousBurst == false && BurstCount == 0) || SingleBurst == true || Serial.available() > 0) {
for (int i = 0; i < MAX2870_RegsToWrite; i++) {
vfo.MAX2870_R[i] = OnBurstData[i];
}
Serial.println(F("End of burst"));
break;
}
if (BurstOffTime <= 16383) {
delayMicroseconds(BurstOffTime);
}
else {
delay((BurstOffTime / 1000));
delayMicroseconds((BurstOffTime % 1000));
}
}
}
}
else if (strcmp(field, "SWEEP") == 0) {
BigNumber::begin(12); // will finish on setf()
getField(field, 1);
Expand Down Expand Up @@ -420,12 +511,14 @@ void loop() {
}
else if (strcmp(field, "STATUS") == 0) {
PrintVFOstatus();
SPI.end();
if (digitalRead(LockPin) == LOW) {
Serial.println(F("Lock pin LOW"));
}
else {
Serial.println(F("Lock pin HIGH"));
}
SPI.begin();
}
else if (strcmp(field, "CE") == 0) {
getField(field, 1);
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ReadRDIV2 KEYWORD2
ReadRefDoubler KEYWORD2
ReadPFDfreq KEYWORD2
ReadFrequencyError KEYWORD2
setPowerLevel KEYWORD2
setAuxPowerLevel KEYWORD2
ReadSweepValues KEYWORD2
WriteSweepValues KEYWORD2
MAX2870_AUX_DIVIDED LITERAL1
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MAX2870
version=1.1.1
version=1.1.2
author=Bryce Cherry
maintainer=Bryce Cherry
sentence=Supports the MAX2870 Wideband Frequency Synthesizer chip from Maxim.
Expand Down
28 changes: 28 additions & 0 deletions src/MAX2870.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,32 @@ int MAX2870::setrf(uint32_t f, uint16_t r, uint8_t ReferenceDivisionType)
MAX2870_R[0x02] = BitFieldManipulation.WriteBF_dword(24, 2, MAX2870_R[0x02], 0b00000000);
}
return MAX2870_ERROR_NONE;
}

int MAX2870::setPowerLevel(uint8_t PowerLevel) {
if (PowerLevel < 0 && PowerLevel > 4) return MAX2870_ERROR_POWER_LEVEL;
if (PowerLevel == 0) {
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(5, 1, MAX2870_R[0x04], 0);
}
else {
PowerLevel--;
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(5, 1, MAX2870_R[0x04], 1);
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(3, 2, MAX2870_R[0x04], PowerLevel);
}
WriteRegs();
return MAX2870_ERROR_NONE;
}

int MAX2870::setAuxPowerLevel(uint8_t PowerLevel) {
if (PowerLevel < 0 && PowerLevel > 4) return MAX2870_ERROR_POWER_LEVEL;
if (PowerLevel == 0) {
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(8, 1, MAX2870_R[0x04], 0);
}
else {
PowerLevel--;
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(6, 2, MAX2870_R[0x04], PowerLevel);
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(8, 1, MAX2870_R[0x04], 1);
}
WriteRegs();
return MAX2870_ERROR_NONE;
}
2 changes: 2 additions & 0 deletions src/MAX2870.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class MAX2870
int SetStepFreq(uint32_t value);
int setf(char *freq, uint8_t PowerLevel, uint8_t AuxPowerLevel, uint8_t AuxFrequencyDivider, bool PrecisionFrequency, uint32_t FrequencyTolerance, uint32_t CalculationTimeout) ; // set freq and power levels and output mode with option for precision frequency setting with tolerance in Hz
int setrf(uint32_t f, uint16_t r, uint8_t ReferenceDivisionType) ; // set reference freq and reference divider (default is 10 MHz with divide by 1)
int setPowerLevel(uint8_t PowerLevel);
int setAuxPowerLevel(uint8_t PowerLevel);

void WriteSweepValues(const uint32_t *regs);
void ReadSweepValues(uint32_t *regs);
Expand Down

0 comments on commit 2085bd8

Please sign in to comment.