1. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    I am wondering what the ADC pins on the chip can do.

    Can I like hook a microphone up to those pins and record analog voice as binary data.

    Could I use these to send analog signals?

    I am just curious what they do. Since I mainly have been programming the chip to send pluses of current to flash a LED , or displaying AScii to a small LCD screen...etc

    Wondering if I could do analog stuff with it like recording voice clips or sending analog sine waves???

    Anybody know?
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    By the time you sample the audio and massage the data, you will find that the bandwidth that you can reproduce will be on the order of a few thousand Hertz.

    hgmjr
     
  3. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    So for the AVR chips what is the analog pins typically used for?

    Obviously I can buy ADC and DAC chips to do this before I send the data to and from the avr chips.

    But I am just curious why they provided them?

    Also with this chips is their anyway to detect a certain input voltage.
    Like say I input a voltage of 2 volts on pin 9 and then input a voltage of 3 volts. Is their anyway that the avr chip can determine the different voltages and act on a certain one.

    Like say I wanted when it is supplied with 3 > volts on pin 5 to turn on a light but when < 3 volts on pin 5 send current out pin 6.

    Is this possible.

    Because right now I can only send pulses of current at many different rates in/out pins at different times ,...etc.

    Their must be more to avr programming then sending pulses of current down a pin at a certain time? Maybe not?
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    The ADC in the AVR is provided to among other things provide a means of converting the output of an analog sensor to digital values. Once in digital form the information can be either displayed on LCD or LED display. It can also be stored in memory for the purpose of logging the values output by the sensor over a span of time. One example is temperature logger circuit.

    hgmjr
     
  5. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    So if I hooked a mic up to the pin could I record a audio clip.
    I am a little confused with what analog signal gets converted into what digital value ?
    Is their a standard for analog voice to binary voice? ( what would the binary value for any analog A sharp be ? 0 - 256 binary values?)

    Also if the mic is going to be to faster for the pin to sample the voice.
    Then other then a temperature logger circuit. What is it's use?

    Also is their any way to make sine waves and triangle waves instead of square waves out a pin on the avr?

    Maybe using some capacitors or something?
     
  6. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I would think that the use of the AVR and its ADC would not be the best of fits. Usually audio sampling and manipulation is better ackled with a Digital Signal Processor (DSP).
    There are standards for audio conversion and plyback. MP3 being chief among them.
    Any analog signal containing frequency components of a few KiloHertz or less would be a candidate. You could sample the 60 Hertz of a mains AC signal to use in triggering a Triac.
    This is the place where a Digital-to-analog convertor would be used. You can also use a less rigorous method and put together your on R2R ladder resistor network.

    hgmjr
     
  7. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    MP3 is just a compression format just like microsofts WMA.
    What I was getting at is their a standard binary value for a certain height of a given sine wave.

    Like 0 is when the sine wave is at horizontal x -axis , 1/4 the amplitude of the sine wave is the value 256/4 = 64 binary ,...etc.

    Else how would you convert the sine wave into binary data. The sampling of the different heights must have standard values or else how would you determine what the binary number 64 corosponded 1/4 the amplitude of the sine wave.

    Maybe I am lost but I don't get it fully certain height on the wave have to corospond to certain fix binary values. And without a standard you would hear different sound on different computers sound cards when you
    cat song > dev/dsp on linux...etc


    You can also use a less rigorous method and put together your on R2R ladder resistor network.

    ANY simple diagrams for a sine wave using the avr chip.
     
  8. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    I was told that I can do it with PWM and resistors/capacitors.

    I can code it to vary the frequency of the square way's in anyway using the delay.h functions.

    But I am still looking for a way to figure out how I have to vary the PWM to get the desired shape.

    Plus I don't know what capacitor/resistors to use.

    Over at avrfreak they seem to say just put a resistor and a capacitor in series on the desired pin and use PWM.

    Maybe you have more info.

    They said you can get any desired shape in theory from doing this.
     
  9. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    PWM together with a low pass filter made up of a resistor and a capacitor is a viable way to synthesize an analog signal.

    You could digitize an incoming analog signal using the AVR's ADC and then use the PWM approach to turn it back into an analog signal. I think the AVR's fast PWM would serve nicely.

    The datasheet for the atmega32 decribes how to program the PWM function in detail.

    hgmjr
     
  10. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    There is no standard value for a given point on an incoming sinewave. Typical ADCs come in a range of accuracies such as 8-bit, 10-bit, 12-bit and 16-bit. Another variable is the maximum voltage that the ADC can accept.
    Since ADC's generally operate on analog signals that are positive with respect to ground, if the incoming signal swings above and below ground then the signal will need to be given a positive offset to make it compatible with the ADC's input.
    An R2R resistor ladder network is a way to convert an n-bit digital value into a specific analog voltage. You can google R2R network to find some examples of this digital-to-analog technique.

    Have a look at this datasheet on an R2R IC. Keep in mind that you can build your own R2R network out of discrete resistors. The downside of rolling your own is that the resistors will not be matched as closely as in the IC.

    hgmjr
     
  11. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    R2R ladder looks like it is just resistors between each pin to make a voltage drop so that each pin final output produces a different output voltage.

    But where is the capacitors do you not need these?

    I would think if I used 8 pins of the avr to create a R2R ladder I would have 8 different voltages. But varying between them will still produce different tiny square waves at different heights. So if you look closely at the wave it's going to be a combo of tiny square waves. I am wondering how you would make them more smooth.

    Or maybe the best you can do is just vary the frequency faster between the 8 pins? But I would think this would change the frequency of the wave overall. The only way I see is to have much more pins this would make the digital/analog wave more fine looking (like a analog wave) .

    Just as in calculus lim --> 0 of square width leads to integration
     
  12. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    The R2R approach and the PWM with low-pass filter are two distinctly different approaches to accomplishing the D-to-A conversion.

    hgmjr
     
  13. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    R2R ladder you just send a pulse out the first pin then the second , ... last pin..etc. And circulate it like if I was doing an 8 bit R2R ladder.

    I would send pulses of current like to pin 1 ,2, 3, 4, 5,6,7 ,8 ,1 ,2 ,3 ,4 ,...
    etc so cycling between the 8 pins over and over again indefinitely.

    And the R2R ladder would be their just to provided different voltages for each pins output. But all the individual pins would still be outputing a square wave of different fix voltage. So it would still look like a jagged sine wave?

    I would think the only way to make the tops of the square waves not show in the sine wave so much is use more pins like a 10 ,12, 14, 16 bit R2R ladder. But I am not willing to use more then 8 pins for the R2R ladder so is their some other way to smooth the tops of the sine waves without changing the frequency of the sine wave? <--using the R2R ladder method
     
  14. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    It sounds like the PWM approach should optimally serve you application.

    hgmjr
     
  15. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    PWM with the 8 bit R2R ladder is that what you mean?

    So when I cycle thur the 1 ,2 ,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,..etc
    At a equal rate for all pins where does the PWM come in?

    PWM would be varying the frequency of the square waves from each pin. (i.e when I turn on pin 1 then turn it off , turn pin 2 on then turn it off , ... cycling thru etc ) <-- but I don't see how changing frequency will help
    Do you want me to turn them on and off at different rates.

    I don't get where the PWM comes into the R2R ladder.
     
  16. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You will not need the R2R at all. You will only need to use the PWM output alone. You will then add the RC integrator (low-pass filter) to the PWM output.

    hgmjr
     
  17. Mathematics!

    Thread Starter Senior Member

    Jul 21, 2008
    1,022
    4
    So do you mean use this type of circuit with the PWM

    http://en.wikipedia.org/wiki/File:1st_Order_Lowpass_Filter_RC.svg

    If is I have a few questions first what size capacitor (does it matter)
    what size resistor ( does it matter and why?)

    Also looking at the picture the upper input hole goes to my pin I am doing PWM out of but what do I connect the lower input and output holes to. <-- I am assuming the lower input and output hole goes to ground on my board.

    I know the last question hear is sort of a stupid question.

    So you are really suggesting not to use R2R ladder and just use PWM and a low pass filter. Ah , I kind of was getting the impression in the earlier post you wanted me to do the R2R ladder over the low pass. But whatever. I am curious about the low pass questions.
     
  18. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Here is a link in the wikipedia site that provides more details regarding a first-order low-pass made from a resistor and a capacitor.

    The choice of resistor and capacitor are dictated by the frequency range of your sinewave output.

    You will probably need to add an opamp buffer between the output of the low-pass filter and whatever you plan to drive with your output signal.

    I was initially leaning toward an R2R network but I think you will benefit from becoming more familiiar with programming the PWM of the ATMEGA32.

    What is the frequency range of your input analog signal and how are you planning on using the output analog signal?

    hgmjr
     
    Last edited: May 16, 2009
  19. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Ordinary AVRs or PICs are not able to sample an audio signal because their sampling rate is less than 500 kHz. To sample an audio signal and have a reasonable quality you need at least a 1MHz sampling frequency. This is available on DSP microcontrollers only. What is more, you will need an external EEPROM to store all this samples because the DSP won't have adequate memory itself.
     
  20. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Mathematics,

    You can see that mik3 has reinforced what I mentioned very early in this thread. AVRs can only faithfully reproduce signals in the low kilohertz range. If you have visions of reproducing analog signals of higher frequencies than this you are going to need a lot more horsepower than an AVR can provide.

    hgmjr
     
Loading...