1. Features of the PIC16C62× series of microcontrollers
The PIC16C62× series is a RISC reduced instruction, Harvard structure bus, and 18-pin microcontroller. It has the characteristics of low power consumption, high performance, fully static, 35 instructions and extremely easy to program. OTP films are extremely cost-effective. In addition to the characteristics of general microcontrollers, the PIC16C62× series integrates two analog comparators and a 4-bit programmable reference voltage source (REF). If you take advantage of these characteristics of the microcontroller, you only need a few peripheral components to have A/D and D/A conversion functions, and the resolution can reach 8bit~10bit. The price advantage makes its application prospects in the industrial control industry, instrumentation, and home appliances extremely optimistic.
This article uses 8-bit resolution to demonstrate the implementation method of A/D and D/A conversion. The solution for higher resolution is completely similar, with only minor adjustments in programming.
2. D/A converter
Some of the internal functional modules of the PIC16C62× series microcontroller and the A/D and D/A circuits are shown in Figure 1.
Figure 1 Part of the functional modules and conversion circuit of PIC16C62×
2.1 Using the internal reference source The
internal reference source of the PIC16C62× series microcontroller consists of a 16-tap resistor ladder network, which is equivalent to a 4-bit resolution D/A converter. The reference source is composed of VRCON special function register control. The VRCON register is defined as follows:
VREN: REF reference voltage source enable bit. When VREN=1, the internal reference voltage source is enabled.
VROE: REF output selection bit. When VROE=1, REF is output to the RA2 pin.
VRR: REF segment selection, the REF value can be programmably set to high and low segment output.
VR3~VR0: 4bit REF voltage value. Changing the value of the 4 bits changes the voltage value of REF. For the purpose of the following explanation, the 4-bit binary code is defined as follows:
VR= VR3VR2VR1VR0
VR-1=VR3VR2 VR1VR0-1
According to the characteristics of PIC16C62×:
(1) When VRR=1, the low-section reference voltage output REFL=DD*VRL/24, and the resolution unit VF1=DD/24.
The REFL voltage value range is: VRL*DD/24, VRL= 0~15, indicating the corresponding low-segment binary code value.
(2) When VRR=0, the high-section reference voltage output REFH=DD/4+DD*VRH/32, and the resolution unit VF2=DD/32. VRH=0~15, VRH represents the corresponding high-segment binary code value.
The REFH voltage value variation range is: DD/4~23*DD/32.
The above DD is the power supply voltage of PIC16C62×. As long as a simple power supply decoupling circuit is added to the power supply end, the anti-noise requirements of the reference voltage REF can be well guaranteed.
It can be seen from the above that the internal reference source of the PIC16C62× series microcontroller is actually a 4-bit D/A converter that can be set to two segment values. The binary code value of each segment is 0~15, and the resolution units of the two segments are different. Same. In order to design a D/A converter of 8bit and above, the range of REF needs to be expanded. Use the REFH value, that is, REFH =DD/4~23*DD/32, expand to REFH= (DD/4-DD /32) ~23*DD/32, extend a resolution unit value DD /32 to the low end of the voltage, Equivalent to the binary code value VRH=0~15 expanded to -1~15. This is the key to achieving D/A conversion of 8bit and above. VRH= -1 is a special condition, which exceeds the limit of the binary code value VRH corresponding to the REF value range, and must be realized by the low-section reference voltage REFL and the external programmable fixed attenuation ratio resistor network. There is a field effect OC gate (open-drain gate) inside the PIC16C62×, which is connected into the application circuit shown in Figure 1.
When OC gate GK is turned on, the attenuation coefficient =1/(0+1) 0=2kΩ (internal fixed resistance).
When the OC gate GK is turned off, the attenuation coefficient = 1 (the RA4 pin is high impedance).
The field effect OC gate performs I/O operations on the RA4 pin through programming to achieve its turn-on and turn-off.
From the above, the REFH reference value corresponding to the high-segment VRH=-1 can be obtained by multiplying the REFL value corresponding to the low-segment binary code value VRL by a coefficient.
When VRH=-1, REFH=DD/4-DD/32=7DD/32, establish the following equation
7DD /32 = (DD/24)*VRL* (1)
VRL=1~15 (take an integer) (2)
K <1 (3)
Multiple sets of solutions can be obtained for VRL=6~15, any one of which can be chosen, for example: VRL=7, =0.75.
The coefficient is determined by the value of external resistor 1. When programming, first determine the VRL value, then calculate the coefficient according to equation (1), and then calculate the resistance value of 1 according to =1/(0+1), 0=2kΩ. 1 can also be replaced by adjusting a potentiometer.
2.2 Program 4bit PWM to achieve 8bit D/A conversion
Assume that the 8-bit binary number to be D/A converted is stored in a certain unit of the data memory of PIC16C62×; and is defined as the following format:
Divide it into two 4-bit binary codes: VR=VR3VR2VR1 VR0, VP=VP3VP2VP1V P0. VR controls the reference voltage source to implement 4-bit D/A conversion, and VP is used to perform 4-bit PWM (pulse width modulation) on the output voltage of the reference source. The high level of PWM is the VREF voltage value corresponding to VR, and the low level of PWM is the VREF voltage value corresponding to VR-1. In this way, the two VREF values corresponding to the two adjacent binary codes of the 4-bit D/A conversion reference voltage source are used as the high level and low level of the 4-bit PWM respectively, which forms an 8-bit D/A converter. Figure 2 and Figure 3 show the difference between conventional PWM and D/A+PWM. The high level of conventional PWM is VDD (such as 5V), and the low level is 0V. The principle is well known and will not be described in detail here. The PWM working principle of D/A+PWM described in this article is the same as that of conventional PWM, except that the high level and low level of the PWM pulse are determined by the values of VR and VR-1 respectively. When programming, first divide the 8-bit binary number to be D/A converted into the high 4 bits and the low 4 bits. The low 4 bits are stored in a certain data memory R0 of PIC16C62×, and the high 4 bits are right-shifted (moved to the word) 4 times. section low end) is stored in another data memory R1 of PIC16C62×. Use a timer interrupt of PIC16C64× to write a PWM program. The duty cycle of PWM is determined by the value in R0 (that is, the VP value). Set the timer interrupt to the highest priority level to ensure PWM duty cycle accuracy. The essence of this program is: assign a value to the VRCON control register in the PWM program whose duty cycle is determined by the binary code VP. The high level of the PWM pulse is generated by loading VR into the lower 4 bits of the VRCON control register, and the low level of the PWM pulse is generated by loading VR-1 into the lower 4 bits of the VRCON control register. It needs to be judged in the program: when VRH=0, the REF corresponding to VR-1 is realized by the REFL low-segment value mentioned above.
OUT is the 8-bit D/A output. The PWM filter circuit is composed of 0, 2, and 1, and its time constant is selected according to the PWM period, which is related to the speed and programming required for D/A conversion in specific applications. Due to the high-speed RISC simplified instructions of PIC16C62×, the D/A conversion speed can reach more than 400Kbit/s. The temperature drift requirement of DD is as small as possible. OUT can be amplified or level converted as needed.
3 A/D converter
As shown in Figure 1, the OUT analog signal output by the aforementioned D/A conversion is connected to the non-inverting terminal of a comparator inside the PIC16C62×, and the analog signal to be converted is connected to the inverting terminal of the comparator. This constitutes a typical sequential Approximation A/D converter. Its principles are explained very clearly in many textbooks and will not be described in detail in this article.
Since PIC16C62× has a comparator interrupt function, making full use of comparator interrupts can improve programming efficiency and increase A/D conversion speed. Define a PIC16C62× data memory unit as the A/D conversion result data register. Before starting the A/D conversion, preset an empirical data in this register, and use the aforementioned D/A conversion method to convert this data into an OUT level. The OUT level is compared with the analog signal level to be converted. When the level of the non-inverting terminal of the comparator is higher than the level of the inverting terminal, the comparator outputs logic "1" and generates an interrupt. When the level of the non-inverting terminal of the comparator is lower than the level of the inverting terminal, the comparator outputs logic "0" and also generates an interrupt. The comparator output logic state "1" or "0" can be obtained by querying the relevant bits of its special function register. In the comparator interrupt program, the data in the "A/D conversion result data register" is modified successively according to the query results, so that the OUT level successively approaches and finally converges to the level of the analog signal to be converted. When convergence, the value in the data register is is the A/D conversion result. The quality of the convergence algorithm is the key to improving the A/D conversion speed, which is related to the specific application and peripheral circuit parameters. However, the analog signals converted in most home appliance applications are low-speed and slowly changing signals, and the requirements for A/D conversion speed are not high. Therefore, the requirements for the convergence algorithm are not high, and an algorithm that compares sequentially from MSB to LSB is usually used. In addition, the analog signal to be converted must undergo level conversion so that its change range is consistent with the change range of the OUT level.
4 Summary
The PIC16C62×; series of microcontrollers have two independent analog comparators inside, and its digital I/O port has the ability to directly drive light-emitting diodes and LED digital tubes. The application circuit using the A/D and D/A converter principles described in this article only occupies the internal resources of an analog comparator, a reference source, and 4 pins. The peripheral circuit is also very simple, and the application system is easy to reduce in size. Small, highly reliable and cost-effective. The disadvantage is that the conversion speed of A/D and D/A is slow and takes up a lot of time resources of the microcontroller, which is suitable for low-speed changing signal applications.
Reference
1 MICROCHIP. PIC16C62× DATA SHEET. 1997. 10 ~ 22
Previous article:Research on photoelectric detection based on single-chip microcomputer technology
Next article:Pulse coding sensor implemented using single-chip microcomputer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Free gifts: Aim TTi current measurement probe, professional signal generator, JD card and other small gifts are waiting for you
- Happy Mid-Autumn Festival and National Day friends!
- TangDynasty Software Manual for Anlu FPGA IDE
- Looking for a single chip microcomputer
- [TOPWAY 5-inch smart TFT module review] First experience
- [Hua Diao Experience] 20 Music Visualization: A Series of Trials with ESP32_C3 and WS2812B
- One week evaluation information delivered on time~
- How to use simth Smith chart software
- EEWORLD University ---- 2021_Digikey KOL Series: Application of New Intelligent Exposure Algorithm in Face Recognition
- How to use Bluetooth 4.2 to implement the Internet of Things