vcc = (int)(4096L * *BGV / res); // (12-bit ADC algorithm)Calculate VREF pin voltage, i.e. battery
voltage
// vcc = (int)(1024L * *BGV / res); // (10-bit ADC algorithm)Calculate VREF pin voltage, i.e. battery
voltage
//Note that this voltage is in millivolts (mV)
UartSend(vcc >> 8); //Output voltage value to UART
UartSend(vcc);
while (1);
}
The method above uses the 15th channel of the ADC to invert the external battery voltage. In the ADC measurement
range, the external measurement voltage of the ADC is proportional to the measurement value of the ADC, so the 15th
channel of the ADC can also be used to reverse the input voltage of the external channel. Assuming that the current
internal reference signal source voltage is BGV, the ADC measurement value of the internal reference signal source is
res
bg
, and the ADC measurement value of the external channel input voltage is res
x
, then the external channel input
voltage Vx=BGV / res
bg
* res
x
;
17.5.6 Using ADC as Capacitive Sensing Touch Keys
Key is one of the most commonly used parts in the circuit, and it is an important input method for the human-
machine interface. We are most familiar with mechanical keys. The mechanical keys have a disadvantage of limited
contact life especially for the cheap keys. And they are easy to appear poor contact and failure. Non-contact keys have
no mechanical contacts, long life and easy to use.
There are various solutions for non-contact keys. Capacitive-sensing keys are low-cost solutions. Specialized ICs
were used to implement capacitive-sensing keys many years ago. With the enhancement of MCU functions and the
practical experience of users, MCUs were used to implement capacitive-sensing keys directly. The technology of
capacitive sensing keys is mature. The most typical and reliable one is the solution using ADC.
The solution of using STC series MCUs with ADC is described in detail in this document. Any MCU with ADC
function can be used to implement the scheme. The first three diagrams below are the most commonly used methods.
The principles are the same. The second diagram is used.