📜 ⬆️ ⬇️

50 shades of stub * ADC and ADC with Microchip microcontroller computer


Part 3


The previous articles [ 1 ] and [ 2 ] dealt with such parts of the Microchip Independent Microcontroller (MK) Microchip Peripherals such as configurable logic cells and I / O ports with a new useful current limiting function.


Now consider the Analog-to-Digital Converter (ADC) and in particular the new ADC with post-calculator. As you probably already used to, new features of the periphery can help in the implementation of specific functions and simplify the code under the PIC microcontrollers.


Unlike the previous parts, this one will have a bit more theory and a few less examples.


Content



Overview of ADC capabilities


ADC with full confidence can be called Peripheral Independent of the Core, since the ADC has a clocking option from the built-in RC generator and can perform the conversion in the Sleep energy conservation mode. But independence is not limited to this. Many families of PIC16F1xxx have an ADC with the possibility of starting on events, and completely new families of PIC16F188xx have also received a post-calculator.


Consider the possibilities of the ADC for example MK family PIC16F18855 / 75


ADC controllers of this family has:



ADC with a post-calculator consists of several blocks (Fig. 1):



Fig. 1. The structure of the ADC with the computer in the PIC16F18855 family.


Trigger trigger ADC


Gone are the days when it was necessary to manually set the bit to start the ADC measurement. Now, the ADC can be launched by the following events:



VHD and CVD


The sampling / storage unit (VHR) received additional capabilities, mainly related to simplifying the determination of the capacity of the ADC connected to the input. First of all, it helps in creating interfaces with capacitive (touch) buttons.


Microchip offers to determine the capacitance of the sensor using a capacitive voltage divider (Capacitive Voltage Divider, CVD).


The essence of the method is as follows. In the first step (see Fig. 2), the sensor input is connected to the “ground” (its capacity is discharged), and the ADC channel to the supply voltage, the capacity of the water economy department is charged.
Then the sensor input is connected to the VHD ADC, the charge is redistributed between the capacitance of the sensor and the VHD capacity. Then, the voltage measurement at the storage facility tank is measured.


CVD input controlCVD waveform

Fig. 2. Diagrams explaining capacitance measurement using a capacitive voltage divider.


Touching the sensor will change its capacitance, which means we will fix different steady-state values ​​of the voltage at the storage facility capacitor.
To reduce the effect of induced noise on the sensor and / or operator, a differential CVD is used, consisting of two consecutive measurements using CVD, but in the second stage we invert the charges on the sensor and the water economy department (we charge the sensor to the supply voltage, and discharge the water economy device, see figure .3)



Fig.3. Signal diagram with differential CVD.


Details about capacitive sensors, the method of differential CVD and control of the protective conductor can be found under the link [2].


The new ADC with post calculator for support and automation of CVD has the following functions:



Thus, the ADC can automatically perform a differential CVD and provide us with the finished result.


Post-Calculator Functions


The post calculator performs several functions.


Filtration


The ADC module can operate in one of five modes:


Basic mode. In this mode, the ADC can make one or two measurements; after each, an interrupt flag can be set.


Accumulation. For each measurement, the result is added to the battery and the measurement counter is incremented.


Averaging For each measurement, the result is added to the battery and the measurement counter is incremented. Upon reaching the specified number of repetitions, the result is divided and entered into the comparison module, and the next measurement will reset the counter to 1 and the battery value will be replaced with the result of the first measurement.


Queuing averaging. By launching the ADC, the battery and the measurement counter are cleaned and a series of measurements is performed a specified number of times, after which the result is divided and sent to the comparison module.


Low Pass Filter. Each measured value passes through the low-pass filter. Upon completion of a specified number of measurements, the result falls into the comparison module.


Error calculation


Upon completion of each calculation, the result is recorded until the end of the next measurement. It also calculates the difference between:



If you do not need to calculate the difference, then you can choose to calculate the difference between a constant equal to zero.


Comparison with thresholds


The result of the error calculation is compared with the upper and lower thresholds. Additionally, an interrupt may be generated if:



ADC Configuration Examples


Autostart, Filtering


This example shows the ADC configuration in the Mplab Code Configurator (MCC) plugin for the following actions:




Fig. 4. ADC settings with a calculator.



Fig. 5. Read raw and filtered data from the ADC.


Autostart, CVD, averaging, interruption compared to thresholds


This example is based on the implementation of the “ fast creation of a capacitive sensor ” from microchip.wikidot.com [5].


The following configuration is selected:




Fig. 6. ADC settings for CVD.



Fig.7. Reaction to touch the touch button with a single CVD.


Setting the threshold can give us an interruption not for each measurement / series of measurements with filtering, but at the touch of a “button”.


Autostart, Differential CVD, Conversion Series, Averaging


This example uses the following peripheral configuration:




Fig. 8. ADC settings for the differential CVD option.



Fig. 9, Chart at the input of a differential CVD sensor



Fig.10. Touch Response with Differential CVD


From a comparison of CVD (Fig. 7) and differential CVD (Fig. 10), it can be seen that the second one is distinguished by a more “pure” signal with a larger amplitude.


The entire sequence of actions described is performed fully automatically and independently of the core - at this time, the MC can perform some other actions or be in the Sleep micro-consumption mode. By interruption, it remains to calculate the averaged value of the measurement result.


Results


We looked at another part of the Peripheral Independent of the Core - the ADC with the transmitter in Microchip microcontrollers. Some features, such as trigger triggering, or CVD are present in many PIC16F1xxx families, but a new “feature” - ADCC (ADC with a calculator) appeared in the PIC16F188xx family (PIC16F18855, etc.).


The periphery independent of the core is interesting in and of itself, but the possibility of synthesizing functional blocks, i.e. sharing of several peripheral modules for solving specific tasks. In this case, the clock frequency, speed, and bit depth of the core go into the background - the hardware performs specialized functions, and the core deals with software support for the product.


PS
Question to readers. Is it worth it to lay out the source code for the examples for some specific (cheap) demo board or from the descriptions and so everything is clear and code examples are not needed?


Literature:


  1. Configurable Logic Cells in PIC Controllers
  2. 50 shades of stub. I / O Ports
  3. Technology mTouch (tm). Creating capacitive keyboards, sensors and screens.
  4. PIC16 (L) F18855 / 75 Data Sheet. www.microchip.com

')

Source: https://habr.com/ru/post/397479/


All Articles