Using an array that stores the frequency, we need to plot the frequency data on a graphic, using a T6963C 240x128 graphic display. Also, we need it to calculate the frequency value and show it on the display. I’m sending a sketch on the attachment. Positioned below the graphic we will have some input and output data as I described in the following:
1 – Delay: it is a delay that we will set to start acquiring the data before this time. As the microphone senses its first sound and as a button is pressed (we need this two conditions satisfied to start the measuring), so the program will wait this delay and then it will start measuring. It will be a millisecond time. This will be a input, it will be set by buttons.
2 – Time: This is the time that the program will keep storing data from the microphone, as it ends the measuring is complete. It will be a millisecond time. This will be a input, it will be set by buttons.
3 – Frequency: This will be the measured as the following: The wood starts vibrating, values will grow until reaches its peak, then it will decrease until reaches its minimum value, then it will start growing again, and that’s how the wave is. We need the program to consider that the maximum value is the maximum positive, the minimum value is the maximum negative, defining the medium value between then as the Zero Amplitude that will be used as a reference to that active measurement. Both maximum positive and maximum negative values has to be extracted from more than one value, to be sure we are doing it right, as we can have some noise that could trick the program. So, the program could sum 10 values, for instance, and divide it by 10, this way we would have a better accuracy. But, as we don’t know if 10 values is too much or if it’s less than we will need to our sample, it’s important that the programs gives us the choice to set this parameter, in other words, we will have a field on the screen to set the number of samples that program has to sum for sample maximum and minimum, that we called [url removed, login to view], as you can see on the sketch, it will be set by buttons too.
So, each time the amplitude starts from zero, goes to maximum, return to zero, goes to its maximum negative, returns to zero, we have to store it in a array, and it is a cycle. The frequency will be calculated by the formula: Frequency = quantity of cycles / Time. Time is the item 2, define by the user. Quantity of cycles will be the same as the quantity of arrays.
An important observation: maybe the program cannot be precise to get all zeros, so, to be safe, it’s important that the conditional recognizes when values are =0.
Another change we need to do in the original program is to set the start. We need to start when the sensor starts sensing sound AND when we have a high in any other pin (this high will be set with a position sensor that will check if the piece is on the right position to start, you can consider that this sensor is like an NO button linked to a 5Vdc and the other side to the pin you choose).
4 – Graphic: Plot the graphic of input data, use de Zero Amplitude for zero reference as described for Frequency on item 3 above.
So, resuming it: the inputs are delay, time, [url removed, login to view], buttons and the pin you choose for the position sensor. Outputs are graphic and frequency value.
About the buttons, we need it to be 4 buttons, we use two of them to increase or decrease values and the other two to switch the constant (going right and left). In other words, like one button up, other down, one button left, other right. We use Normal Open buttons.
It’s not necessary to build the electrical diagram for the display, we already use this display here and we have it connected to our PIC test board (we use an EasyPic7 from Mikroc).