0
\$\begingroup\$

I am trying to create an electric tuner using a piezo (so it can be used to detect vibrations rather than a mic which is subject to ambient noise)

I have the schematic below using a voltage regulator to create 5v (5.09V is the closest I could get)

The battery then powers the ADC and the op-amp and the 10-bit data is sent to the SPI pins of the Raspberry pi.

I am attempting to create a 3.3V bias so the negative voltages generated by the piezo can be read. (3.3V is the simplest implementation as 3.3V is all ready to go)

I have recently changed the design because the 5V from the RPi was unstable and giving me erroneous result but I am still getting bad results from my current setup.

The code I use reads the pin and converts the data into it's correct voltage the data is then displayed as a graph and created as a .wav file (the .wav will be used when I can get the setup right to listen to the note played)

Here is the code:

import spidev
import time
import os
import matplotlib.pyplot as plt
import wave
import numpy as np
from scipy.fftpack import fft, ifft
from scipy.io.wavfile import write

spi = spidev.SpiDev()
spi.open(0,0)

def read_spi(channel):
    spidata = spi.xfer2([96,0])
    data = ((spidata[0] & 3) << 8) + spidata[1]
    return data

def ConvertVolts(data):
    volts = (data * 5.09) / float(1023)
    return volts

ADC_channel = 0
samples = []


print "Starting detection..."
start_time = time.time()
try:
    while(True):
        samples.append(ConvertVolts(read_spi(ADC_channel))
except KeyboardInterrupt:
    pass
readTime = time.time() - start_time
print "Detection complete."
print("%s seconds" % (readTime))
time_axis = range(1,len(samples)+1,1)
print "Generating graph..."
plt.plot(time_axis,samples)
npSamples = np.asarray(samples)
scaled = np.int16(npSamples/np.max(np.abs(npSamples))*32767)
write('audio.wav', int(len(samples)/readTime),scaled)
plt.show()

Using the code above I generate a graph which looks like this:

enter image description here

This is the results for just under 1 second of reading.

schematic

simulate this circuit – Schematic created using CircuitLab

Can anyone explain why I am not getting a constant 3.3V displayed on my table?

Thank you.

EDIT:

When I remove the op-amp and connect the ADC input to the positive rail (5.09V) I get a reading of 768 or 3.8 Volts. So the code must be slightly out. But I don't get why the 3.3V on the RPi is inconsistent unless I'm sinking too many milliamps and it's unstable.

EDIT2: Updated the design. I have two 9V batteries and 2 LMT317. One generating 5.09V and one with 2.46V. 2.46V is connected to the input to the ADC and 5V is powering it. I'm still getting bad results fluctuating between 768, 256, 96 and 0. (3.82V, 1.27V, 0.47V and 0V, respectively)

Really don't understand at the moment.
Also, if CH0 is unplugged entirely it fluctuates between 0 and 256.

schematic

simulate this circuit

\$\endgroup\$
6
  • \$\begingroup\$ Try forcing data to some fixed value before converting to volts then what do you see? In other words abandon the result of reading the ADC. \$\endgroup\$
    – Andy aka
    Commented Oct 21, 2015 at 13:00
  • \$\begingroup\$ So just fake a 10-bit binary number and convert that? Does the setup look like it has no reason to not return 3.3V? \$\endgroup\$ Commented Oct 21, 2015 at 13:14
  • \$\begingroup\$ Yeah just to convince yourself it's not in the back half of the code. I can't see anything wrong with the circuit but it was only a 30 sec glance. \$\endgroup\$
    – Andy aka
    Commented Oct 21, 2015 at 13:25
  • \$\begingroup\$ I guess it's just a mistake when drawing: MOSI is MasterOutSlaveIn and MISO is MasterInSlaveOut. You have to connect MOSI to DIN and MISO to DOUT. And what's the difference between GND and -RAIL? Next, for debugging: Could you list some raw values. i.e. values your PI reads from the ADC (in HEX)? \$\endgroup\$
    – sweber
    Commented Oct 21, 2015 at 13:56
  • \$\begingroup\$ I changed the schematic, sorry for the error. The code seems correct. I changed the code to use this sites.google.com/a/joekamphaus.net/… and still got the same results. Just reading without the voltage conversion I get 768, 192,384. Fluctuating up and down. \$\endgroup\$ Commented Oct 21, 2015 at 14:12

1 Answer 1

4
\$\begingroup\$

I don't have the reputation to post this a comment so I've had to 'answer'.

Is the ADC Vdd really connected as shown in the schematic? If so it doesn't have a current path from the power rail and so doesn't have power.

It looks as though C3 and C4 are intended to provide decoupling. Capacitors performing this function should be connected between the positive and negative supply rails directly (hopefully near to the IC that they are providing decoupling for).

The Vdd pin of U3 should be connected directly to the positive rail and not through C3 or C4.

Sorry if I've misread your schematic and gone off on a tangent, but it should really be a lot clearer than it is.

(While we're at it, is there a difference between the 'ground' connected to the negative supply of OA1 and the negative rail used in the rest of the circuit?)

\$\endgroup\$
3
  • \$\begingroup\$ No, the grounds are the same. How do I give the ADC the 'current path'? \$\endgroup\$ Commented Oct 21, 2015 at 17:38
  • \$\begingroup\$ @JamesDonnelly you have connected capacitors C3 and C4 in series to the Vdd pin of the ADC in the diagram. This may be a drawing issue, but if that is actually what you've done, then it will not work. The wire from the voltage supply needs to go directly to the VDD pin on the ADC, and the capacitors C3 and 4 go from VDD to VSS, to act as decoupling capacitors. \$\endgroup\$
    – KyranF
    Commented Oct 21, 2015 at 21:30
  • \$\begingroup\$ The schematic was wrong, but the setup was done correctly. So I'm very confused \$\endgroup\$ Commented Oct 21, 2015 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.