dtmf timing, sub-khz frequency resolution

This commit is contained in:
Morgan Redfield 2018-08-04 19:31:53 -07:00
parent 176814bc98
commit 45527b826f
3 changed files with 450 additions and 349 deletions

View File

@ -47,6 +47,7 @@ void setup() {
// let the AU ot of reset
digitalWrite(RESET_PIN, HIGH);
delay(5); // wait for device to come up
Serial.println("beginning radio setup");
@ -73,6 +74,8 @@ void setup() {
Serial.println("changing frequency");
freq = 420000;
radio.frequency(freq);
Serial.print("new frequency: ");
Serial.println(radio.getFrequency());
// set RX volume to minimum to reduce false positives on DTMF rx
radio.setVolume1(6);
@ -88,6 +91,16 @@ void setup() {
// set up DTMF
radio.enableDTMFReceive();
/* DTMF timing settings are optional.
* These times are set to default values when the device is started.
* You may want to change them if you're DTMF receiver isn't detecting
* codes from the HamShield (or vice versa).
*/
radio.setDTMFDetectTime(24); // time to detect a DTMF code, units are 2.5ms
radio.setDTMFIdleTime(50); // time between transmitted DTMF codes, units are 2.5ms
radio.setDTMFTxTime(60); // duration of transmitted DTMF codes, units are 2.5ms
Serial.println("ready");
}
@ -145,7 +158,6 @@ void loop() {
dtmf_to_tx = false;
}
}
delay(20); // make sure the last code is done
// done with tone
radio.setModeReceive();
radio.setTxSourceMic();

View File

@ -249,6 +249,9 @@ void HamShield::initialize(bool narrowBand) {
setSQLoThresh(80);
setSQOn();
*/
setDTMFIdleTime(50);
setDTMFTxTime(60);
setDTMFDetectTime(24);
}
@ -447,7 +450,7 @@ void HamShield::softReset() {
void HamShield::setFrequency(uint32_t freq_khz) {
radio_frequency = freq_khz;
radio_frequency = (float) freq_khz;
uint32_t freq_raw = freq_khz << 4; // shift by 4 to multiply by 16 (was shift by 3 in old 1846 chip)
// turn off tx/rx
@ -482,6 +485,10 @@ void HamShield::setFrequency(uint32_t freq_khz) {
}
uint32_t HamShield::getFrequency() {
return (uint32_t) radio_frequency;
}
float HamShield::getFrequency_float() {
return radio_frequency;
}
@ -985,13 +992,7 @@ void HamShield::enableDTMFReceive(){
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 1, 1);
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, 24);
// idle time
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, 50);
// tx time
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, 60);
//HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, 24);
//HSwriteBitsW(devAddr, 0x57, 0, 1, 1); // send dtmf to speaker out
@ -1000,6 +1001,38 @@ void HamShield::enableDTMFReceive(){
}
void HamShield::setDTMFDetectTime(uint16_t detect_time) {
if (detect_time > 255) {detect_time = 255;} // maxed out
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, detect_time);
}
uint16_t HamShield::getDTMFDetectTime() {
HSreadBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, radio_i2c_buf);
return radio_i2c_buf[0];
}
void HamShield::setDTMFIdleTime(uint16_t idle_time) {
if (idle_time > 63) {idle_time = 63;} // maxed out
// idle time is time between DTMF Tone
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, idle_time);
}
uint16_t HamShield::getDTMFIdleTime() {
HSreadBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, radio_i2c_buf);
return radio_i2c_buf[0];
}
void HamShield::setDTMFTxTime(uint16_t tx_time) {
if (tx_time > 63) {tx_time = 63;} // maxed out
// tx time is duration of DTMF Tone
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, tx_time);
}
uint16_t HamShield::getDTMFTxTime() {
HSreadBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, radio_i2c_buf);
return radio_i2c_buf[0];
}
uint16_t HamShield::disableDTMF(){
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 1, 0);
}
@ -1223,6 +1256,54 @@ bool HamShield::frequency(uint32_t freq_khz) {
return false;
}
bool HamShield::frequency(float freq_khz) {
if((freq_khz >= 134000) && (freq_khz <= 174000)) {
setTxBand2m();
} else if((freq_khz >= 200000) && (freq_khz <= 260000)) {
setTxBand1_2m();
} else if((freq_khz >= 400000) && (freq_khz <= 520000)) {
setTxBand70cm();
} else {
return false;
}
// convert from float to int
uint32_t freq_raw = (uint32_t) (freq_khz * 16); // radio_frequency is accurate to 1/16 kHz
radio_frequency = ((float) freq_raw) / 16; // radio_frequency is accurate to 1/16 kHz
// turn off tx/rx
HSwriteBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0);
// if we're using a 12MHz crystal and the frequency is
// 136.5M,409.5M and 455M, then we have to do special stuff
if (radio_frequency == 136500 ||
radio_frequency == 490500 ||
radio_frequency == 455000) {
// set up AU1846 for funky freq
HSwriteWord(devAddr, 0x05, 0x86D3);
} else {
// set up AU1846 for normal freq
HSwriteWord(devAddr, 0x05, 0x8763);
}
// send top 16 bits to A1846S_FREQ_HI_REG
uint16_t freq_half = (uint16_t) (0x3FFF & (freq_raw >> 16));
HSwriteWord(devAddr, A1846S_FREQ_HI_REG, freq_half);
// send bottom 16 bits to A1846S_FREQ_LO_REG
freq_half = (uint16_t) (freq_raw & 0xFFFF);
HSwriteWord(devAddr, A1846S_FREQ_LO_REG, freq_half);
if (rx_active) {
setRX(true);
} else if (tx_active) {
setTX(true);
}
}
/* FRS Lookup Table */
bool HamShield::setFRSChannel(uint8_t channel) {

View File

@ -240,7 +240,9 @@ class HamShield {
void safeMode();
bool frequency(uint32_t freq_khz);
bool frequency(float freq_khz);
uint32_t getFrequency();
float getFrequency_float();
// channel mode
// 11 - 25kHz channel
@ -392,6 +394,12 @@ class HamShield {
// Writing a single DTMF code:
// setDTMFCode(code); // code is a uint16_t from 0x0 to 0xF
void enableDTMFReceive();
void setDTMFDetectTime(uint16_t detect_time);
uint16_t getDTMFDetectTime();
void setDTMFIdleTime(uint16_t idle_time); // idle time is time between DTMF Tone
uint16_t getDTMFIdleTime();
void setDTMFTxTime(uint16_t tx_time); // tx time is duration of DTMF Tone
uint16_t getDTMFTxTime();
uint16_t disableDTMF();
uint16_t getDTMFSample();
uint16_t getDTMFCode();
@ -480,7 +488,7 @@ class HamShield {
uint16_t radio_i2c_buf[4];
bool tx_active;
bool rx_active;
uint32_t radio_frequency;
float radio_frequency;
/* uint32_t FRS[];
uint32_t GMRS[];
uint32_t MURS[];