A kind of digital-analog convertion method
Technical field
The present invention relates to a kind of digital-to-analogue conversion (D/A) method.Specifically be pulse width modulation (PWM) the output side signal ripple that utilizes microprocessor and carry out obtaining analog quantity after the RC filtering.
Background technology
D/A switch (D/A) circuit is one of circuit commonly used in the digital system, and it mainly acts on is that digital signal is converted to analog signal, normally utilizes special-purpose D/A switch (D/A) chip to realize.Using special-purpose D/A chip, is that price is higher on the one hand, is to need interface with control chip (normally single-chip microcomputer) to be connected on the other hand, can take many IO mouths.Microprocessor (single-chip microcomputer) is very universal now, household appliances more than 90% are with monolithic processor controlled, in the low occasion of cost requirement, for cost saving, when not using the D/A special chip, have only and make single-chip microcomputer outside with some conventional D/A conversion methods, realize the D/A conversion as methods such as weighted resistance network, T type resistor network or inverted T shape resistor networks, the common ground of this several method is that needed element can be many, to element permissible accuracy also high (all will adopt precision resistance), and to take a large amount of IO pin.Many elements also mean can reduce reliability.
Summary of the invention
At the problems referred to above, that the present invention aims to provide is simple and reliable, directly utilize the internal resource of microprocessor, only takies a kind of method that an I/O mouth just can be realized digital-to-analogue conversion.
For realizing this technical purpose, technical scheme of the present invention is: pulse width modulation (PWM) function of utilizing the interior band of microprocessor (single-chip microcomputer), its I/O pin that has pulse width modulation function is connected with a resistance, and resistance is connected with an electric capacity again, constitutes RC filtering.By little PWM function of handling inside, make its I/O pin output duty cycle that has PWM and the corresponding square-wave signal of digital quantity, after this square-wave signal process RC filtering, become analog signals, thereby finished the D/A switch function.
Adopting the product of the inventive method, in the occasion of using microprocessor (single-chip microcomputer), only need resistance and electric capacity just can realize the D/A conversion, is the extremely low D/A conversion of cost; Circuit can be accomplished very simple, only takies IO pin of single-chip microcomputer, saves mcu resource greatly; Because circuit is simple, need only with two elements, reliability can improve.
Description of drawings
Fig. 1 is the circuit diagram that the inventive method adopted.
Embodiment
Concrete realization circuit is described as follows as shown in Figure 1:
Square-wave signal among the figure is the square-wave signal that microprocessor (single-chip microcomputer) is exported on the I/O pin, utilize pulse width modulation (PWM) function of single-chip microcomputer inside or produce PWM by software with the timer of single-chip microcomputer, output and the square-wave signal that sets the corresponding duty ratio of digital quantity just can obtain corresponding analog signal after RC filtering.
Such as, if the supply voltage of single-chip microcomputer is 5V, when the duty ratio of PWM was set to 37%, after the square-wave signal process R1 of the I/O mouth of PWM output, the C1 filtering, the analog quantity that obtains was exactly 5V*0.37=1.85V.The hardware PWM of common single-chip microcomputer inside is 8 or 10, and then D/A output also can be accomplished 8 or 10 resolutions, can also become the more D/A converter of multidigit resolution by software extensions when needing.