Microcontrollers are purely digital devices which work on logic0 and logic1 voltages; still they are widely used for analog signal processing. There are specialized signal processors chips available which are custom made for particular applications; however a general purpose microcontroller is more than enough for small kind of signal processing applications like audio signal input and output. The microcontroller can read the analog input voltage by sampling it and converting it to their digital values. The Analog to Digital Converter (ADC) available in almost all the microcontrollers help in this task. A timer can be used to generate the sampling time period. The sampled values can then read and modify by the microcontroller. The modified signal is then output by the microcontroller in the form of Pulse Width Modulated (PWM) waves. Most of the microcontrollers have the PWM module which helps them in generating analog voltage output at an external device.
In this project PIC18F4550 microcontroller is used to read low voltage signals from a microphone amplifier circuit and try to generate the same signals which are strong enough to produce the sound in a loudspeaker. The audio signals are sampled and the same audio signals are re-constructed at the same instant from those samples in this project. The significance is that in a future project it might be possible to store the sampled values in a medium and then play the audio whenever required.
The PIC18F4550 has a built-in 10bit ADC, which is provided with a13 input channels. It has a PWM module with four output channels. In this particular project the ADC, PWM modules are used along with the timer0 modules and the method of using those modules are already discussed in previous projects. This project is actually an application which makes use of the above mentioned modules. Both the coding and the external circuitry have equal importance in this project. The working of this project can be explained with the help of the following diagram.
VOICE INPUT
The voice input block has a microphone which captures the voice signals from the surroundings. The voice signals are then amplified to a certain level using a small amplifier circuit. The amplified signal may have both positive and negative cycles. Since the ADC of the microcontroller can read only the positive voltages, the signal output from the amplifier should be clamped above the zero voltage level so that the ADC can read the complete cycle.
Hence the VOICE INPUT block is designed to capture the voice signals and modify them in such a way that the ADC of the microcontroller can read them. The following figure shows the different sub blocks inside the AUDIO INPUT block which helps to capture and modify the audio signals.
MICROPHONE CIRCUIT
The microphone used in this project is the commonly available condenser microphone. The microphone is pulled up using a resistor. The voice in the environment causes the capacitor plates of the condenser microphone to vibrate and hence the variation of capacitance occurs. This causes current to flow in an out of the condenser microphone according to the voice signal. The current flow produces voltage drop across the resistor which can then couple out using another capacitor.
The following image is the signal captured using CRO at the output of MICROPHONE CIRCUIT. The Volts/Division of the CRO has been set to 0.05V
AMPLIFIER
The voltage signal coming from the MICROPHONE CIRCUIT is very small and hence these cannot be read by the microcontroller. Before fed this signal to the microcontroller it should be amplified. In this project a NPN transistor is used to amplify the voice signals to a particular level so that the ADC will be able to read it. Another advantage of using the amplifier is that it somewhat reduces the noise which forms along with the voice signal at the MICROPHONE CIRCUIT.
POSITIVE CLAMPER
The positive clamper is very important in this project since the ADC can read only the positive voltages and the amplified voice signals from the AMPLIFIER will be having both positive and negative cycles. The entire signal should be clamped to the positive voltage level without any distortion so that the ADC can read both the cycles. A germanium diode clamper is used in this project which can clamp the signal above a positive voltage which is equivalent to its forward bias voltage.
The following image is the signal captured using CRO at the output of POSITIVE CLAMPER. The Volts/Division of the CRO has been set to 1V
VOLTAGE DIVIDER
The amplified signal could be sometimes larger than which the ADC can convert completely. For all the signal voltages above the ADC reference voltage the ADC will produce its maximum value only. The values which are read by the ADC are directly used to modify the pulse width of the PWM wave. Since the maximum pulse width in a PWM cycle is also limited the voltage level that is produced by the AMPLIFIER should be kept in a suitable range. The voltage divider block which consists of a variable resistor connected across the POSITIVE CLAMPER will help to keep the voltage level in a range which the ADC can read and also the pulse width of a PWM wave can represent.
TIMER
The timer module is used to generate period interrupts at a very high frequency which is well above the frequency of the audio signals. Each time the interrupt fires the value captured by the ADC is read which can be called as the sampled value of the signal at that particular instant. Thus the timer act as the sampling period generating block which samples the audio signal captured by the microphone.
The input signals should be sampled at least double the input frequency, and then only it will be possible to reconstruct the same signal. As the sampling frequency increases the number of samples increases and the reconstructed signal resembles more to the original signal. The audio signals normally fall in a frequency range from 500Hz to 5 KHz and hence the sampling frequency should be well above that frequency.
Using the timer0 module to generate sampling time is explained in a previous project on Sine wave generation using PWM module of the PIC.
ADC
The analog to digital converter (ADC) is used to convert the value of the input audio to its digital equivalent at each and every sampling period. In PIC18F4550 the digital value will be of 10 bytes long which is then used to generate the equivalent PWM wave at the output. The pictorial representation of the sample voltage generated by the ADC module at each sampling interval is shown in the following figure;
Source: How To Use PIC Microcontroller For Voice Input And Output- (Part 23/25)