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

    You guys crack me up !

    Ok' I'm working my way through this version using the 16F873A, but I've hit a small issue which is so basic I can't see why it responds the way it does (it worked with the 16F628a).

    I have set port A to all inputs and added
    Code:
    SW1 var PORTA.2                         ;pattern selection switch
    I have a 10k pull up resistor between pin 4 (RA2) and +5v with a tactile switch between pin 4 and GND.

    I've added the code
    Code:
    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
    So in therory if the switch (sw1) is low then swcount is increased by 1, until it is > than 7 and if so then its swcount is reset to 1. This way the pattern is selected by pressing the switch.

    However in practice, the PIC simply ignores any input on RA2, but more confusingly, it runs each pattern once in sequence, ie it cycles through the patterns as if the button is being pressed, so swcount must in some way be changing as the remainder of the code works if the above lines are remed out and swcount is manual set to 1, 2, 3 etc, which results in just the selected pattern running.

    Code:
    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 D                      ;delay for speed
            NEXT
    GOTO MAIN
    Its probably me having a blonde moment (no offence to any fair haired madiens out there ) - but can anyone shed some light why this isn't working.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c
    Ok' I'm working my way through this version using the 16F873A, but I've hit a small issue...

    I have set port A to all inputs...

    the PIC simply ignores any input on RA2, but more confusingly, it runs each pattern once in sequence, ie it cycles through the patterns as if the button is being pressed, so swcount must in some way be changing...
    Code:
    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 D                      ;delay for speed
            NEXT
    GOTO MAIN
    Exactly what value have you put into ADCON1 to "set port A to all inputs" yet still get the Pot command to work? It seems as though you still might have some of them set as Analog Inputs.

    SteveB
    Last edited by SteveB; - 17th December 2006 at 01:57.

  3. #3
    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 !

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

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

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

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

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