Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using the ADC in the 16F877A to measure short signals from a Piezo

Status
Not open for further replies.

KPKevin

New Member
Hi, I'm a bit embarassed to say that I'm quite new to circuitry design, and a group of us who specialise in music would to use a 16F877A microcontroller to read signals coming in from a piezo which is being used like a small microphone placed underneath a drum skin. However none of us are particularly fluent in electronics.

Using an oscilloscope we are taking readings that the pk-pk voltage is around 25V from each strike directly above the piezo.

From what I believe, the ADC input needs to be at around 0 - 5V.

The length of each waveform lasts around 50ms with an approximate time period of around 5ms and I am wondering if the 16F877A ADC is fast enough to sample at this speed.

There are a few other questions I'd like to ask, but I'd like to get the basic input circuit prepared before I start diving into things that could get a lot more complicated.

It'd also be useful if a circuit diagram that was provided came with the principle behind why a circuit was built that way. If this could be provided me and my group would be very thankful.
 
Perhaps you should try using google?, there are various such projects already on the net.

Here's a popular one, and it should give you everything you need.
 
Thanks for the information and link to the eDrum, it has helped us significantly with the circuitry we require to build such an instrument.

I would like to move onto the reason as to why we're particularly interested in how fast the ADC on the 16F877A works from people's past experiences with it. - This is so we can use several of these piezos on a larger surface area and measure the time delay detected between 4 of them (So a single strike will be triggering several piezos in quick succession, with a maximum time delay of around 2.5ms), so we are not only detecting the maximum pk-pk voltage using the ADC, although that is something we'd like to do as well, but would have already been covered by the information available on the eDrum website.

We have already built a separate output from one of the piezos that performs a FFT on the waveform to trigger different samples depending on the tool used to strike the instrument.

I once again express my gratitude for your support previously.
 
Half wave -> Full wave rectifier

Hi, I've been testing the circuit from the website you provided, the circuit is built and tested, and it is working perfectly.

However we found that we need a full wave rectifier for the waveforms that we will be detecting using the PIC chip.

**broken link removed**

I was wondering if anyone here would be able to help with changing this circuit design into a full wave rectifier without changing anything too much, I believe that the use of an extra opamp is required.
 
Circuit Evaluation

This is my first time designing a circuit as I have not dabbled in electronics before, I have added this to the previous circuit based on this diagram in the link that you sent me.

**broken link removed**

And thus designed this circuit, however I do not know whether or not it will work, are there any flaws that you can immediately point out?

**broken link removed**
 
Yes, the design you tried to copy from used the first opamp in inverting mode, so you can;t just connect it like that.

I would suggest you try fig. 6 from the page I linked, and use R1 as 47K as you have above.
 
Thanks! Looks like I'll have to rewire the 8 channels then. I'll be able to build the circuit Monday once University re-opens, I'm already quite behind and the deadline is coming up.
 
hi,
This is single OPA, fullwave version of a prec rect as shown on the OPA datasheet.
 

Attachments

  • PrecRect1.gif
    PrecRect1.gif
    51 KB · Views: 410
Oh! I forgot to explain that entirely. As for the CA3140 circuit, I'd love to usean op amp with full wave rectifying function already built in, but I'd have to end up using 8 separate ones, however it could make things easier in the end, I'll test out two configurations using the CA3140 method, and then use the LM324 to also try out the diagram in Figure 6 from earlier.

Also with the full wave rectification - I need this because both sides of the waveform produced by the piezo are important to me. The first peak is the most important to me, and sometimes the peak is negative. However a half wave rectifier is canceling out this signal!

The project itself is dependent on Time Delay between 4 piezos on the same drum skin. This time delay happens in the order of less than a millisecond, but is still noticeable when using an oscilloscope to compared such data.

**broken link removed**

If you look at the readings on the graph, you can see that one peak from a piezo arrives before the rest, followed by two at relatively the same time, followed by the one on the opposite side of the drum.
 
And with very different waveforms, probably relating drum-head harmonics, which are surprisingly complex.

You know, a PIC A/D could read all those without rectification. You could get 32 reads out of one of those 1ms/division boxes on that scope image - that's 8 sample points for each channel.
 
The drum hit itself was soft - medium hit. That produced a peak to peak of around 10 volts.

I've read on the datasheet that a voltage underneath 0V and a voltage above 5V will damage the analogue inputs on the PIC chip as well as be undetectable.

