Skip to content

Commit 2085bd8

Browse files
Add files via upload
Added setPowerLevel function which can be used for frequency bursts
1 parent da78a8d commit 2085bd8

File tree

6 files changed

+138
-1
lines changed

6 files changed

+138
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# MAX2870
22
Arduino Library for the MAX2870 Wideband Frequency Synthesizer chip
33

4+
v1.0.0 First release
5+
6+
v1.0.1 Double buffering of RF frequency divider implemented by default
7+
8+
v1.1.0 Added current frequency read function
9+
10+
v1.1.1 Corrected issue with conversion in ReadCurrentFreq
11+
12+
v1.1.2 Add setPowerLevel function which can be used for frequency bursts
13+
414
## Introduction
515

616
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
@@ -52,6 +62,8 @@ setf(*frequency, PowerLevel, AuxPowerLevel, AuxFrequencyDivider, PrecisionFreque
5262

5363
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
5464

65+
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
66+
5567
WriteSweepRegs(*regs): high speed write for registers when used for frequency sweep (*regs is uint32_t and size is as per MAX2870_RegsToWrite
5668

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

examples/example2870/example2870.ino

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Commands:
66
REF reference_frequency_in_Hz reference_divider reference_multiplier(UNDIVIDED/DOUBLE/HALF) - Set reference frequency, reference divider and reference doubler/divide by 2
77
(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)
8+
(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
89
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
910
STEP frequency_in_Hz - set channel step
1011
STATUS - view status of VFO
@@ -278,6 +279,96 @@ void loop() {
278279
}
279280
}
280281
}
282+
else if (strcmp(field, "BURST") == 0 || strcmp(field, "BURST_CONT") == 0 || strcmp(field, "BURST_SINGLE") == 0) {
283+
bool ContinuousBurst = false;
284+
bool SingleBurst = false;
285+
unsigned long BurstCount;
286+
if (strcmp(field, "BURST_CONT") == 0) {
287+
ContinuousBurst = true;
288+
}
289+
else if (strcmp(field, "BURST_SINGLE") == 0) {
290+
SingleBurst = true;
291+
}
292+
bool AuxOutput = false;
293+
getField(field, 1);
294+
unsigned long BurstOnTime = atol(field);
295+
getField(field, 2);
296+
unsigned long BurstOffTime = atol(field);
297+
getField(field, 3);
298+
if (strcmp(field, "AUX") == 0) {
299+
AuxOutput = true;
300+
}
301+
else if (ContinuousBurst == false && SingleBurst == false) {
302+
BurstCount = atol(field);
303+
getField(field, 4);
304+
if (strcmp(field, "AUX") == 0) {
305+
AuxOutput = true;
306+
}
307+
}
308+
unsigned long OnBurstData[MAX2870_RegsToWrite];
309+
vfo.ReadSweepValues(OnBurstData);
310+
if (AuxOutput == false) {
311+
vfo.setPowerLevel(0);
312+
}
313+
else {
314+
vfo.setAuxPowerLevel(0);
315+
}
316+
unsigned long OffBurstData[MAX2870_RegsToWrite];
317+
vfo.ReadSweepValues(OffBurstData);
318+
Serial.print(F("Burst "));
319+
Serial.print((BurstOnTime / 1000));
320+
Serial.print(F("."));
321+
Serial.print((BurstOnTime % 1000));
322+
Serial.print(F(" mS on, "));
323+
Serial.print((BurstOffTime / 1000));
324+
Serial.print(F("."));
325+
Serial.print((BurstOffTime % 1000));
326+
Serial.println(F(" mS off"));
327+
if (SingleBurst == true) {
328+
vfo.WriteSweepValues(OffBurstData);
329+
if (BurstOffTime <= 16383) {
330+
delayMicroseconds(BurstOffTime);
331+
}
332+
else {
333+
delay((BurstOffTime / 1000));
334+
delayMicroseconds((BurstOffTime % 1000));
335+
}
336+
}
337+
if (ContinuousBurst == false && SingleBurst == false && BurstCount == 0) {
338+
ValidField = false;
339+
}
340+
if (ValidField == true) {
341+
FlushSerialBuffer();
342+
while (true) {
343+
vfo.WriteSweepValues(OnBurstData);
344+
if (BurstOnTime <= 16383) {
345+
delayMicroseconds(BurstOnTime);
346+
}
347+
else {
348+
delay((BurstOnTime / 1000));
349+
delayMicroseconds((BurstOnTime % 1000));
350+
}
351+
vfo.WriteSweepValues(OffBurstData);
352+
if (ContinuousBurst == false && SingleBurst == false) {
353+
BurstCount--;
354+
}
355+
if ((ContinuousBurst == false && BurstCount == 0) || SingleBurst == true || Serial.available() > 0) {
356+
for (int i = 0; i < MAX2870_RegsToWrite; i++) {
357+
vfo.MAX2870_R[i] = OnBurstData[i];
358+
}
359+
Serial.println(F("End of burst"));
360+
break;
361+
}
362+
if (BurstOffTime <= 16383) {
363+
delayMicroseconds(BurstOffTime);
364+
}
365+
else {
366+
delay((BurstOffTime / 1000));
367+
delayMicroseconds((BurstOffTime % 1000));
368+
}
369+
}
370+
}
371+
}
281372
else if (strcmp(field, "SWEEP") == 0) {
282373
BigNumber::begin(12); // will finish on setf()
283374
getField(field, 1);
@@ -420,12 +511,14 @@ void loop() {
420511
}
421512
else if (strcmp(field, "STATUS") == 0) {
422513
PrintVFOstatus();
514+
SPI.end();
423515
if (digitalRead(LockPin) == LOW) {
424516
Serial.println(F("Lock pin LOW"));
425517
}
426518
else {
427519
Serial.println(F("Lock pin HIGH"));
428520
}
521+
SPI.begin();
429522
}
430523
else if (strcmp(field, "CE") == 0) {
431524
getField(field, 1);

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ReadRDIV2 KEYWORD2
1515
ReadRefDoubler KEYWORD2
1616
ReadPFDfreq KEYWORD2
1717
ReadFrequencyError KEYWORD2
18+
setPowerLevel KEYWORD2
19+
setAuxPowerLevel KEYWORD2
1820
ReadSweepValues KEYWORD2
1921
WriteSweepValues KEYWORD2
2022
MAX2870_AUX_DIVIDED LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=MAX2870
2-
version=1.1.1
2+
version=1.1.2
33
author=Bryce Cherry
44
maintainer=Bryce Cherry
55
sentence=Supports the MAX2870 Wideband Frequency Synthesizer chip from Maxim.

src/MAX2870.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,32 @@ int MAX2870::setrf(uint32_t f, uint16_t r, uint8_t ReferenceDivisionType)
536536
MAX2870_R[0x02] = BitFieldManipulation.WriteBF_dword(24, 2, MAX2870_R[0x02], 0b00000000);
537537
}
538538
return MAX2870_ERROR_NONE;
539+
}
540+
541+
int MAX2870::setPowerLevel(uint8_t PowerLevel) {
542+
if (PowerLevel < 0 && PowerLevel > 4) return MAX2870_ERROR_POWER_LEVEL;
543+
if (PowerLevel == 0) {
544+
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(5, 1, MAX2870_R[0x04], 0);
545+
}
546+
else {
547+
PowerLevel--;
548+
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(5, 1, MAX2870_R[0x04], 1);
549+
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(3, 2, MAX2870_R[0x04], PowerLevel);
550+
}
551+
WriteRegs();
552+
return MAX2870_ERROR_NONE;
553+
}
554+
555+
int MAX2870::setAuxPowerLevel(uint8_t PowerLevel) {
556+
if (PowerLevel < 0 && PowerLevel > 4) return MAX2870_ERROR_POWER_LEVEL;
557+
if (PowerLevel == 0) {
558+
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(8, 1, MAX2870_R[0x04], 0);
559+
}
560+
else {
561+
PowerLevel--;
562+
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(6, 2, MAX2870_R[0x04], PowerLevel);
563+
MAX2870_R[0x04] = BitFieldManipulation.WriteBF_dword(8, 1, MAX2870_R[0x04], 1);
564+
}
565+
WriteRegs();
566+
return MAX2870_ERROR_NONE;
539567
}

src/MAX2870.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class MAX2870
117117
int SetStepFreq(uint32_t value);
118118
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
119119
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)
120+
int setPowerLevel(uint8_t PowerLevel);
121+
int setAuxPowerLevel(uint8_t PowerLevel);
120122

121123
void WriteSweepValues(const uint32_t *regs);
122124
void ReadSweepValues(uint32_t *regs);

0 commit comments

Comments
 (0)