Analog issue


Closed Thread
Results 1 to 19 of 19

Thread: Analog issue

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    just try

    Code:
    FLASH:
    
    IF (Porta.4 AND NOT Porta.5) THEN
    
    PORTB.3 = 1
    PAUSE DUR
    
    PORTB.0 = 1 : PORTB.1 = 1 : PORTB.3 = 0
    pause 1000
    
    ENDIF
    
    GOTO MAIN
    Last edited by Acetronics2; - 17th March 2009 at 17:38.
    ************************************************** ***********************
    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 " !!!
    *****************************************

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I would replace PORTB.0 = 1 : PORTB.1 = 1 : PORTB.3 = 0 with a single write to the whole
    port to help reduce my chances of read-modify-write.

    You can make your code a lot smaller/faster also by adjusting a few simple routines.

    Below are just a few suggestions.
    Code:
    PORTB = %00000111 ' setting port latches "before" tris avoids pin glitches
    TRISA = %11111111
    TRISB = %11110000
    
    'PORTB.0 = 1   ' done above
    'PORTB.1 = 1   ' Note: this can cause read-modify-write problems
    'PORTB.2 = 1
    'PORTB.3 = 0
    
    'BNK1 = 0      ' taken care of below 
    'BNK2 = 0
    'DUR = 0
    
    MAIN:
        DUR = 0
        ' PORTB.3 = 0 ' taken care of at POR and end of Flash routine
        BNK1 = 0
        BNK2 = 0
        ADCIN 0, BNK1
        ADCIN 1, BNK2
    
    '    IF PORTB.4 = 1 then
    '    DUR = 8
    '    endif
    '    IF PORTB.5 = 1 THEN 
    '    DUR = 4
    '    endif
    '    IF PORTB.6 = 1 THEN 
    '    DUR = 2
    '    endif
    '    IF PORTB.7 = 1 THEN 
    '    DUR = 1
    '    endif
    
        ' reverse how DIP switch assigns 8,4,2,1 with
        ' IF RB7 = 1 DUR = 8
        ' IF RB6 = 1 DUR = 4
        ' IF RB5 = 1 DUR = 2
        ' IF RB4 = 1 DUR = 1
        
        ' now just shift upper 4-bits read from DIP switch
        ' AND make sure upper 4-bits of result in DUR are clear.
         DUR = (PORTB >> 4) & $0F 
        ' returns 8, 4, 2 or 1 in DUR if "ONLY 1" of RB7, RB6, RB5 or RB4 are set.
        
        IF (BNK1 => 466) OR (BNK2 => 466) THEN FLASH
        goto MAIN
        
    FLASH:
        IF (PORTA.4=1) OR (PORTA.5=0) THEN 
    '   PORTB.0 = 0 : PORTB.1 = 0 : PORTB.3 = 1
        PORTB = %00001100 ' avoids read-modify-write
        endif
           
    '    IF DUR = 1 THEN 
    '    PAUSE 1
    '    endif
    '    IF DUR = 2 THEN 
    '    PAUSE 2
    '    endif
    '    IF DUR = 4 THEN 
    '    PAUSE 4
    '    endif
    '    IF DUR = 8 THEN 
    '    PAUSE 8
    '    endif
        PAUSE DUR ' DUR already holds the PAUSE time. This saves a lot of code.
        
    '   PORTB.0 = 1 : PORTB.1 = 1 : PORTB.3 = 0
        PORTB = %00000111 ' avoids read-modify-write
        GOTO MAIN
        
        END
    I don't know which PIC you're using, but I would also check to make sure RA4 and RA5 are
    both set to digital "analog disabled" for these pins so they don't return the wrong value
    when being tested.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    Bruce, thanks for the awesome post. I feel edumacated now!

    Actually before I saw your post I changed a few things and got the board working perfectly. I'll include your port setting changes to remoe the potential RMW errors. Thanks for that suggestion.

    However, I am unable to implement the reversal of dip swith settings as the board is laid out and silkscreen shows 1, 2, 4 and 8mS.


    So, has anyone ever seen 6 LED's pulling over 1.5KW?!

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


    Did you find this post helpful? Yes | No

    Talking Bad an excuse !!!

    Hi, JM

    However, I am unable to implement the reversal of dip swith settings
    May be you could have a look to manual $ 4.17.11

    REV command ...

    Alain
    Last edited by Acetronics2; - 18th March 2009 at 08:30.
    ************************************************** ***********************
    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 " !!!
    *****************************************

Similar Threads

  1. pic18f analog comparator problem
    By david.silaghi in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th May 2009, 09:38
  2. Pic getting part power from Analog Port
    By ShaneMichael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 22nd April 2009, 10:34
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  4. 18F1320 ... Strange Memory
    By Acetronics2 in forum mel PIC BASIC Pro
    Replies: 43
    Last Post: - 9th April 2006, 09:55
  5. analog inputs on 16F716
    By schwinn_rider in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th October 2005, 04:07

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