Well hit at the hardest volume the piezo produced a pk-pk voltage of around 30V - 35V (No I'm not kidding!).

That graph there is a close up of the waveforms to look at the time delay itself. If you were to zoom out and look at the rest of the data you'd see that other than the start of the wave, all 4 piezos produce almost exactly the same waveform at almost exactly the same time, but as you said, the drum does produce complex harmonics so when zoomed in you can see the slight differences here and there. The data captured here lasts for around 50 ms or more but only the first few milliseconds are shown.
 
Last edited:
The drum hit itself was soft - medium hit. That produced a peak to peak of around 10 volts.

I've read on the datasheet that a voltage underneath 0V and a voltage above 5V will damage the analogue inputs on the PIC chip as well as be undetectable.

The PIC isn't fed from the input anyway, it's fed from the oputput of the opamp, which is only fed from 8V, has a 0.7V diode on the output, and the opamp used can't approach the supply rail very close either.

PIC inputs also have protection diodes, as long as it's fed via a suitable current limiting resistor it's perfectly safe.

Well hit at the hardest volume the piezo produced a pk-pk voltage of around 30V - 35V (No I'm not kidding!).

That graph there is a close up of the waveforms to look at the time delay itself. If you were to zoom out and look at the rest of the data you'd see that other than the start of the wave, all 4 piezos produce almost exactly the same waveform at almost exactly the same time, but as you said, the drum does produce complex harmonics so when zoomed in you can see the slight differences here and there. The data captured here lasts for around 50 ms or more but only the first few milliseconds are shown.

Looking at the original circuit, it won't accept negative peaks anyway, as it only uses a single supply, and has a protection diode to remove the negative input peak.
 
Heh thanks for the information. However I forgot to mention that the maximum amplitude detected is also important as we wish to use 3 variables to control what sound is produced computer side.

#1 Amplitude
#2 Time Delay
#3 FFT analysis.

A total of 5 piezos are used for each drum. 4 are used to measure time delay and go through the PIC as microcontrollers are much better at working in the order of microseconds to analyse such data. The last piezo is directly connected to the line in of the computer and the FFT analysis is performed via the computer, which acts like a switch that routes the instructions from the PIC through different routes depending on the last FFT detected.

With the amplitude I believe that the ADC works between 0 - 5V and anything below or above this value is capped or discarded, hence the need to bring the voltage to a suitable level.
 
Last edited:
Um, is this an excercise on doing FFT's on discontinuous functions? If not, maybe you should check out my previous post again.
 
I have tried all suggested circuits. The one proving the most fruitful being figure 4 from **broken link removed** with a potentiometer at the front to configure the overall voltage output of each piezo. It's working a charm at the moment, I had to add a 220 nF capacitor at each output to eliminate DC offset that varied amongst the output of the TL072 OP AMP chips - some would produce a strange offset of as much as -140mV whilst others would produce offsets of +25mV.

Now that the circuitry is out of the way I would like to get to discussing the PIC16F877A itself.

I want to ask several basic Yes/No questions.

Am I right in assuming this from what I read on the datasheet?

#1 The input at VREF and VDD should be 5.12V or more if I want the maximum range (0V - 5.12V) of voltages to be detected.

#2 Any input above 5.12V gets capped at 5.12V when read by the ADC.

#3 There is no interrupt function on AN0 - AN7.

#4 The ADC treats all negative values on the input as zero.

#5 There is a 10 bit register value where the ADC conversion is stored momentarily, and the ADRESH values are 5.12V divided by 128, meaning I have a 40mV quantisation step.

#6 ADRESH is the 8 most significant bits, while ADRESL is the 8 least significant bits.

#7 Acquisition time for each sample generally takes around 2 - 6 microseconds and if I were to poll around 8 inputs, it'd take 16 - 48 microseconds to do a complete loop.
 
1 - yes
2 - yes
3 - sorta, the A/D has an interrupt on complete, probably isn't what you want
4 - yes and no - don't give it a negative input, ever
5 - no, 10 bits is not 128. 10 bits is 1024, 5mv steps
6 - yes, but it's 10 bits, not 16. You can select right or left justify on these.
7 - no, check your math. Top end on that A/D is around 30khz, not 166khz
 
Last edited:
...and you don't want the rectifier, precision or otherwise, if you are doing FFT, FFS!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top