PIC16F690 as a sound syntesizer

Discussion in 'General Electronics Chat' started by chaos51, Jun 18, 2011.

  1. chaos51

    Thread Starter Member

    Jun 18, 2011
    39
    1
    Hi,

    I am having problems with a seemingly very simple problem.
    I have programmed a pic, to output audio, encoding it on 4 digital outputs, and using a resistor ladder to convert a digital signal to an analogue signal.
    The I am putting the sound through a capacitor, as the PIC chip can only create positive voltages, and I want the signal to be AC.

    I get decent sounds, and am pretty happy with that. To create some more volume, I used the LM386 amplifier. This also works pretty well.

    Now to the problem. I am also outputting additional volume information on the wave, using a resistor ladder, I create a volume control signal is between 0 and 5 volts.

    Now the problem is using this voltage to control the volume of the output.
    I thought I just run the signal through a transistor, and control the transistor with this value. However whatever I tried, the transistors I am using either seem to be open, or closed, I cannot seem to use it as a sound volume
    controller. I tried before the amplifier, after, and instead. It's not getting me anywhere.

    So I am basically looking for tips, transistor recommendations (Which is better for this application MOSFET or regular transistor?), or perhaps links to how to use a dc signal to control volume of an audio signal.

    Any help appreciated.
    Thanks and regards
    DaC
     
  2. #12

    Expert

    Nov 30, 2010
    16,338
    6,824
    OTA means operational transconductance amplifier.

    They use a current signal as a gain multiplier.

    Look one up in a vendors site and read the datasheet. It's a bit of a mindf**k if you're used to the usual op-amps.
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,648
    2,348
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    Or just get a digital potentiometer. They come in a ton of variations indluding resistance (LDO), single or dual or up to 6, different control interfaces such as SPI, I2C, up/down and more.
     
  5. #12

    Expert

    Nov 30, 2010
    16,338
    6,824
    Figures 24 and 25 show how to make a voltage controlled amplifier with an operational transconductance amplifier.
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    If you don't need a great range or perfect linearity you can use a FET. They are a variable resistance that varies in response to gate voltage. You put the NFET in the bottom of a voltage divider.
     
  7. chaos51

    Thread Starter Member

    Jun 18, 2011
    39
    1
    Hi all,

    Thanks for the solutions proposed.

    Ok, right now I am biased towards the MOSFET, as it's the simplest thing, allthough probably it has low accuracy, I think it might be enough for my little pet project.

    I just need reasonable accuracy. A sinusform needs to be a sinus, and not a square wave. However if it's a little deformed that's ok, it output through a small speaker, which will deform it a bit anyway.

    As I said, I like the MOSFET idea most just now, as it's pretty easy to understand. What puzzles me a litle is why I cannot do the same thing with a transistor, that you can do with a MOSFET.

    I know that transistors are current devices, and MOSFETS are voltage devices. but putting appropriate restistors in the circuit, should convert your voltage to the appropriate current, correct? So I am doing something obviously wrong there. I think I am probably working in the wrong range or something.

    Ok, next then, which signal should be going to the GATE? Logically the "volume" signal, but I suppose it can also be the actual audio signal, and making the volume signal drive the drain. Or is there some logical reason not to do this?

    I also like the digital potmeter. However my PIC chip is allready occupied 99% with creating the audio signal, and adding another layer of communication in it, will break the accuracy I have right now in creating the audio signal.

    -DaC
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    The FET requires some way of putting a variable DC voltage on the gate, not the signal. Typically you need a PWM to get this but I bet yours is busy doing the audio.

    The pot could use an UP/DOWN control that just needs a few pulses to set the volume once.
     
  9. chaos51

    Thread Starter Member

    Jun 18, 2011
    39
    1
    Sorry, I forgot to mention, the signal, directly from the PIC is variable AC, it only gets to be DC after I run it through a capacitor.

    I don't wan't to use PWM, as many have allready done that I have seen in forums. Because of that I was curious how to do it without PWM, which led to this little project.

    So, I got two variable DC signals to play with, one is the signal, before it goes through the capacitor (0-5v). And the second is the volume signal, which is a voltage between (0-5v).
    To call the volume, perhaps is a bit misleading, as it is not a static value, that can be set manually, as the volume usually is. But it is a dynamic value, that gets set, based on the fraction of the sound the chip is producing. (Attack; Sustain; Decay)


    The "dc-signal", is variable on a much higher frequency then the volume signal, as it creates the actual sound waves (a few KHz). And the volume is variable somewhere in the 6-600Hz frequency range.

    Which should be going to the gate? Does the frequency matter?
     
    Last edited: Jun 20, 2011
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    OK, then it sounds like you are doing an old school traditional style synthesiser, one output is basically "frequency" information, and the other volume is an "envelope."

    That's going to need a true as voltage controlled amp (VCA) as bertus or #12 suggested. Trying to use a FET for that will lead to madness.

    Madness?

    THIS IS SPARTA !!!
     
  11. chaos51

    Thread Starter Member

    Jun 18, 2011
    39
    1
    Ok, thanks,

    But now you got me interested even more why a FET would not work, why would the FET lead to "MADNESS"?
    Is it not quick enough, is it not linear enough, is it a thresshold that making thinks "MAD", or is it just a combination of things?
     
  12. #12

    Expert

    Nov 30, 2010
    16,338
    6,824
    Please don't waste your time chasing silliness. Start studying the ways to do a VCA and let us be a little silly when we want to.
     
  13. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    So the Spartans didn't use FETs?? :eek:

    Silly or not using a FET for the VCA is about as "Spartan" as it gets... ;)

    But you are right for a good envelope amp a much more linear VCA would be a better choice.
     
Loading...