AtoD - first attempts


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default AtoD - first attempts

    Guys, I'm getting a little out of my depth and would like some feedback here.

    From my previous posts some of you (two Steves !) will remember that I'm playing with a 16F873 to come up with a better version of some disco lights based on an 16F628a. I'm now looking at hooking up the audio output from a CD player but I've never played with A - D conversion and not sure what I need to do. I've used the example varibles in the manual so I have

    Code:
    B0 VAR BYTE
    ADCIN 0, B0		' Read channel 0 to B0
    I want to use RA0/AN0 (pin 2) for the input, and I've used a win-scope to obtain the voltage levels that the CD player is kicking out (see attached). How do I go about calibrating the A-D so that I can display the values of B0 on port B relative to the music level ?

    EDIT:

    I tried the obvious:
    Code:
    ADCIN 0, B0		' Read channel 0 to B0
    Portb=B0
    RETURN
    However even with no music present the first 5 bits of Port B seem to display a random pattern, rather than just PB0 being lit. There is however a noticable change of state when a music signla present, I get more LEDs light up and it extends over the full port.. but it's not seqentially lighting them up like a VU meter.

    EDIT:
    Sorry should of added that I copied the settings form the manual too
    Code:
    DEFINE ADC_BITS 8	' Set number of bits in result
    DEFINE ADC_CLOCK 3	' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50	' Set sampling time in microseconds
    And have the following config:
    Code:
    ADCON1=$07
    CMCON = 7                               ' Digital inputs
    CCP1CON = 0                             ' PWM off
    TRISA=%11111111                         'set PORTA as all input
    Attached Images Attached Images  
    Last edited by malc-c; - 29th December 2006 at 14:04.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Guys, I'm getting a little out of my depth and would like some feedback here.

    From my previous posts some of you (two Steves !) will remember that I'm playing with a 16F873 to come up with a better version of some disco lights based on an 16F628a. I'm now looking at hooking up the audio output from a CD player but I've never played with A - D conversion and not sure what I need to do. I've used the example varibles in the manual so I have

    [/code]


    And it's probably not going to act like a VU meter. I've tried this before. I was semi-successful in 2 ways.

    The first way, I got around it by looking for and averaging the peaks of what I was sampling on the A/D port over X time. It's either that or you feed the audio in thru a diode into a capacitor across the A/D port with a small-ish resistor to ground (I wish I could do ASCII graphics). The audio 'charges' up the cap, the resistor discharges it slowly-ish (think R/C time constant), the diode keeps the cap from messing with the input signal and only let's positive voltage thru even though you do lose the .25v or .7v due to forward voltage drop (or you could use an opamp as a follower). Then you sample the A/D input.

    The 2nd method was using actual FFT routines on a PIC18F4620, 128 bands per channel updated at about 13hz. Ya baby! That was neat to look at on a 128x64 graphic LCD! But the FFT routines cost me some $$$. Check my site (www.srt.com/~jdgrotte) to see what came out at the PICAlyzer link.

    But just sampling the A/D of an audio input won't get you anywhere. It would be just like looking at audio on an o'scope. Doesn't look like anything useful...

  3. #3
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Yeah I 'spose when you think of it I would need to rectify the AC signal in some way so that there is something for the pic to read.

    I'll try the diode / capacitor thing and see what happens.. thanks for the input

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Yeah I 'spose when you think of it I would need to rectify the AC signal in some way so that there is something for the pic to read.

    I'll try the diode / capacitor thing and see what happens.. thanks for the input
    Oh it works pretty good, once you get the caps/resistors all set up to the right numbers. I don't remember the values that I used, but I do know I ended up buffering the input with an opamp before going into the diode. I've got a decent pdf of what I did around somewhere. If I find it, I'll link it.

  5. #5
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default furthering the idea.

    Hello Skimask / Malc-c,

    I also want to pursue this project and was wondering, what was the overall results of Malc-c project.

    In abscence of some design guidelines (Schematic) from Malc-c side towards the project, I would like to share my idea.
    1. I also wish to make a dancing light controller with musical input on a ADC port or a PIC 16F72 / 16F873A to make PORTB dance to the music. REALTIME
    2. I am also interested in digitizing the pattern of the music , so that it could be replayed without any music source. STORE/PLAY

    I would first like to work upon the REALTIME idea and then jump over to the STORE/PLAY version.

    Could anyone please guide me thru this.

    regards

    p.s. Wonder it this thread is still alive

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=malc-c;30210] Guys, I'm getting a little out of my depth and would like some feedback here.

    > I really thought you'd left it aside ... too bad !

    EDIT:

    I tried the obvious:
    Code:
    ADCIN 0, B0		' Read channel 0 to B0
    Portb=B0
    RETURN
    > What about Trying this

    Code:
    ADCIN 0, B0		' Read channel 0 to B0
    Portb= DCD B0
    RETURN
    > AND Using ONLY ADC Channel 0 as an input ...

    However even with no music present the first 5 bits of Port B seem to display a random pattern, rather than just PB0 being lit.

    > Did you think to place a pulldown resistor at the Channel 0 input ( I suspect a capacitive input coupling ...)


    by the way ... a scheme could be useful !!! ( as we're used to your designs ... )

    a Happy new year to you ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default A very happy new year !

    Nice to see the thread revive.

    Any inputs on the second idea. Storing the sample and playing it back. I wonder if its as simple as reading the analog input over a period of time and saving it in a eeprom and then just playing it back !

    regards

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Here is a very crude circuit that I made for a portable cassette player to make LED's "dance" with the music. I tapped off a low level audio signal in the preamp circuit. Maybe a WRITE command to eeprom during ADC readings would allow you to store it in a PIC with eeprom. I used an 8-pin 12F675.

    ANSEL = 0 'all inputs digital
    CMCON = 7 'comparators off
    DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device
    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
    TRISIO = %00000001
    GPIO = 0 'all outputs low
    X VAR BYTE


    START:
    ADCIN 0, X
    IF X > 2 Then High GPIO.4 : Pause 100 'on leds
    IF X < 2 Then Low GPIO.4 : Pause 5 'low leds
    GoTo START

  9. #9
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161


    Did you find this post helpful? Yes | No

    Default Is it a VU Meter or a Graphic EQ !

    thanks peterdeco,

    Yes i looked upon your code in the last thread, and its for a single led. But I want PORTB to dance to the music.

    I have a slight confusion in my mind, regarding the ADC Val that we sample. Does it mean that we are actually making a VU meter. How do we sample different frequencies ?

    No Clue.I

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by charudatt View Post
    thanks peterdeco,

    Yes i looked upon your code in the last thread, and its for a single led. But I want PORTB to dance to the music.

    I have a slight confusion in my mind, regarding the ADC Val that we sample. Does it mean that we are actually making a VU meter. How do we sample different frequencies ?

    No Clue.I
    You don't sample different frequencies with an ADC, at least not without banks of wide- or narrow- band filters. All you sample with an ADC is analog values.

    You can sample a segment of ADC values, do some complex math on it and get a spectrum display out of it (see Post #2), but it isn't easy, it's time/memory consuming with a PIC18F. There are a few graphic equalizer chips out there that'll split the audio into bands of frequencies which you could then sample individually, but again, it's not easy. I guess it depends on how many 'bands of frequencies' you're talking about...

Similar Threads

  1. Averaging AtoD samples
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 39
    Last Post: - 29th September 2011, 21:51
  2. 16F684 AtoD problem
    By hell_pk in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 20th February 2009, 06:59
  3. Atod Digital Filter
    By GeoJoe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd April 2008, 17:04
  4. 877A AtoD config problem?
    By ttease in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st April 2007, 16:57

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts