DCD command - need some advice


Closed Thread
Results 1 to 21 of 21

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Here is the complete code (less the data for light patterns)
    Code:
    ;************* set up PIC ********************
    
    ADCON1=$0F
    CMCON = 7                               ' Digital inputs
    CCP1CON = 0                             ' PWM off
    TRISA=%11111111                         'set PORTA as all input 
    TRISB=%00000000                         'set PORTB as all output
    PORTB=0
    PORTA=0
    SW1 var PORTA.1                         ;pattern selection switch 
    
    ;************* 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 = 254  
    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 for testing only or default sequence
    
    ;**************** main program ********************
    main:
    
    if sw1=0 then swcount=swcount+1         ;check to see if up button pressed, if so add 1 to SWcount
    pause 60                                ;debounce delay
    If swcount>7 then swcount=1             ;error trap for exceeding max patterns                      
    
    ;Pot PORTA.1,scale,D                     ;used to read value from 10k pot and set the speed
    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 250                      ;delay for speed
            NEXT
    GOTO MAIN
    In this example I've removed the wire from the 10 pot and set SW to the same pin as I have the pot working fine - and it works. If I set SW to RA0, RA2, RA3 etc the LEDs run through each pattern from 1 - 7 in a loop.

    As you stated, it must be something is the setting of port A for digital. However I will at some point want one pin to be det up to use the A to D conversion as I want to input the line signal from a CD player to get the LEDs to flash / run to music at some stage in the future, all other inputs.

    Sorry if it seems so basic, but as the other Steve can vouch for.. I'm very rusty on the PBP coding !

  2. #2
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1277&stc=1&d=116632121 9">

    Have a look at the chart above, which shows the lower nibble of ADCON1 (it's in the datasheet in section 11). ADCON1 = $0F sets PORTA.2 (pin4 ) as the Vref-. Try ADCON1=$07. This will make all PORTA pins digital.

    This should allow the Pot on PORTA.1 (pin 3) and the switch on PORTA.2 (pin4 ).

    I haven't looked real closely at the rest of the code yet, but this should help.

    SteveB

    EDIT: I should have read up on the POT command (never had a use for it), so I had to make a couple of changes.
    Attached Images Attached Images  
    Last edited by SteveB; - 17th December 2006 at 01:56.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yup it should fix the problem. THE ADCON1=$0F setting was good for the previous PIC18F2550... wich, i feel, will gather dust for awhile

    I never used POT command, i prefer to use a real A/D converter instead. ADCIN or the eternal write/read PIC register solution. For an audio trigger... i would use a analog comparator instead as they react way faster.
    Last edited by mister_e; - 17th December 2006 at 09:51.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Guys, thanks once again.

    I'll try the changes a little later and see how I get on.

    If I read that table correctly, by entering the value in the left column, AN0, AN1 etc are set accordingly. So for example 0000 would cause all the pins (AN0 - AN7) to be analogue. 011x would do the opposite and make them all digital ?

    I take it the $0f etc is just the Hex value for those dec numbers 0000 - 1111 ?

    was good for the previous PIC18F2550... which, i feel, will gather dust for awhile
    LOL - yeah.. you're probably right !

    For an audio trigger... i would use a analog comparator instead as they react way faster
    Steve, when I'm ready for looking at using music for the sound to light / chaser component I'll be interested to hear your suggestions as i've never used these sort of functions on a PIC before.

    Thanks again

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


    Did you find this post helpful? Yes | No

    Default

    Steve(s)

    That works fine (I had no reason to doubt it wouldn't)

    Slightly off topic, but I would like to run some ideas by you.

    I want to have three sections, chase, music and s2l. Chase is the section I've already written (with your help) that simply runs the selected pattern at what ever speed is set by the pot. Music is where I want to make the 8 LEDs act like a level meter, just like that on most tape decks or top end video recorders. S2L is a sound to light, where the music is split by filters for bass, mid and treble.

    For the music section I was thinking that i could simply connect the line in (1v peak to peak) from the CD player direct to a pin on the PIC and use the A to D convertion - although Steve mentioned someing about a comparator.. would this work ?

    As for the sound to light section (s2l) I was thinking of building something like the filter section shown on this site http://sound.westhost.com/project62a.htm but only using bass, lower midrange, upper midrange and treble, with two LEDs being driven from each filter (ie bass drives RB0 and RB1, lower mid RB2 and RB3, upper mid RB4 and RB5 with treble driving RB6 and RB7) -

    Comments would be wellcome

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The PIC have only 2 comparator if my memory serves me well, you if you need 3 different trigger source working at the same time you will need to add some external stuff... not really interesting.

    Here the ADC solution have it's own advantages. It will allow as many trigger source as you have ADCs. ALSO you can implement software threshold on EACH audio band (low, mid, high)

    well configured and speed optimized (clock source, acquisition time), ADC are not so slow, and BTW, we don't talk about something really timing critical... it's visual effect on audio. nobody will see the difference in a few ten or hundreds uSec of latency

    So you build a modern version of the old-timer 'color organ' ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    Thanks for the reply,

    Yes, I've been playing with making a colour organ (or sound to light unit) for some time. I originally made a basic unit using a 16F877 with code written in JAL (sory for swearing on the PBP forum ) - I then discoverd PBP and ported the basics over to a 16F628a, but never got around to doing the music side, and was limited by the number of pins so i couldn'l use the LCD.

    Now I'm determined to build the filters, get a decent bass beat peak circuit made, and include a normal sound to light based. This is really my first advancement from the simple "flash a LED" and combined with the factI've not coded for a while its a steep learning curve

    I'll swat up on the ADC section of the manual. I have used RA2 and RA3 for switches, but as these are AN2 and AN3 I will change them to RA4 and RA5 so that will leave RA0/AN0, RA2/AN2, and RA3/AN3 for use with the audio side.

    No doubt I'll probably need a helping hand to debug the code, but I'll see how far I can get on my own first, hopefully without blowing up the PIC (or the CD player !)

Similar Threads

  1. Need "PIC16F84A" Controler schematic Advice...
    By Kyo_89 in forum Schematics
    Replies: 1
    Last Post: - 28th May 2009, 00:03
  2. Design Advice
    By isaac in forum General
    Replies: 38
    Last Post: - 12th October 2008, 00:07
  3. Your OTP advice?
    By truvahorse in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th June 2008, 17:37
  4. NCD vs. DCD - Commentary
    By andrewroz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th November 2007, 00:16
  5. Advice needed on 'neat' Project!
    By vacpress in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th February 2007, 07:21

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