Skip to content

Commit e016a50

Browse files
committed
Fixes Fract Dividers for Clock Output and PLL Output, rolls version for release
1 parent 4e0976d commit e016a50

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

examples/Example3_int_and_frac_divider_calc/Example3_int_and_frac_divider_calc.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void setup(){
6868
Serial.println(fbVal);
6969

7070
// Clock One -----------------------------------------------------
71-
// To get 16MHz Output = (1600MHz/2)/22MHz = 36.3636
71+
// To get 22MHz Output = (1600MHz/2)/22MHz = 36.3636
7272
// Integer portion = 36
7373
// Fractional portion = .36 -> Need to convert to a HEX value
7474
// 2^24 * .36 = 6039796.76

examples/Example7_external_clock/Example7_external_clock.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void setup(){
4545

4646
clockGen.clockInControl(ENABLE);
4747
// Assuming 12MHz input:
48-
Serial.println("Setting Internal Clock Frequency to 1600MHz.");
48+
Serial.println("Setting Internal Clock Frequency to 1200MHz.");
4949
clockGen.setVcoFrequency(1200.0); // Give float value in MHz.
5050

5151
// Clock One -----------------------------------------------------
@@ -55,7 +55,7 @@ void setup(){
5555
// There are many OUTPUT modes available for each clock - this example uses
5656
// LVPECL (Low voltage Positive Emitter Coupled Logic) mode.
5757
clockGen.clockOneConfigMode(LVPECL_MODE);
58-
Serial.println("Setting Clock One Frequency to 16MHz.");
58+
Serial.println("Setting Clock One Frequency to 6MHz.");
5959
clockGen.setClockOneFreq(6.0); // Give float value in MHz, 6.0 = 6000000Hz or 6MHz
6060
// --------------------------------------------------------------
6161

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Clock 5P49V60 Arduino Library
2-
version=1.0.0
2+
version=1.0.1
33
author=SparkFun Electronics <techsupport@sparkfun.com>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library that enables all functionality for the SparkFun Clock Generator 5P49V60.

src/SparkFun_5P49V60.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ bool SparkFun_5P49V60::begin(TwoWire &wirePort)
2929
void SparkFun_5P49V60::setVcoFrequency(float freq){
3030

3131
//Convert to MHz
32-
_vco_freq = static_cast<uint16_t>(freq);
32+
_vco_freq = freq;
3333
float pll_divider = _vco_freq/_clock_freq;
3434
// Seperate the divider into the whole number and decimal.
3535
uint16_t int_portion = static_cast<uint8_t>(pll_divider);
3636
float decimal = fmod(pll_divider, int_portion);
37-
uint32_t fract_portion = static_cast<uint32_t>(fract_portion * pow(2,24));
37+
uint32_t fract_portion = static_cast<uint32_t>(decimal * pow(2,24));
3838

3939
setPllFeedbackIntDiv(int_portion);
4040
setPllFeedBackFractDiv(fract_portion);
@@ -47,9 +47,10 @@ void SparkFun_5P49V60::setVcoFrequency(float freq){
4747
void SparkFun_5P49V60::setClockOneFreq(float freq){
4848

4949
float division = (_vco_freq/2)/freq;
50+
5051
uint32_t int_portion = static_cast<uint32_t>(division);
5152
float decimal = fmod(division, int_portion);
52-
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
53+
uint32_t frac_portion = static_cast<uint32_t>(pow(2.0,24.0) * decimal);
5354

5455
setIntDivOutOne(int_portion);
5556
setFractDivFodOne(frac_portion);
@@ -63,7 +64,7 @@ void SparkFun_5P49V60::setClockTwoFreq(float freq){
6364
float division = (_vco_freq/2)/freq;
6465
uint32_t int_portion = static_cast<uint32_t>(division);
6566
float decimal = fmod(division, int_portion);
66-
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
67+
uint32_t frac_portion = static_cast<uint32_t>(decimal * pow(2.0,24.0));
6768

6869
setIntDivOutTwo(int_portion);
6970
setFractDivFodTwo(frac_portion);
@@ -78,7 +79,7 @@ void SparkFun_5P49V60::setClockThrFreq(float freq){
7879
float division = (_vco_freq/2)/freq;
7980
uint32_t int_portion = static_cast<uint32_t>(division);
8081
float decimal = fmod(division, int_portion);
81-
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
82+
uint32_t frac_portion = static_cast<uint32_t>(decimal * pow(2.0,24.0));
8283

8384
setIntDivOutThree(int_portion);
8485
setFractDivFodThr(frac_portion);
@@ -93,7 +94,7 @@ void SparkFun_5P49V60::setClockFourFreq(float freq){
9394
float division = (_vco_freq/2)/freq;
9495
uint32_t int_portion = static_cast<uint32_t>(division);
9596
float decimal = fmod(division, int_portion);
96-
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
97+
uint32_t frac_portion = static_cast<uint32_t>(decimal * pow(2.0,24.0));
9798

9899
setIntDivOutFour(int_portion);
99100
setFractDivFodFour(frac_portion);

src/SparkFun_5P49V60.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
// 1 , 2 , 4 , 8 , 16 , 32
4141
static float _cap_arr[6] = {.43 , .43 , .86 , 1.73 , 3.46 , 6.92};
42-
static uint8_t DEF_CLOCK = 16; //16MHz
42+
static float DEF_CLOCK = 16.0; //16MHz
4343

4444
enum REGISTER_INDEX {
4545

@@ -465,8 +465,8 @@ class SparkFun_5P49V60
465465

466466
// Private Variables
467467
uint8_t _address;
468-
uint8_t _clock_freq;
469-
uint16_t _vco_freq;
468+
float _clock_freq;
469+
float _vco_freq;
470470

471471
float _calculate_skew_variables(uint8_t);
472472

0 commit comments

Comments
 (0)