4.3 Firmware Operation

After the initialization of peripherals, the TDS value of water is measured every second and is displayed on the PC terminal application.

The TDS measurement and calculation sequence is as follows:

  • The pulse signal generated by the relaxation oscillator circuit is monitored to observe changes in frequency, which indicate change in the TDS value of the water being tested
  • The CCP peripheral is configured in Capture mode and captures every fourth rising edge of the pulse signal
  • The CCP Capture register value and Timer1 overflow count values are considered. As a result, the period of pulse is determined and then frequency of the signal is calculated
    Note: Further, adjust the frequency of signal with the OPA output calibration value from the Mindi simulation model.
  • The TDS value is measured by determining the conductivity of water, which is calculated from the frequency captured by the CCP module using the following equation:
    C o n d u c t i v i t y = Re l a x a t i o n c i r c u i t c o n v e r s i o n * C a p t u r e d f r e q u e n c y
    Based on the equation mentioned earlier.
  • The ADCC module reads the NTC temperature sensor output of the TDS probe and calculates the water temperature
  • The value of water conductivity is then compensated for temperature
  • The water conductivity is multiplied with the cell constant of TDS probe given by the manufacturer (can be modified in firmware). The value of TDS in water is measured as:
    T D S v a l u e = W a t e r c o n d u c t i v i t y * S a l t f a c t o r
    Note: The salt factor can be modified in the firmware based on the type of salts present in the water.
  • The TDS value is sent to the PC terminal
  • If the TDS probe is disconnected or removed from the water, the hardware disconnect error message is sent
  • If the TDS value is greater than 2000, the TDS value exceed range error message is sent

The circuitry of this demonstrator is designed to measure the TDS values in water within a range of 0 to 2000 mg/L, using a 0.1 µF input capacitor in the relaxation oscillator circuit. By varying this capacitor value, the TDS measurement range can be modified. The designed relaxation oscillator generates pulses within a frequency range of 1Hz to 40 kHz for the TDS range of 0 to 2000 mg/L.

Note: It is recommended that the frequency of pulse signals generated by the relaxation oscillator circuit do not exceed 50 kHz. If the frequency is greater than 50 kHz, the program execution will stay within the CCP ISR for most of the time. This may affect the execution of the application.

Calibration

To accurately calibrate the device, taking frequency readings at every 20 mg/L and adjusting the frequency to the TDS value conversion equation in the firmware is recommended. While calibrating, choosing an accurate TDS meter for the reference is recommended to achieve satisfactory results.