Skip to content

Commit

Permalink
revisioned
Browse files Browse the repository at this point in the history
  • Loading branch information
FaultyTwo committed Jun 28, 2022
1 parent c2a0995 commit 4aeecd1
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 67 deletions.
48 changes: 11 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@ An Arduino Library for LTC6904, 1kHz to 68MHz I2C Programmable Oscillator.

For more technical details, please refer to the [datasheet.](https://www.analog.com/media/en/technical-documentation/data-sheets/69034fe.pdf)

## Pinout
![LTC6904 Pinout](pic/ltc6904.png)

## How To Use The Library
Since LTC6904 only has two I2C addresses. To create an object, just use Boolean in the constructor method like this:
```C
LTC6904 clk(0); //0x16
LTC6904 clk2(1); //0x17
```
Then in the setup function:
```C
void setup(){
clk.begin();
clk2.begin();
...
```

To use this library with other I2C ports, you can simply create a TwoWire object then parse it into the 'begin' function:
```C
// ESP32
Expand All @@ -42,33 +31,33 @@ void begin();
```
Initiate the LTC6904 library.

Can be configured to use other I2C ports from a 'TwoWire' object. For default I2C port, just leave the parameter blank.
Can be configured to use other I2C ports from a 'TwoWire' object.<br>
For default I2C port, just leave the parameter blank.

```C++
```C
void setFreq(float freq, uint8_t power)
```
Set frequency rate of LTC6904.
Set frequency value of LTC6904.
**Where:**<br>
- freq: Your frequency value in decimal.
- power: Exponent value of power of 10. (based off science notation).
Ex. 6.83 KHz -> setFreq(6.83,3);<br> **(6.83x10^3)**<br>
Ex. 12.54 MHz -> setFreq(12.54,6);<br> **(12.54x10^6)**
```C++
```C
void setOct(uint8_t oct)
```
Set 'OCT' value of LTC6904.<br>
**^OCT should be in range of 0 to 15.**
Set 'OCT' parameter of LTC6904.<br>
**^'DAC' shouldn't exceed 1023, otherwise will be set back to 15.**

```C++
```C
void setDac(short dac)
```
Set 'DAC' value of LTC6904.<br>
**^DAC should be in range of 0 to 1023.**
Set 'DAC' parameter of LTC6904.<br>
**^'DAC' shouldn't exceed 1023, otherwise will be set back to 1023.**
```C++
```C
void outputConfig(uint8_t _CNF)
```
Configure outputs of LTC6904.
Expand All @@ -81,18 +70,3 @@ Configure outputs of LTC6904.
| 0x03 | Powered-Down | Powered-Down |

***Beyond than 0x03 will set output back to 0x00**

```C++
uint8_t returnOct()
```
Return OCT value of LTC6904.<br>

```C++
unsigned short returnDac()
```
Return DAC value of LTC6904.<br>

```C++
uint8_t returnCNF()
```
Return CNF value of LTC6904.<br>
3 changes: 0 additions & 3 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ outputConfig KEYWORD2
setOct KEYWORD2
setDac KEYWORD2
setFreq KEYWORD2
returnDac KEYWORD2
returnOct KEYWORD2
returnCNF KEYWORD2
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"maintainer": true
}
],
"version": "1.3.2",
"version": "1.4",
"frameworks": "arduino",
"platforms": "*"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=LTC6904-arduino-lib
version=1.3.2
version=1.4
author=Chawin 'FaultyTwo' Treesugol <https://github.com/FaultyTwo>
maintainer=FaultyTwo
sentence=An Arduino Library for LTC6904
Expand Down
Binary file removed pic/ltc6904.png
Binary file not shown.
17 changes: 1 addition & 16 deletions src/LTC6904.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void LTC6904::setOct(uint8_t oct){ //why?
}

void LTC6904::setDac(unsigned short dac){
if(dac >= 1024) //bazinga
if(dac >= 1024)
dac = 1023;
firstFrame = ((firstFrame >> 4) << 4) | (dac >> 6);
secondFrame = ((secondFrame << 6) >> 6) | (dac << 2);
Expand Down Expand Up @@ -54,21 +54,6 @@ void LTC6904::setFreq(float freq, uint8_t power){ // should be float for precisi
write();
}

uint8_t LTC6904::returnOct(){
return firstFrame >> 4; //return shift left four times (OCT value)
}

unsigned short LTC6904::returnDac(){
uint8_t firstDac, secondDac;
firstDac = (firstFrame << 4) >> 4;
secondDac = (secondFrame >> 2) << 2; //only wanted OCT 5 - OCT 0, no CNF
return short(((firstDac << 8) | secondDac) >> 2);
}

uint8_t LTC6904::returnCNF(){
return _CNF; //why?
}

void LTC6904::write(){
_wire->beginTransmission(_adr);
_wire->write(firstFrame);
Expand Down
9 changes: 0 additions & 9 deletions src/LTC6904.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
//rewritten -> 11/20/2021

#ifndef LTC6904_h_ft
#define LTC6904_h_ft

#if (ARDUINO < 100) && !defined(MPIDE)
#error LTC6904 library requires Arduino 1.0 or later
#endif

#include "Arduino.h"
#include "Wire.h"

Expand All @@ -18,9 +12,6 @@ class LTC6904{
void setOct(uint8_t oct);
void setDac(unsigned short dac);
void begin(TwoWire &yourWire = Wire);
uint8_t returnOct();
uint8_t returnCNF();
unsigned short returnDac();
private:
void write();
TwoWire *_wire;
Expand Down

0 comments on commit 4aeecd1

Please sign in to comment.