Designing A/D and D/A converters using microcontroller

Publisher:VelvetDreamerLatest update time:2006-08-09 Source: E代电子Keywords:register Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Keywords:register Reference address:Designing A/D and D/A converters using microcontroller

Previous article:Research on photoelectric detection based on single-chip microcomputer technology
Next article:Pulse coding sensor implemented using single-chip microcomputer

Recommended Content
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号