Design of Single Chip Microcomputer Weighing System

1. Introduction to the sensor

    Weighing systems are widely used in industrial daily life, from small electronic scales to large scales. Most of the sensors are resistance strain pressure sensors. The Huygens bridge is generally composed of four resistance strain gauges, which are installed on an elastic body. When there is pressure, the strain gauge deforms with the elastic body, the resistance changes, and the bridge generates an unbalanced voltage. Generally, the pressure is linearly proportional to the unbalanced voltage of the bridge.

       The output voltage of the sensor is generally relatively small, at the mV level. It depends on the excitation voltage and sensor sensitivity. Common sensitivities are 1mV/V, 2mV/V, and 3mV/V. For a 2mV/V sensor, when the excitation voltage is 5V, the output voltage at full scale is 2mV/V*5V=10mV.

2. Hardware design

    The sensor signal is relatively small and needs to be amplified before AD collection. At present, there are many AD chips dedicated to weighing systems with integrated amplifiers, which greatly simplifies the design of hardware circuits. Such as TI's ADS1231, Chipsea Technology's CS1231, Haixin Technology's HX710, etc. These chips are all 24-bit AD, and integrated 128 times amplifier (some chips can be set to magnify). This article takes HX710 as an example to introduce. The circuit diagram is as follows:

    Check the manual and you can see that the performance of the chip when powered by 5V is better than that by 3V. But it should be noted that the AVDD of HX710 cannot be greater than DVDD, and most of the single-chip microcomputers currently supply 3.3V power, so 3.3V power supply is used here. ADS1231 does not have this restriction, that is, DVDD can be 3.3V and AVDD can be 5V.

    The common-mode input voltage range of the chip is from AGND+0.9V to AVDD-1.3V, which should be paid attention to in other applications.

    The differential input voltage range of the chip is ±0.5VREF/magnification factor (128)≈±12.89mV. For a sensor with a 3.3V excitation voltage and a sensitivity of 2mV/V, the maximum output voltage is ±6.6mV, which is within the required range of the chip. The difference between the two values ​​is nearly doubled, and about 1 bit of resolution is lost. The greater the excitation voltage, the closer the sensor output voltage is to the input range of AD, the more effective the resolution of AD can be used. But also consider the design of the entire power system.

    In addition, the excitation voltage of the sensor should use the same power supply as the VREF of the chip as much as possible, so that some common mode interference can be suppressed.

3. Software design

    The interface between the chip and the microcontroller is simple, with a data output pin DOUT and a clock pin SCK.

    When the AD conversion is completed once, DOUT changes from high to low. At this time, SCK pin inputs 25~27 clock pulses, and the rising edge of each clock reads data from DOUT. The timing diagram is as follows. The read data timing of other chips is basically the same as this chip.

Programming

int32_t ad_val=0;//AD值

void Get_HX710()
{
    HX710_SCLK_CLR;
    if(READ_HX710_DOUT_PIN)return ;

    for(i=0;i<24;i++)
    {
         HX710_SCLK_SET;
         ad_val=ad_val<<1;
         HX710_SCLK_CLR;
         if(READ_HX710_DOUT_PIN)
           ad_val++;
    }
    HX710_SCLK_SET;
    if(ad_val&0x800000)ad_val|=0xFF000000;
    HX710_SCLK_CLR;
}

Sensor calibration

    The above read is the original value of AD, the sensor needs to be calibrated before being converted into weight. Generally, sensor calibration requires at least two points: zero point and full range (of course, any two points are also possible, because two points determine a straight line). For some high-demand occasions, multiple points are required for segmented calibration, or even different temperature ranges. This article takes two-point calibration as an example. The calibration data includes zero point calibration value, zero point AD value, full scale calibration value, and full scale AD value.

    Calculating the weighing value is relatively simple, that is, to determine a straight line through two calibration points, and find the weight corresponding to the AD value on the curve. The procedure is as follows:

int32_t CaliADCValue[2];//校准的AD值
int32_t CaliSensorValue[2];//校准的传感器值
int32_t ZeroValue;//去皮AD值

void CalcWeight(int32_t AD_Value)
{
       int32_t Sensor_Value = 0;
       int32_t TempCaliADCValue[2];//校准AD值      

       TempCaliADCValue[0] = CaliADCValue[0] + ZeroValue;
       TempCaliADCValue[1] = CaliADCValue[1] + ZeroValue;//去皮
      

       if(AD_Value < TempCaliADCValue[0])//小于0点值
       {
              Sensor_Value = 0;
       }
       else if(AD_Value > TempCaliADCValue[1])//大于最大校准值
       {
              Sensor_Value = CaliSensorValue[1] + (float)(AD_Value - TempCaliADCValue[1])/(float)(TempCaliADCValue[1] - TempCaliADCValue[0]) * (float)(CaliSensorValue[1] - CaliSensorValue[0]);
       }
       else//在校准范围内
       {
              Sensor_Value = CaliSensorValue[0] + (float)(AD_Value - TempCaliADCValue[0])/(float)(TempCaliADCValue[1] - TempCaliADCValue[0]) * (float)(CaliSensorValue[1] - CaliSensorValue[0]);
       }
}

    An important function of the weighing system is tare. The above program includes the function of tare, tare is to add the AD value of tare to the original calibrated AD value and calculate it as the new calibrated AD value.

    AD tare value = current AD value-zero point calibration AD value.

ZeroValue = ad_val - CaliADCValue[0];

 

What this article describes is just a common weighing system design scheme. In some high-demand occasions, it may be necessary to compensate the sensor for creep, using methods such as AC excitation.

 

Welcome to pay attention to the official account "Embedded Technology Development", you can leave a message to me in the background for communication. If you think this official account is helpful to you, you are also welcome to recommend it to others.

Guess you like

Origin blog.csdn.net/zhang062061/article/details/113061057