Skip to content

Commit

Permalink
Fixes Fract Dividers for Clock Output and PLL Output, rolls version f…
Browse files Browse the repository at this point in the history
…or release
  • Loading branch information
edspark committed Apr 1, 2020
1 parent 4e0976d commit e016a50
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setup(){
Serial.println(fbVal);

// Clock One -----------------------------------------------------
// To get 16MHz Output = (1600MHz/2)/22MHz = 36.3636
// To get 22MHz Output = (1600MHz/2)/22MHz = 36.3636
// Integer portion = 36
// Fractional portion = .36 -> Need to convert to a HEX value
// 2^24 * .36 = 6039796.76
Expand Down
4 changes: 2 additions & 2 deletions examples/Example7_external_clock/Example7_external_clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void setup(){

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

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

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=SparkFun Clock 5P49V60 Arduino Library
version=1.0.0
version=1.0.1
author=SparkFun Electronics <techsupport@sparkfun.com>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library that enables all functionality for the SparkFun Clock Generator 5P49V60.
Expand Down
13 changes: 7 additions & 6 deletions src/SparkFun_5P49V60.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ bool SparkFun_5P49V60::begin(TwoWire &wirePort)
void SparkFun_5P49V60::setVcoFrequency(float freq){

//Convert to MHz
_vco_freq = static_cast<uint16_t>(freq);
_vco_freq = freq;
float pll_divider = _vco_freq/_clock_freq;
// Seperate the divider into the whole number and decimal.
uint16_t int_portion = static_cast<uint8_t>(pll_divider);
float decimal = fmod(pll_divider, int_portion);
uint32_t fract_portion = static_cast<uint32_t>(fract_portion * pow(2,24));
uint32_t fract_portion = static_cast<uint32_t>(decimal * pow(2,24));

setPllFeedbackIntDiv(int_portion);
setPllFeedBackFractDiv(fract_portion);
Expand All @@ -47,9 +47,10 @@ void SparkFun_5P49V60::setVcoFrequency(float freq){
void SparkFun_5P49V60::setClockOneFreq(float freq){

float division = (_vco_freq/2)/freq;

uint32_t int_portion = static_cast<uint32_t>(division);
float decimal = fmod(division, int_portion);
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
uint32_t frac_portion = static_cast<uint32_t>(pow(2.0,24.0) * decimal);

setIntDivOutOne(int_portion);
setFractDivFodOne(frac_portion);
Expand All @@ -63,7 +64,7 @@ void SparkFun_5P49V60::setClockTwoFreq(float freq){
float division = (_vco_freq/2)/freq;
uint32_t int_portion = static_cast<uint32_t>(division);
float decimal = fmod(division, int_portion);
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
uint32_t frac_portion = static_cast<uint32_t>(decimal * pow(2.0,24.0));

setIntDivOutTwo(int_portion);
setFractDivFodTwo(frac_portion);
Expand All @@ -78,7 +79,7 @@ void SparkFun_5P49V60::setClockThrFreq(float freq){
float division = (_vco_freq/2)/freq;
uint32_t int_portion = static_cast<uint32_t>(division);
float decimal = fmod(division, int_portion);
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
uint32_t frac_portion = static_cast<uint32_t>(decimal * pow(2.0,24.0));

setIntDivOutThree(int_portion);
setFractDivFodThr(frac_portion);
Expand All @@ -93,7 +94,7 @@ void SparkFun_5P49V60::setClockFourFreq(float freq){
float division = (_vco_freq/2)/freq;
uint32_t int_portion = static_cast<uint32_t>(division);
float decimal = fmod(division, int_portion);
uint32_t frac_portion = static_cast<uint32_t>(decimal/pow(2.0,24.0));
uint32_t frac_portion = static_cast<uint32_t>(decimal * pow(2.0,24.0));

setIntDivOutFour(int_portion);
setFractDivFodFour(frac_portion);
Expand Down
6 changes: 3 additions & 3 deletions src/SparkFun_5P49V60.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

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

enum REGISTER_INDEX {

Expand Down Expand Up @@ -465,8 +465,8 @@ class SparkFun_5P49V60

// Private Variables
uint8_t _address;
uint8_t _clock_freq;
uint16_t _vco_freq;
float _clock_freq;
float _vco_freq;

float _calculate_skew_variables(uint8_t);

Expand Down

0 comments on commit e016a50

Please sign in to comment.