From db162360f9142bf97c59c72d93a9cbf13c9167f8 Mon Sep 17 00:00:00 2001 From: Jason Milldrum Date: Sat, 9 Sep 2017 15:35:37 -0700 Subject: [PATCH] Change set_freq() for auto output enable on 1st call only --- README.md | 4 ++++ src/si5351.cpp | 21 +++++++++++++-------- src/si5351.h | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 01087dc..90282f4 100644 --- a/README.md +++ b/README.md @@ -666,6 +666,10 @@ This library does not currently support the spread spectrum function of the Si53 Changelog --------- +* v2.0.7 + + * Change _set_freq()_ behavior so that the output is only automatically enabled the very first time that _set_freq()_ is called + * v2.0.6 * Call _set_pll()_ in _set_correction()_ to ensure that the new correction factor is applied diff --git a/src/si5351.cpp b/src/si5351.cpp index 3d72890..b82aa42 100644 --- a/src/si5351.cpp +++ b/src/si5351.cpp @@ -125,7 +125,6 @@ void Si5351::reset(void) si5351_write(22, 0x80); si5351_write(23, 0x80); - // Turn the clocks back on... si5351_write(16, 0x0c); si5351_write(17, 0x0c); @@ -174,6 +173,7 @@ void Si5351::reset(void) { clk_freq[i] = 0; output_enable((enum si5351_clock)i, 0); + clk_first_set[i] = false; } } @@ -231,8 +231,12 @@ uint8_t Si5351::set_freq(uint64_t freq, enum si5351_clock clk) } } - // Enable the output - output_enable(clk, 1); + // Enable the output on first set_freq only + if(clk_first_set[(uint8_t)clk] == false) + { + output_enable(clk, 1); + clk_first_set[(uint8_t)clk] = true; + } // Set the freq in memory clk_freq[(uint8_t)clk] = freq; @@ -284,8 +288,12 @@ uint8_t Si5351::set_freq(uint64_t freq, enum si5351_clock clk) { clk_freq[(uint8_t)clk] = freq; - // Enable the output - output_enable(clk, 1); + // Enable the output on first set_freq only + if(clk_first_set[(uint8_t)clk] == false) + { + output_enable(clk, 1); + clk_first_set[(uint8_t)clk] = true; + } // Select the proper R div value r_div = select_r_div(&freq); @@ -416,9 +424,6 @@ uint8_t Si5351::set_freq(uint64_t freq, enum si5351_clock clk) } } - // Enable the output - output_enable(clk, 1); - div_by_4 = 0; int_mode = 0; diff --git a/src/si5351.h b/src/si5351.h index dbed20e..df8416d 100644 --- a/src/si5351.h +++ b/src/si5351.h @@ -308,6 +308,7 @@ class Si5351 struct Si5351Status dev_status; struct Si5351IntStatus dev_int_status; enum si5351_pll pll_assignment[8]; + bool clk_first_set[8]; uint64_t clk_freq[8]; uint64_t plla_freq; uint64_t pllb_freq;