Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
TDC1000.h
00001 //TDC1000.h 00002 //More plain-english functions for changing settings and stuff 00003 //Created on 7 December 2015, by Eric Lindholm 00004 00005 #include "mbed.h" 00006 #include "TI_Registers.h" 00007 00008 #ifndef TDC1000_H 00009 #define TDC1000_H 00010 00011 ///The SettingChoice variable indicates which setting should be changed. 00012 //It allows the program to look up the how the setting in question is used in a table. 00013 //This only applies to on/off settings. 00014 //Unfortunately, some of these settings are true=on and some true=off. 00015 enum SettingChoice{VCOM_SEL, MEAS_MODE, DAMPING, CH_SWP, EXT_CHSEL, CH_SEL, TEMP_MODE, 00016 TEMP_RTD_SEL, TEMP_CLK_DIV, BLANKING, RECEIVE_MODE, TRIG_EDGE_POLARITY, 00017 PGA_CTRL, LNA_CTRL, LNA_FB, FORCE_SHORT_TOF, ECHO_TIMEOUT, CLOCKIN_DIV}; 00018 const int settingAddress[18] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 00019 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x05, 0x08, 0x08, 0x09}; 00020 const int settingLookUp[18] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x40, 0x20, 00021 0x10, 0x08, 0x40, 0x20, 0x10, 0x08, 0x04, 0x40, 0x04, 0x04}; 00022 00023 /** TDC1000.h 00024 * Chip function manifest for the TDC1000 00025 * More documentation to come. 00026 * Unfortunately, there are a lot of pins that need to be determined. 00027 * This file assumes that a separate stopwatch chip is used, and 00028 * that the MCU only performs the register access functions plus a 00029 * few more. If an invalid number is entered for a 'set' function, 00030 * the setting will be set to the default. 00031 * Pin Number on TDC1000 Function 00032 * 11 Channel Select. Use any digital out pin for this. 00033 * 12 Error pin. Requires an INTERRUPT pin in. 00034 * 15 Enable pin. Use any digital out pin for this. 00035 * 17 Reset pin. Use any digital out pin for this. 00036 * 18 SPI serial clock (SCLK) pin. Tie to an SPI interface. 00037 * 19 Chip select pin. Tied to SPI signal, but can be any digital out pin. 00038 * 20 SPI MOSI serial pin. Tie to an SPI interface. 00039 * 21 SPI MISO serial pin. Tie to an SPI interface. 00040 */ 00041 class TDC1000 00042 { 00043 //Put all functions here, as well as register object. 00044 public: 00045 //!Create TDC1000 instance 00046 TDC1000(PinName ChSel = p22, PinName ERR = p23, PinName EN = p16, PinName RESET = p10, 00047 PinName SCLK = p7, PinName CS = p8, PinName MOSI = p5, PinName MISO = p6); 00048 00049 //Unknown if this should be public or private. Probably private. 00050 TI_Registers tdc1000_registers; 00051 00052 //Error handler function 00053 /** readError Function 00054 * The read error function reads the error register and returns that value. 00055 */ 00056 int readError(); 00057 00058 /** errorHandler function 00059 * The error handler function is not really meant to be called by the user. 00060 * It details the problem the TDC1000 has claimed, but does very little about it. 00061 */ 00062 void errorHandler(); 00063 00064 /** readToggle function 00065 * The read a toggle setting function reads a toggle setting for the TDC1000. 00066 * There are ...a few toggle settings for the TDC1000. 00067 * NOTICE: a value of true does not always equal enabled... 00068 * 00069 * Use the name that is in the TI documentation, with capital letters, of that setting. 00070 * Or, you can refer to this big chart. 00071 * VCOM_SEL | Common-mode voltage reference control (default internal) 00072 * MEAS_MODE | AFE measurement type (default time-of-flight) 00073 * DAMPING | Transmit burst damping (default disabled) 00074 * CH_SWP | Turns on or off automatic channel swapping in mode 2 (default disabled) 00075 * EXT_CHSEL | Allows for external channel selection (default disabled) 00076 * CH_SEL | Selects the active transmit/receive pair (default channel 1) 00077 * TEMP_MODE | Select which temperature measurement channels are used (default Reference, RTD1 and RTD2) 00078 * TEMP_RTD_SEL | Change which type of RTD is currently connected (default PT1000) 00079 * TEMP_CLK_DIV | Modify the clock divider for the temperature mode (default divide by 8) 00080 * BLANKING | Adds power blanking in the standard TOF measurements (default disabled) 00081 * RECEIVE_MODE | Changes receive echo mode (default: single echo) 00082 * TRIG_EDGE_POLARITY | Change what the trigger edge polarity should be (default rising edge) 00083 * PGA_CTRL | Turns on or off the Programmable Gain Amplifier (default active) 00084 * LNA_CTRL | Turns on or off the Low-Noise Amplifier (default active) 00085 * LNA_FB | Modifies the LNA feedback mode (default capacitive feedback) 00086 * FORCE_SHORT_TOF | Forces the chip to use a short TOF mode even with a large timing register (default disabled) 00087 * ECHO_TIMEOUT | Turns on or off the timeout function, which means the chip will stay in receiving mode until 00088 * | it receives all of the necessary echoes (default enabled) 00089 * CLOCKIN_DIV | The divisor for generating the standard waiting period (default 1) 00090 * 00091 * @param choice Choice indicates which setting you want to read. 00092 */ 00093 bool readToggle(SettingChoice); 00094 00095 /** setToggle function 00096 * This toggle function is very similar to the readToggle function, except that 00097 * instead of simply reading the setting value, it changes it. If the value was on, 00098 * this function turns it off, and if it was off, this function turns it on. 00099 * Just like how toggles should work. 00100 * 00101 * @param choice Choice indicates which setting you want to toggle. 00102 */ 00103 void setToggle(SettingChoice); 00104 00105 //Now, more specific functions 00106 /** MODE_SELECT is the mode the chip is in. 00107 * The mode of the chip selects which transducers transmit and which 00108 * transducer receives the signal. 00109 * Mode 0 uses each transducer as both sender and receiver, and maps the 00110 * transmit1 channel with receive2, and transmit2 with receive1. In this 00111 * mode, Channel selection is what tells the chip which transducer channel 00112 * to use: ChSel = 0, transmit1; ChSel = 1, transmit2. In this mode, 00113 * the chip is used primarily for fluid level measurement. 00114 * Mode 1 also uses each transducer as both sender and receiver. This 00115 * mode varies with mode 0 by mapping the transmit1 channel with the 00116 * receive1 channel, and transmit2 with receive2. Otherwise it works 00117 * almost exactly like mode 0. 00118 * Mode 2 is different in that it is for fluid flow measurement. The 00119 * channels are mapped in the same way as mode 1 (TX1-RX1 & TX2-RX2), but 00120 * when a signal is transmitted on one channel, the chip will be listening 00121 * for the echo on the other channel. It can be thought of as sending 00122 * signals back-and-forth between the two transducers. Mode 2 allows for 00123 * automatic channel swapping: as soon as the signal goes one way, the 00124 * chip can automatically send it through the second channel in the other 00125 * direction. For automatic swapping, EXT_CHSEL needs to be off. 00126 * There is no mode 3 ... yet. 00127 */ 00128 int readMODE_SELECT(); 00129 void setMODE_SELECT(int); 00130 //! TX_FREQ_DIV is the transmit frequency divisor. 00131 //! Transmit Frequency = (Frequency_in)/(2^(TX_FREQ_DIV+1)) 00132 int readTX_FREQ_DIV(); 00133 void setTX_FREQ_DIV(int); 00134 //! NUM_TX is the number of transmit pulses. 00135 int readNUM_TX(); 00136 void setNUM_TX(int); 00137 //! NUM_AVG is the number of cycles to create averaging. 00138 int readNUM_AVG(); 00139 void setNUM_AVG(int); 00140 //! NUM_RX is the number of expected receive pulses. 00141 int readNUM_RX(); 00142 void setNUM_RX(int); 00143 //! ECHO_QUAL_THLD is the voltage that qualifies a receive pulse. 00144 //! the value is a number between 0 and 7 that controls the actual threshold value, which is in negative millivolts. 00145 int readECHO_QUAL_THLD(); 00146 void setECHO_QUAL_THLD(int); 00147 //! TX_PH_SHIFT_POS is the point in the transmit burst that the phase shift occurs. 00148 int readTX_PH_SHIFT_POS(); 00149 void setTX_PH_SHIFT_POS(int); 00150 //! PGA_GAIN is the gain of the Programmable Gain Amplifier. 00151 //! The actual gain is the gain number * 3dB. 00152 int readPGA_GAIN(); 00153 void setPGA_GAIN(int); 00154 //! TIMING_REG creates the period between transmit and receive. 00155 //The timing register is a bit different than the rest of these. 00156 int readTIMING_REG(); 00157 void setTIMING_REG(int); 00158 //! SHORT_TOF_BLANK_PERIOD is the blanking period for a short TOF measurement. 00159 int readSHORT_TOF_BLANK_PERIOD(); 00160 void setSHORT_TOF_BLANK_PERIOD(int); 00161 //! TOF_TIMEOUT_CTRL is the echo listening window timeout. 00162 int readTOF_TIMEOUT_CTRL(); 00163 void setTOF_TIMEOUT_CTRL(int); 00164 //! AUTOZERO_PERIOD is the receiver auto-zero period. 00165 int readAUTOZERO_PERIOD(); 00166 void setAUTOZERO_PERIOD(int); 00167 00168 //Other functions that don't play with the registers. 00169 //! Enable the chip 00170 bool read_EN(); 00171 void set_EN(bool); 00172 00173 //! Reset the chip, also resetting all settings. 00174 void resetTDC1000(); 00175 00176 //! utilize external channel selection 00177 bool readChannelSelect(); 00178 void toggleChannelSelect(); 00179 00180 //! Functions that read setting values 00181 int readClockFrequencyIn(); 00182 int readTransmitFrequencyDivision(); 00183 double readEchoQualificationThreshold(); 00184 int readTransmitPhaseShiftPosition(); 00185 double readPeriod0(); 00186 double readPeriod1(); 00187 int readTimingRegister(); 00188 int readNumberofCycles(); 00189 double readShortTOFBlankingPeriod(); 00190 double readAutoZeroPeriod(); 00191 00192 //! Clock frequency is not set within the chip. 00193 //! @param newfreq is the frequency of the system clock in Hz. 00194 void setClockFrequencyIn(int); 00195 00196 //stuff that shouldn't be touched goes here. 00197 private: 00198 //A few variables, like what mode is currently active and the actual digital out stuff 00199 DigitalOut en; 00200 DigitalOut chsel; 00201 DigitalOut reset; 00202 InterruptIn error; 00203 int currentMode; 00204 int fclkin, txfreqdiv, txphshiftpos, timingreg, numavg; 00205 double echoqualthld, t0, t1, shorttofblankperiod, autozeroperiod; 00206 }; 00207 #endif
Generated on Tue Jul 12 2022 23:44:08 by
1.7.2