AtoD - first attempts


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    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

  2. #2
    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...

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


    Did you find this post helpful? Yes | No

    Default

    dupliaceted post due to login errors / time out !
    Last edited by malc-c; - 23rd January 2008 at 19:14. Reason: problems with login caused duplicate

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


    Did you find this post helpful? Yes | No

    Default

    Struth - was it that long ago when I was messing about with this project !

    Basically I ended up using a low pass filter to trigger an NE555 in mono stable mode. Its output was then fed to the PIC which ran the pre-set pattern at what ever speed the "gate" was set to. This video shows one of the first versions which used op-ams in the filter

    http://www.micro-heli.co.uk/discolights2.avi

    This then evolved into this,



    which used a simplified (but now looking at the two videos, less responsive) filtering, as can be seen in the video below

    http://www.micro-heli.co.uk/lmv.avi

    As far as I can tell this is the code for the PIC using the schematic above (I've had to dig it out of an archive backup so can't be 100% sure its the final version)

    Code:
    '****************************************************************
    '*  Name    : Lightmaster V                                     *
    '*  Author  : M.Crabbe                                          *
    '*  Notice  : Copyright (c) 2007 M. Crabbe                      *
    '*          : All Rights Reserved                               *
    '*  Date    : 01/01/2007                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    
    
    ;*************** Set up LCD *****************
    
    DEFINE LCD_DREG PORTC                           ' LCD data port 
    DEFINE LCD_DBIT 0                               ' LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTC                          ' LCD register select port 
    DEFINE LCD_RSBIT 4                              ' LCD register select bit 
    DEFINE LCD_EREG PORTC                           ' LCD enable port 
    DEFINE LCD_EBIT 5                               ' LCD enable bit 
    DEFINE LCD_BITS 4                               ' LCD bus size 4 or 8 
    DEFINE LCD_LINES 2                              ' Number lines on LCD 
    DEFINE LCD_COMMANDUS 2000                       ' Command delay time in us 
    DEFINE LCD_DATAUS 50                            ' Data delay time in us
    
    ;************* 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 PIC ********************
    
    ADCON1=$07                                      ' PORTA all disgital
    CMCON = 7                                       ' Digital inputs
    CCP1CON = 0                                     ' PWM off
    TRISA=%11111111                                 ' set PORTA as all input 
    TRISB=%00000000                                 ' set PORTB as all output
    TRISC=%00000000                                 ' set PORTC as all output
    PORTB=0
    audio var PORTA.0                               ;input from beat filter (+5v)
    option var PORTA.2                              ;music or chase option select
    sequence var PORTA.3                            ;pattern selection
    
    ;************* set up variables ***************
    
    Patt    var byte [8]                            ;used to store the sequences
    Patt[1]=Patt1
    Patt[2]=Patt2
    Patt[3]=Patt3
    Patt[4]=Patt4
    Patt[5]=Patt5
    Patt[6]=Patt6
    Patt[7]=Patt7
    
    C var byte                                      ;used to advance through pattern
    D var byte                                      ;used for the speed the sequence runs at
    scale var byte                                  ;used in the POT command
    Scale = 10                                     ;used to provide ragge with pot command
    steps var byte                                  ;used for storing the number of steps in a sequence
    swcount var byte                                ;used to select the required sequence required
    swcount=1                                       ;set default sequence at start
    sel var byte                                    ;used to select music or chase
    sel=1                                           ;used to select mode 
    
    ;**************** main program ********************
    main:
    
    Pot PORTA.4,scale,D                             ;used to read value from 10k pot and set the speed
    gosub pattern                                   ;jump out to select pattern sequence
    LCDOUT $FE,$C0, "Chase Speed " ,#D	            'show decimal value of D for speed of chase
    if PORTA.2=0 then goto music                    ;if Pin A2 is low goto music
    pause 60                                        ;debounce delay
    read patt[swcount],steps                        ;read the first value of the selected patter and place it in the variable steps
    for C = 1 to steps                              ;for / next loop
    READ PATT[SWCOUNT]+ C,PORTB                     ;reads the step value for selected pattern and send it to PORTB 
    PAUSE D                                         ;delay for speed
    NEXT                                            ;advance through pattern
    goto main:                                      ;go to start of main program
    
    music:                  
    gosub pattern                                   ;jump to pattern sequence selection
    LCDOUT $FE,$C0, "Music - selected "  	        ;show that music has been selecterd
    read patt[swcount],steps                        ;read the first value of the selected patter and place it in the variable steps
    READ PATT[SWCOUNT]+ C,PORTB                     ;reads the step value for selected pattern and send it to PORTB 
    If audio=1 then C=C+1                           ;if pin is high a beat is present, so advance pattern
    If C=steps then C=1                             ;check to see if end of the patetrn is reached
    if PORTA.2 = 0 then goto main                   ;if A2 is low then goto main
    pause 20                                        ;debounce pause
    goto music:                                     ;go back to music and start again
    
    ;*********** subs **************
    
    pattern:
    if sequence=0 then swcount=swcount+1            ;check to see if cycle button pressed, if so add 1 to SWcount
    pause 40                                        ;debounce delay
    If swcount>7 then swcount=1                     ;error trap for exceeding max patterns                      
    if swcount=1 then LCDOUT $FE, 1, "Pattern 1"    'Clear display and show sequence number
    if swcount=2 then LCDOUT $FE, 1, "Pattern 2"
    if swcount=3 then LCDOUT $FE, 1, "Pattern 3"
    if swcount=4 then LCDOUT $FE, 1, "Pattern 4"
    if swcount=5 then LCDOUT $FE, 1, "Pattern 5"
    if swcount=6 then LCDOUT $FE, 1, "Pattern 6"
    if swcount=7 then LCDOUT $FE, 1, "Pattern 7"
    return
    Hope this helps

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