For this assignment I decided to use a mic and capture the output signals from it.This also will be part of my graduation project.
It has two electrodes with a gap between them that acts like a parralel plate capacitor with a fixed charge bonded to its surface. Air pressure variations (sound waves) move one of the electrodes of the capacitor back and forth, changing the distance between the two electrodes, and change the capacitance of the structure. Because the charge on the microphone is fixed, varying the capacitance causes the voltage on the capacitor to also change, satisfying the equation:
$$Q = {c} \times {V}$$JFET is a transitor whoes current flowing between drain and source changes by changing the biasing voltage ( the voltage on its base).
The voltage signal produced by sound modulates the gate voltage of the JFET, labeled VG in the above image causing a change in the current flowing between the drain and source of the JFET (IMIC).An extremely high resistance RG is included to bias the gate of the JFET.
I have searched for my electret mic manfacturer to check the datasheet and the connection recommended. I got my mic from EPE ELECTRONIC CO.
I found that this is the simplest circuit to make the electret mic working.
R1 and C3 together form a high pass filter. It's a filter that passes only frequienceis higher than a certain Cutoff frequency and attenuates frequencies lower than the cutoff frequencey.The value of this capacitor should be calculated at a very low cutoff frequency to not attenuate any signals.
$$C_3 = {{1}\over {2\pi R_1f_c}} = {{1}\over{2\pi\times2200\times5}}=1.4\times10^-5=14\times10^-6=14 uF$$I used 10 uF capacitor
The output signal from the electret mic is very small and the variations in the signal are not really measurable on very small values so I needed to amplify the output signal from the electret mice to amplify the variations and make it scalable to use these variations in my code. As described in the previous step the output signal is in voltage and we need to boost this voltage to be able to read it.
I have already tested the circuit the LM386 audio amplifier but my instructor insisted on using the amplifier we have in the inventory LM4861.It was a little bit challenging as it has a lot of features that I don't really need in my project but I started to explore it.
The LM4861 is a bridge-connected audio power capable of delivering 1.1W of continuousaverage power to an 8Ω load using a 5V power supply.
The output voltage is taken from output pin Vo1 with reference to output pin Vo2 not like most of the amplifiers who give the output signal from one pin with refrence to the ground.
The libraries required for this design:
The components I used with their names in Eagle:
The circuit consists of 3 main parts:
The voltage requlator we have in the inventory is ZLDO1117. It's a voltage regulator with adjustable output.The output value depends on the resistors connected to it.
To have consistent 5V output the resistor should have a ratio of 3:1 as shown in the picture.
I used three resistors of 100 ohm in series then only one 100 ohm as shown in the schematic to give 3:1 ratio.
After making the DRC( Design Rules Check) generate the milling and cutting files as described in Electronics design week.
For more detailed instructions on how to use fab modules for PCB milling check Electronics production week documentation.
Before starting the soldering I always check the PCB with Avometer and the buzzer tool for short circuits or unconnected wires.
I That I used wrong package for the regulator 23 instead of 223 so I edited it in the design then remilled it again.After finishing I started soldering.
After soldering I discovered that pin 7 of the amplifier was not connected to anything and in the datasheet it was stated that it shouldn't be left floating and should be connected to the ground so I soldered it to a GND trace using 0 ohm resistance.I also soldered the switch pins as it will take its power from the ISP and FTDI power pins through the programming and testing and no need for an external power source.
I decided to read the output from the mic directly then from the amplifier output and from the attiny reading through the serial port and compare between the results.
Frequency will be changed using an app I downloaded on my mobile ( there are hunderds of applications on app store) to generate frquencies.
I used a portable oscilliscope that belongs to my husband but all oscilliscopes work in the same way. each channel has a prob that has two terminals, these two terminals should be connected between the two points of the output we want to measure.make sure that the probs is not damaged, I wasted a lot of time thinking that my board is not working as I was not recieving any reasonable signals on the oscilliscope while the whole problem was just in the Probs.
The readings I got:
Frequency (HZ) | Mic output (mv) | Amplifier output (V) |
---|---|---|
500 |
27 |
0.43 |
600 |
32 |
0.48 |
700 |
39 |
0.61 |
800 |
40 |
0.71 |
900 |
44 |
1 |
1000 |
52 |
1.12 |
Calculate the actual gain from the readings:
$$Gain = {V_{out}\over V{in}}={\sum V_{out}\over \sum V_{in}} = {{(0.43+0.48+0.61+0.71+1+1.12)*1000} \over{27+32+39+40+44+52}}=18.8$$Perfect! I got a gain on 18.8 which is really close to the 20 gained I designed the circuit for.
I wrote an arduino code to read the output of the amplifier using the ADC pins in the attiny44 and send the readings through the FTDI cable.
For more info about how to program the board check the Electronics design documentation and Embedded programming documentation.
#define RX 0 // connected to attiny44 pin 12 #define TX 1 // connected to attiny44 pin 13 #define VO1 3 // connected to atting44 pin 10 #define VO2 2 // connected to attiny44 pin11 int output2=0; int output1=0; int result=0; SoftwareSerial mySerial(RX, TX);
void setup() { // put your setup code here, to run once: pinMode(RX,INPUT); pinMode(TX,OUTPUT); pinMode (VO1,INPUT); pinMode (VO2,INPUT); mySerial.begin(9600); }
void loop() { output1 = analogRead(VO1); output2= analogRead (VO2); result=(output2-output1)*20; mySerial.print(output1); mySerial.print(","); mySerial.print(output2); mySerial.print(","); mySerial.print(result); mySerial.print(","); mySerial.print(ADCL); mySerial.print(","); mySerial.print(ADCH); mySerial.print(","); mySerial.print(ADC); mySerial.println(); delay(500); }
I was able to read the data but I though that it's a little bit random and can't be taken as a refrence in coding so I went for a more complex approach which is using the diffrential ADC property in ATTINY boards!
The single endded amplifier has a single output with refrence to the ground. The diffrential amplifier has two outputs ( called diffrential outputs) and the output signal is measured between these two outputs. In another meaning the output is measured from one output referring to the other output instead of the ground.
The amplifier that I'm using LM4861 has diffrential output.
ADC or analog to digital converter is used to convert the analog data comming from sensors to digital signals to enable microcontrollers that works with only digital read that data.
The Attiny microcontrollers pins have the feature of ADC and diffrential ADC. So if the input signal is single endded, ADC will be use. If the input signal is diffrential, diffrential ADC will be used.
I used the code that prof. Neil uploaded in Input devices week schecule under the sound section and modified it to work with my circuit(Attiny 44 and LM4861 amplifier) as it was written for Atting 45 and another amplifier. This code is written in C and it was really hard for me to understand it all so I started to figure out the parts that matters and leave the rest of the code as it is.
The Attiny do the ADC and diffrential ADC through a multiplixer and there is a "ADMUX – ADC Multiplexer Selection Register" which is used to change the channels or the voltage refrence.
The first two bits are for selecting the refrence voltage to be internal (1.1 V) or external ( VCC) and the rest of the bits are for selecting the pins that you are using on attiny and the gain that will be added to the result.
From the tables above I chose the internal voltage refrence and the PA3 and PA2 where I'm connecting my amplifier outpu1 and output2 and gain is one.
And I set BIN bit to 1 ro enable the ADC and ADLAR bit to 1 to lower the overall ADC resolution to 8 bit instead of 10 bit.
When the ADC conversion is done, the results can be found on ADC registers (ADCH and ADCL). In the code it stores the data in two arrays one for ADCH and the other for ADCL. These data are Bytes and I wan't able to send Bytes through Arduino Serial monitor so I checked the data using termite software and decided to use latest version ofArduino to use the serial plotter option.
The Arduino Serial plotter use the data that is sent through serial monitor but instead of just display the data it plots these data.
Serial.print(temperature); Serial.print("\t"); Serial.println(humidity);
put_char(&serial_port, serial_pin_out, array_lo[i]);//serial print ADCL put_char(&serial_port, serial_pin_out,9); // print tab put_char(&serial_port, serial_pin_out, array_hi[i]);//serial print ADCH put_char(&serial_port, serial_pin_out, 10); // print new line
The baud rate was 9600 and I speeded it up upone a recommendation from our local instructor Haggag to 19200 by changing the bit_delay_time to 51 instead of 102.
For more detailed instructions on how to upload a code using Arduino IDE and Fab ISP programmed check Electronics deign week documentatio.