Best way to amplify an audio signal for PIC use

Discussion in 'Embedded Systems and Microcontrollers' started by Vaughanabe13, May 6, 2009.

  1. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    Hello,

    I am building a guitar tuner using a PIC18F452. My tuning algorithm works great, and can accurately tune notes when the input is a sine (or square) wave from a generator. The input wave needs to swing high enough so that the PIC can recognize it as logic level 1 on an input pin, and it also needs to swing low enough that the PIC can recognize logic level 0. Essentially I am implementing a Schmitt trigger in software and using TMR0 to count the time for one period and use a look-up table to compare to known values for notes.

    Now the problem becomes, how do I actually get an audio signal from an instrument, say an electric guitar's pickup output, into the PIC and amplify the signal enough so the PIC will recognize logic levels? When I connect the pickup output from my guitar to a scope, the pk-pk is only about 50mV. What can I use to jack up the gain, keeping in mind that I don't care about distortion, clipping, or degradation of signal quality? All I need is to turn the guitar output into a sine/square wave that has a high enough amplitude for the PIC to read logic 1 and 0. At that point my algorithm will kick in and be able to measure the frequency.

    Any ideas? I have been toying with rail-rail op-amps, NPN common emitter amplifiers, etc, but no luck so far. I am running off a +5V power supply.

    Thanks, responses are very much appreciated! Let me know if more information is needed.
     
  2. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
  3. XtremeelectroniX

    New Member

    Nov 6, 2008
    6
    0
    I see what you are trying to do!
    Well if you are not worried whether the input to the PIC is a SINE wave or a square wave then you could use a very simple OP-AMP circuit.
    Any op-amp would do. I dont know how to put a circuit up on this. If you know how I can draw it in 2 secs...
    What is the Part no on the OP-AMP you are using?
     
  4. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    I picked up a rail-rail op amp (since I am dealing with a single source power supply) this morning. It's the Analog Devices AD623, and here is the data sheet:

    http://www.analog.com/static/imported-files/data_sheets/AD623.pdf

    The computer terminal I am working on does not have a circuit simulation program to wire up a schematic, so I have attached a quick drawing of how I wired it.

    [​IMG]


    I'm currently getting nothing on the output, and I have no clue what is wrong with it. Any ideas?
     
  5. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    *Update*

    I tried cranking up the input waveform and I get 0V output from the op-amp until the pk-pk of the waveform hits about 1.45V. Then it amplifies as it should and boosts the output close to the power source, around 4.5V. This doesn't help me because I need to boost a very low signal. How can I fix this?
     
  6. DonQ

    Active Member

    May 6, 2009
    320
    11
    The in- pin has no reference voltage so it is probably drifting to some voltage other than what you would think. Try just putting a large value resistor (like a 1 MΩ) between the in+ and in-. This will reference it at the same voltage that's provided by the voltage divider. It will probably work much better that way.
     
  7. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    I'd also connect the REF pin to the 2.5V. You can reduce the gain down also to 20.
     
  8. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    Thanks for the suggestions. I decided to throw out that circuit in favor of an inverting op amp running from +- 5V, because I had to do a proof of concept demo today. However, I still want to get that circuit working so I will take your suggestions and see what I can get.

    In the meantime, here is my proof-of-concept guitar tuner, where the middle board is the op amp circuit, the right board is mostly just for the 7 segment display, and the left board is my PIC development board. You may notice a bunch of diodes on the op amp output. This was a quick-fix signal clipper that I made from available diodes, but I'll redesign that later. I will eventually implement all of this in a single board but for now it works.

    The tuner is accurate to about +-5 cents, and the error is due to integer rounding.

    [​IMG]
     
  9. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    You can download LTSpice (SwitcherCAD) from http://www.linear.com/designtools/software/ for a nice free simulation and schematic drawing software

    The AD623 is an instrument amplifier so it needs a path to ground on each input and you are capacitively coupling the signal... that is why DonQ recommended a resistor to the reference voltage.
     
Loading...