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.
Fig. 2: Block Diagram of Audio Signal Generation using PIC18F4550
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.
Fig. 3: Block Diagram of Audio Input Block using PIC18F4550
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
Fig. 4: Output Waveform of Condenser Microphone on CRO
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.
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
Fig. 5: Output Waveform of Germanium Diode Positive Clamper on CRO
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.
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.
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;
Fig. 6: Sample Voltage by ADC Module IN PIC18F4450
The Blue colored block in the above figure represents the voltage levels approximated by the ADC module on each sampling interval according to the voice signal received. The voice signal is represented by the orange colored line.
The PWM module is continuously producing a PWM wave whose pulse width can vary after each sampling time. The timer module generates the interrupt, read the ADC value and write a corresponding value to the PWM module so that the pulse width of the PWM cycles at that particular sampling time can generate the voltage at an external device which is equivalent to the voice signal at that same sampling time period.
The following figure shows the sampling of a signal voltage by the ADC module and the reconstruction of the same signal by the PWM waves. It can be noted that the reconstructed signal although not exactly same as the original signal but somewhat resembles it. As the sampling frequency increases the reconstructed signal resembles more to the original signal.
Fig. 7: Signal voltage by ADC module in PIC and Re-constructed sine wave using PWM module of PIC
The figure1 represents the sampling of an audio signal and the orange line is the signal voltage. The vertical lines shows the sampling instants at which the digital equivalent value of the signal is read into. These sample values can be then used to re-construct a wave which resembles the original wave as shown in the figure2.
The methods of generating PWM waves to produce signals are explained in a previous project on Sine wave generation using the PWM module of PIC.
The voice output block converts the PWM wave to its equivalent voltage at a loud speaker. Since the loudspeaker is a device which can itself convert the PWM wave to its equivalent voltage and produce the corresponding sound, no separate filter circuit is required. This particular block mainly has a driver circuit which can drive the comparatively current consuming loud speaker with the PWM waves.
The details of the driver circuit used to drive the loud speaker according to the PWM waves are explained in a previous project on the Sound generation using PWM module of the PIC.
The following image is the signal captured using CRO at the loud speaker. The Volts/Division of the CRO has been set to 1V. The signals are not very clear due to the loading effect of the loud speaker.
Fig. 8: Output Waveform of PWM wave at loud speaker