Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use crystal calibration from OTP #166

Merged
merged 2 commits into from
Feb 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/DW1000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ void DW1000Class::tune() {
byte tcpgdelay[LEN_TC_PGDELAY];
byte fspllcfg[LEN_FS_PLLCFG];
byte fsplltune[LEN_FS_PLLTUNE];
byte fsxtalt[LEN_FS_XTALT]; // not used?
byte fsxtalt[LEN_FS_XTALT];
// AGC_TUNE1
if(_pulseFrequency == TX_PULSE_FREQ_16MHZ) {
writeValueToBytes(agctune1, 0x8870, LEN_AGC_TUNE1);
Expand Down Expand Up @@ -629,8 +629,15 @@ void DW1000Class::tune() {
} else {
// TODO proper error/warning handling
}
// mid range XTAL trim (TODO here we assume no calibration data available in OTP)
//writeValueToBytes(fsxtalt, 0x60, LEN_FS_XTALT);
// Crystal calibration from OTP (if available)
byte buf_otp[4];
readBytesOTP(0x01E, buf_otp);
if (buf_otp[0] == 0) {
// No trim value available from OTP, use midrange value of 0x10
writeValueToBytes(fsxtalt, ((0x10 & 0x1F) | 0x60), LEN_FS_XTALT);
} else {
writeValueToBytes(fsxtalt, ((buf_otp[0] & 0x1F) | 0x60), LEN_FS_XTALT);
}
// write configuration back to chip
writeBytes(AGC_TUNE, AGC_TUNE1_SUB, agctune1, LEN_AGC_TUNE1);
writeBytes(AGC_TUNE, AGC_TUNE2_SUB, agctune2, LEN_AGC_TUNE2);
Expand All @@ -649,7 +656,7 @@ void DW1000Class::tune() {
writeBytes(TX_CAL, TC_PGDELAY_SUB, tcpgdelay, LEN_TC_PGDELAY);
writeBytes(FS_CTRL, FS_PLLTUNE_SUB, fsplltune, LEN_FS_PLLTUNE);
writeBytes(FS_CTRL, FS_PLLCFG_SUB, fspllcfg, LEN_FS_PLLCFG);
//writeBytes(FS_CTRL, FS_XTALT_SUB, fsxtalt, LEN_FS_XTALT);
writeBytes(FS_CTRL, FS_XTALT_SUB, fsxtalt, LEN_FS_XTALT);
}

/* ###########################################################################
Expand Down