Skip to content

Commit 0bc17ea

Browse files
authored
Merge pull request #2 from fourstix/issue_1
Updated tune_cap property to take/resturn pf values
2 parents 15546ac + 7510e5f commit 0bc17ea

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

examples/example3_tune_antenna_i2c.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656
# 16 by default but can be 32, 64, or 128, depending on what value you set.
5757
print ('Division Ratio is set to: ', str(lightning.division_ratio))
5858

59-
# Here you give a value of 0-15, which increases the capacitance on
60-
# the RLC circuit in steps of 8pF, up to 120pF. For example giving a
61-
# paramater of 2: 2 * 8pF = 16pF. # The change in frequency is very modest.
62-
# At 15 (max - 120pF), the frequency is around 490kHz down from 512kHz.
63-
# The equation for calculating frequency in an RLC circuit is:
64-
# f = 1/(2pi*sqrt(LC)). To change the capacitance, uncomment the line below.
59+
# Here you can set a value of 0-120, which increases the capacitance on
60+
# the RLC circuit in steps of 8pF, up to 120pF. The change in frequency is
61+
# very modest. At 15 (max - 120pF), the frequency is around 490kHz down from
62+
# 512kHz. The equation for calculating frequency in an RLC circuit is:
63+
# f = 1/(2pi*sqrt(LC))
64+
# To change the capacitance, uncomment the line below.
6565
# lightning.tune_cap = 0
6666

6767
# When reading the internal capcitor value, it will return the value in pF.

examples/example3_tune_antenna_spi.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@
6060
# 16 by default but can be 32, 64, or 128, depending on what value you set.
6161
print ('Division Ratio is set to: ', str(lightning.division_ratio))
6262

63-
# Here you give a value of 0-15, which increases the capacitance on
64-
# the RLC circuit in steps of 8pF, up to 120pF. For example giving a
65-
# paramater of 2: 2 * 8pF = 16pF. # The change in frequency is very modest.
66-
# At 15 (max - 120pF), the frequency is around 490kHz down from 512kHz.
67-
# The equation for calculating frequency in an RLC circuit is:
68-
# f = 1/(2pi*sqrt(LC)). To change the capacitance, uncomment the line below.
63+
# Here you can set a value of 0-120, which increases the capacitance on
64+
# the RLC circuit in steps of 8pF, up to 120pF. The change in frequency is
65+
# very modest. At 15 (max - 120pF), the frequency is around 490kHz down from
66+
# 512kHz. The equation for calculating frequency in an RLC circuit is:
67+
# f = 1/(2pi*sqrt(LC))
68+
# To change the capacitance, uncomment the line below.
6969
# lightning.tune_cap = 0
7070

7171
# When reading the internal capcitor value, it will return the value in pF.

sparkfun_qwiicas3935.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,8 @@ def division_ratio(self, value):
486486

487487
@property
488488
def tune_cap(self):
489-
"""This setting will return the capacitance of the internal capacitors. It will
490-
return a value from one to 15 multiplied by the 8pF steps of the internal
491-
capacitance."""
489+
"""This setting will return the capacitance of the internal capacitor.
490+
It will return a value from 0 to 120pF, in 8pF steps."""
492491
# REG0x08, bits [3:0], manufacturer default: 0.
493492

494493
value = self._read_register(_FREQ_DISP_IRQ)
@@ -500,13 +499,16 @@ def tune_cap(self):
500499
@tune_cap.setter
501500
def tune_cap(self, value):
502501
"""This setting will add capacitance to the series RLC antenna on the
503-
product. It's possible to add 0-120pF in steps of 8pF to the antenna.
504-
The Tuning Cap value must be between 0 and 15."""
502+
product. It's possible to add 0-120pF in steps of 8pF to the antenna.
503+
The Tuning Cap value will be set between 0 and 120pF, in steps of 8pF.
504+
If necessary, the input value is rounded down to the nearest 8pF."""
505505
# REG0x08, bits [3:0], manufacturer default: 0.
506-
if value < 0 or value > 15:
507-
raise ValueError('The Tuning Cap value must be between 0 and 15.')
506+
# Divide down to integer 0 - 15, rounding down
507+
reg_value = value // 8
508+
if reg_value < 0 or reg_value > 15:
509+
raise ValueError('The Tuning Cap value must be between 0 and 120pF.')
508510

509-
self._write_register_bits(_FREQ_DISP_IRQ, _CAP_MASK, value, 0)
511+
self._write_register_bits(_FREQ_DISP_IRQ, _CAP_MASK, reg_value, 0)
510512

511513
# abstract methods
512514
@abstractmethod

0 commit comments

Comments
 (0)