Music Input


Closed Thread
Results 1 to 22 of 22

Thread: Music Input

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

    Default Music Input

    Hi,

    I'm developing a disco light rig and need some advice. I want to connect the device to the line out from a CD player (typically 1v RMS peak to peak) via a lowpass filter that is then fed through a peak filter (CCt can be supplied if required) to pin RA2 of a 16F628a PIC

    As I already have switches on some PORT A so I only want to set AN2 (RA2) to analogue.

    Now I did try and use the POT comamnd, but realised that this wouldn't work as there is no real means of charging acapacitor, so I looked at the ADCIN command, and this is where my lack of experience shows. Here is the top section of my code

    Code:
    PORTA = 0 ' declare port level BEFORE port direction = safe power-on
    CMCON = 7 ' PortA Digital inputs
    DEFINE ADC_BITS 8
    CCP1CON = 0 ' PWM off
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    ADCIN 2, M
    As I was using switches on port A I had used CMCON = 7 to make all ports didgital, so how do I change this so that RA2 is analogue and the rest digital. I also assume that I have the correct syntax ADCIN 2, M to put the resulting value (0 - 255) into M? The idea then is to include a line that states if the value of M is above a threshold it will run to the step in the pattern, if its below it simply loops until M is above the threshold.

    I welcome your comments

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm. I did something similar a while back with a 12F675 and a portable radio. This program flashes several LED's with the beat of the music. Audio was taken from the audio feed to the volume control. The use of the ADC command automatically converts the port to analog.

    ANSEL = 0 'all inputs digital
    CMCON = 7 'comparators off
    DEFINE OSCCAL_1K 1 ' Set OSCCAL for 1K device to accurize osc
    @ DEVICE MCLR_OFF, INTRC_OSC, WDT_ON, BOD_ON, PWRT_ON, PROTECT_ON
    TRISIO = %11111111 ' all inputs for now
    'high & low commands convert to outputs
    X VAR BYTE 'adc variable

    START:
    ADCIN 0, X
    IF X > 2 Then High GPIO.2 'TURN ON LED'S ON GPIO.2
    IF X <=2 Then Low GPIO.2 'OFF LED'S
    GOTO START

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply,

    Sounds good (sorry no pun intended), I'll have a play and see what I can do.

    Cheers

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If and when you get ADCIN to work with a 16F628A, come back and tell us how you did it. That PIC hasn't got any ADC's...

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


    Did you find this post helpful? Yes | No

    Default

    Sorry I dow to your superior knowledge.. so what's an analogue comparator input then.. will it not do the same thing... ??

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


    Did you find this post helpful? Yes | No

    Cool Already cooked example

    Hi, Malc

    Some years ago, Elektor committed such a project with a 16F84 ... you could have a look to their input stage ...

    16F628 is a "bigger" '84 ...no ???

    Alain

    PS : Project 000107 ... note everything Downloadable ...
    Last edited by Acetronics2; - 21st June 2006 at 10:20.
    ************************************************** ***********************
    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
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for that, but me been a tight ass brit object to having to pay a quid to obtain access to the article... especially when the HEX and ASM are free !!

    I did come accross this project, which appears to use the filtered bass to trigger an NE555 to provide the logic pulse to trigger another NE555 which can run as an astable free runner or mono-stable triggered by the music.






    The actual chase generator is a 4017 decade counter. ( full project details http://sound.westhost.com/project62b.htm )

    I might just try this, however it seems a but of an overkill to use all those op-amps and an NE555 to provide the input into a PIC.... I'll keep googling and yahooing and see what turns up

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    An Analogue Comparator allows you to trip your input pin at different voltage levels determined by an internal or external reference. So, if you set your Reference voltage at say 500mV, you can trip the Comparators Output on or off at 500mV rather than the usual trip level for a Digital I/O pin.

    By sweeping the Comparators Reference Voltage, you can then use its input as a cheapo ADC. However, the internal Reference in the 16F628 only has two scales of 16 steps, and allowing for a settling time would not be very good for Audio input sampling.

    So, in reply to your query, an Analogue COMPARATOR does what it says... it COMPARES your input against a Reference. Whilst an Analogue to Digital CONVERTOR (ADC) will give you a snap-shot of your current Analogue input in Digital form. The two are NOT the same.

    The 16F628 has TWO COMPARATORS on-board and NO ADC's. ADCIN only functions with ADC's which is why it's named ADCIN (that what I love about microprocessors, they name everything so obviously!).

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c
    but me been a tight ass brit object to having to pay a quid to obtain access to the article... especially when the HEX and ASM are free !!
    Let's see how much you hope to save ( let's do the whole count for the project ) ... makes me laugh !!!

    mmmh, by the way ... have a look to Freescale MC 3340 P datasheet. An old Elektor ( once more, ... !!! ) summer issue show a really nice application

    You'll be more than happy : datasheet is free ...

    you fast draw, mmmmh ???

    Alain

    PS : 5or 8 £ for a pre-programmed basic PIC ( 675,628,84 ...) ... you're joking, I hope !!!
    Last edited by Acetronics2; - 21st June 2006 at 13:00.
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Melanie,

    Thanks for the explanation. I understand where my confusion came from now !

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


    Did you find this post helpful? Yes | No

    Default

    Ok I've looked at the PDF (http://www.ee.washington.edu/stores/...ear/mc3340.pdf) for that device, but how does an electronic volume control fit in with my bass extraction / filter thingy ???


    Quote Originally Posted by Acetronics
    PS : 5or 8 £ for a pre-programmed basic PIC ( 675,628,84 ...) ... you're joking, I hope !!!
    Whoops - thanks for pointing out the typo... should be £5 like the rest.. now corrected.

    And before you ask, that just covers the cost of the PIC and postage to me, then the cost of the post, packing and paypal charges when sending it out again !
    Last edited by malc-c; - 21st June 2006 at 14:36.

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    [QUOTE=malc-c]Ok I've looked at the PDF (http://www.ee.washington.edu/stores/...ear/mc3340.pdf) for that device, but how does an electronic volume control fit in with my bass extraction / filter thingy ???

    I just thought you had understood the presence of D1,D2,Q1,Q2 ... around U1A ...

    as for good films : do not make presume the end too early ...

    Alain

    PS: You buy your PICS from Radiospares ??? ... Who said Cr ...??? Ohhhhh.
    RePS: Elektor is the same price ...
    ************************************************** ***********************
    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 " !!!
    *****************************************

  13. #13
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Lightbulb Try Color Organ

    Hi Malcolm,

    A pre-disco name for "disco light" could be "color organ".

    I made a color organ in the early 1970's of the last century.

    It was great before the word kewl, or way cool, or even cool was used to describe "neat" things.

    There seems to be a lot of information on line about color organs. A search may turn up a lot of circuit ideas and schematics.

    For instance:
    http://www.tinaja.com/glib/muse108.pdf
    Describes a color organ as;
    Your speaker level input
    audio is somehow safety isolated and
    then lowpass, bandpass, or highpass
    filtered into (usually) three or more
    channels. Each channel’s output is
    then converted into some dc control
    voltage. That dc control voltage then
    modulates a "power amplifier" of
    some sort. Which in turn relates the
    amount of audio energy in the band
    to the brightness of one or more
    colored lights. For instance, the lows
    might be red, the mids green, and the
    highs blue. Or whatever"
    Now you may be interested, in a single channel "Bass" (lowpass), but the principle should be the same.

    PicBASIC should truly turn the simplistic color organ into a true disco light. But be careful to isolate your circuit from the power lines (mains). It is also good practice to isolate the circuit from the input device as well.

    This is a fun project and we hope you post where your journey takes you so we can all learn with you.

    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  14. #14
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Talking one more piece to the puzzle ...

    Hi,

    May I point out this little circuit from the far east...

    http://www.selectronic.fr/includes_s...ek/HT2040A.pdf

    ... really ... cool !!!

    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Pic_User
    I made a color organ in the early 1970's of the last century.
    God you make me feel old, I think the last century bit made me reach for my zimmerframe and I'm only mid 40's

    Thanks for the lead, I'll google colour (or color) organ and see what I get.

    No worries on the mains isolation. I use solid state relays that have built in opto isolation. Its a lot safer and easier than messing about with triacs and thryistors like the good old days... I built my first sound to light in '77 consisting of a three way passive crossover, three mains to 6v ac transformers (using the secondry as the primary on the audio) and three 206 thyristors... never really thought about the amp become live at mains potential !!!!

    I'll keep you guys posted of any development I get, and hopefully Melanie may let me post the final project and schematic in the respective forums when its completed.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics
    Hi,

    May I point out this little circuit from the far east...

    http://www.selectronic.fr/includes_s...ek/HT2040A.pdf

    ... really ... cool !!!

    Alain
    Thats wicked ! .... nice find

  17. #17
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Smile zimmerframe

    Quote Originally Posted by Malcolm
    God you make me feel old, I think the last century bit made me reach for my zimmerframe and I'm only mid 40's
    Ha, I had to Google "zimmerframe", we have them in this country, just different names... Made me smile...
    http://www.thefreedictionary.com/Zimmer+frame


    Alain
    What a great find. The HT2040A IS a disco light. (they might think it is for Christmas lights, but we know better.) All in one part.


    Side Notes:
    One of the interesting things, about the artistic mode of visual music, is sloppier is better!

    Normally, the goal is to sharpen filters. Make the "cut-off", at band edges, as sharp as possible, without causing "ringing" or other ill effects. However, with "music changed into light", it is better to have overlapping filters, to cause a blending of the lights. Much more interesting patterns, come about, when the band edges overlap.

    Very simple L-C or even R-C passive filters are not only adequate, but even desirable

    "A Project Too Far."
    What might be interesting:
    Have mirrors mounted on some type of PIC controllable devices. This could be stepper motors, syncros, voice coils, linear motors etc..
    The front panel could be some type of translucent, diffusing rear projection screen. Maybe, something as simple as a "suspended ceiling" florescent light diffusion lens.
    The light would be modulated as in a standard colour (color) organ.
    But, the mechanical device would move the modulated colours around by volume (loudness). Who knows, maybe higher on the panel could represent louder musical notes.
    It seems like this might add a third dimension to the mix. ?

    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  18. #18
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink The last ... but not least

    Hi,Malc

    I've another lightshow including a Basic stamp interpreter chip ( In easy words : PicBasic compatible ... but some timings, may be, are to be corrected )

    From Electronique Pratique june 2000 issue ... Here, all is done by soft ( no "miracle" filter to cut and paste ... )

    Alain
    Attached Files Attached Files
    ************************************************** ***********************
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Thanks

    I do get the feeling that I'm re-inventing the wheel... but then again, its all good learning experience

  20. #20
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c
    Thanks

    I do get the feeling that I'm re-inventing the wheel... )
    You took some time to understand it ... but youth must pass !!!

    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default Ok more confusion

    Now the fact that we all went out to a party last night and I'm still getting over a hangover might have something to do with this...

    Whilst this might be re-inventing the wheel, I'm still having fun at trying to get this working, but I'm having problems... I've managed (with some help from guys on an electronics forum) to come up with a low pass filter cct that goes high (5v) in time with the beat. The idea is to feed this pulse into the PIC so that whilst the pin is high the code continues to run through the sequence, and when its low it stops at what ever position it is in the sequence. Here is the modified code, which compiles but when I tie RA2 high the pattern doesn't advance at all.

    Code:
    ;************ set up PIC *****************
    PORTA = 0 ' declare port level BEFORE port direction = safe power-on
    CMCON = 7 ' PortA Digital inputs
    CCP1CON = 0 ' PWM off
    VRCON = 0        ' Voltage reference disabled
    OPTION_REG.7 =    0
    
    
    TRISA=%11100111        'set PORTA as all input apart from A3 & A4
    TRISB=%00000000        'set PORTB as all output
    
    @RC_OSC_NOCLKOUT 
    @WDT_ON
    @PWRT_ON
    @MCLR_OFF
    @BOD_ON
    @LVP_OFF
    @CPD_OFF
    @PROTECT_OFF
    
    ;************* set up pattern data **********
        
    Patt1 DATA 16,1,2,4,8,16,32,64,128,128,64,32,16,8,4,2,1 
    Patt2 DATA 8,129,66,36,24,24,36,66,129 
    Patt3 DATA 16,1,3,2,6,4,12,8,24,16,48,32,96,64,192,128,0 
    Patt4 DATA 16,1,128,2,64,4,32,8,16,8,32,4,64,2,128,1,0 
    Patt5 DATA 12,24,60,126,255,231,195,129,0,129,195,231,255 
    Patt6 DATA 13,1,2,4,8,17,34,68,136,16,32,64,128,0 
    Patt7 DATA 8,128,64,32,16,8,4,2,1
    
    ;************* set up varibles ************
        
    i var byte                          ;used for for next loops
    M var byte                          
    D var byte                          ;used to store the result of the pot on port A1
    scale var byte                      ;used in the POT command
    Scale = 254                         ;used to set range 
    SW1 var PORTA.6                     ;up switch 
    SW2 var PORTA.0                     ;down switch
    mus var PORTA.2                     ;pin for music input
    SWcount var byte                    ;used as a place holder for patterns selwction
    swcount=1                           ;set place holder to default to pattern 1
    steps VAR BYTE                      ;used to store the number of steps in the pattern sequence
    counts VAR BYTE                     ;used in the FOR NEXT loop to run through the sequence
                                                                
    ;************* main program ****************
    
    Main:
    Pot PORTA.1,scale,D                 ;used to read value from 10k pot
    if sw1=0 then swcount=swcount+1     ;check to see if up button pressed, if so add 1 to SWcount
    if sw2=0 then swcount=swcount-1     ;check to see if down button pressed if so delete 1 to SWcount
    pause 60                            ;debounce delay
    If swcount>7 then swcount=7         ;error trap for exceeding max patterns
    If SWcount<0 then swcount=0         ;error trap for exceeding min patterns
    IF swcount = 0 then all:
    
    
    TRISB = 0                           
    gosub sel1                          ;go to subroutine to select pattern
    counts = 1                          ;set position marker
    gosub sel2                          ;go to subroutine to advance through sequence
    PAUSE D                             ;pause period set by varible D
    If mus = 1 then counts = counts + 1 ;check to see if music trigger is present and if so advance position by 1
    If counts > steps then counts =1    ;check to see if at the end of sequence
    goto main:                          ;go back to the main program and run again
    
    ;************* Subroutines *****************
    Sel1:
    if swcount = 1 then read Patt1, steps
    if swcount = 2 then read Patt2, steps
    If swcount = 3 then read Patt3, steps
    if swcount = 4 then read Patt4, steps
    if swcount = 5 then read Patt5, steps
    If swcount = 6 then read Patt6, steps
    If swcount = 7 then Read patt7, steps
    return
    
    Sel2:
    if swcount = 1 then READ (Patt1+counts), PORTB 
    if swcount = 2 then READ (Patt2+counts), PORTB
    if swcount = 3 then READ (Patt3+counts), PORTB
    if swcount = 4 then READ (Patt4+counts), PORTB
    if swcount = 5 then READ (Patt5+counts), PORTB
    if swcount = 6 then READ (Patt6+counts), PORTB
    if swcount = 7 then READ (Patt7+counts), PORTB
    RETURN
    I also tried modifying the previous arrangement using the for next loop

    Code:
    TRISB = 0                           
    gosub sel1                          ;go to subroutine to select pattern
    FOR counts = 1 TO steps             ;advance to through the entries
    gosub sel2                          ;go to subroutine to advance through sequence
    PAUSE D                             ;pause period set by varible D
    if mus = 1 then
    NEXT counts                         ;advance through loop to next position
    end if                       
    goto main:                          ;go back to the main program and run again
    My logic was that if mus (ie pin RA2) is high then continue the for next loop, but no matter how I phrase the section I get syntax errors (nested next without matching for, etc)

    Anyone have any ideas ?

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


    Did you find this post helpful? Yes | No

    Default

    well several cups of coffee later I have something that works.. to a fashion. The only thing with the code at the moment is that it seems to randomly revert back to the default pattern 1, so something is causing SWcount to loose / reset. I'm assuming that the audio filter is causing interfearance, even though the PIN on the PIC is tied low via a 10K resistor.

    Anyway, here is the main section of the code:
    Code:
    ;************* main program ****************
    counts = 0
    
    Main:
    Pot PORTA.1,scale,D                 ;used to read value from 10k pot
    if sw1=0 then swcount=swcount+1     ;check to see if up button pressed, if so add 1 to SWcount
    if sw2=0 then goto music     ;check to see if down button pressed and if so go to music
    pause 60                            ;debounce delay
    If swcount>7 then swcount=1         ;error trap for exceeding max patterns
                               
    gosub sel1                          ;go to subroutine to select pattern
    FOR counts = 1 TO steps             ;advance to through the entries
    gosub sel2                          ;go to subroutine to advance through sequence
    PAUSE D                             ;pause period set by varible D
    NEXT counts                       ;advance through loop to next position                    
    goto main:                          ;go back to the main program and run again
    
    
    music:
    Pot PORTA.1,scale,D                 ;used to read value from 10k pot
    if sw1=0 then swcount=swcount+1     ;cycles through the patterns by adding 1 to SWcount
    if sw2=0 then goto main             ;check to see if down button pressed and if so go to main
    pause 60                            ;debounce delay
    If swcount>7 then swcount=1         ;error trap for exceeding max patterns
    
    
                               
    gosub sel1
    If mus = 1 then counts = counts + 1 ;if bass or beat present move to the next step in pattern 
    gosub sel2                          ;go to subroutine to display pattern in current step
    PAUSE D                             ;pause period set by varible D
    If counts = steps then counts = 0   ;if counts then reset counts to 1
    goto music:                          ;go back to the main program and run again
    
    ;************* Subroutines *****************
    Sel1:
    if swcount = 1 then read Patt1, steps
    if swcount = 2 then read Patt2, steps
    If swcount = 3 then read Patt3, steps
    if swcount = 4 then read Patt4, steps
    if swcount = 5 then read Patt5, steps
    If swcount = 6 then read Patt6, steps
    If swcount = 7 then Read patt7, steps
    return
    
    Sel2:
    if swcount = 1 then READ (Patt1+counts), PORTB 
    if swcount = 2 then READ (Patt2+counts), PORTB
    if swcount = 3 then READ (Patt3+counts), PORTB
    if swcount = 4 then READ (Patt4+counts), PORTB
    if swcount = 5 then READ (Patt5+counts), PORTB
    if swcount = 6 then READ (Patt6+counts), PORTB
    if swcount = 7 then READ (Patt7+counts), PORTB
    RETURN

Similar Threads

  1. Sony LanC Program
    By l_gaminde in forum Code Examples
    Replies: 2
    Last Post: - 25th September 2009, 18:51
  2. floating A/D input
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th April 2009, 13:21
  3. LED "capacitance" won't get lower
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 3rd May 2007, 20:31
  4. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  5. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19

Members who have read this thread : 1

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