Using an Assmbly Routine in PBP


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel--

    Right on about the channel, it should say 6. Otherwise, I don't think it's a hardware issue, i.e. resonator vs. crystal... I've been using PBP code (follows) to capture a single channel or two and it works great, but I'd like to get the whole 512 channels, hence trying to adapt AN1075. I think its getting lost somewhere... could this have something to do with BANK0, BANK1, etc?

    This is the PBP routine that I have been using to read 2-3 channels at a time; on this same hardware platform it works great...

    Code:
     '====================================================
    ' DMX Subroutines
    '====================================================    
    
    readdmx:
            counter = 1
           	PIE1 = 0				' Mask the interrupt
            pulsin target, 0, counter
            idleflag = 0
            DMX_OK = 1
            if counter = 0 then
                idleflag = 1                        'either no DMX or break timed out
                DMX_OK = 0                          'set DMX as not present
                goto noshow_exit
            endif
            
            if counter < 35 then readDMX            'active pulse too short, keep looking
                                  'otherwise its valid DMX & time to read the start code
            dummy = rcreg
            dummy = rcreg 'do this twice to clear out ang garbage in the USART
            spbrg = 0
            txsta.2 = 0 'brgh = 0
            txsta.4 = 0
            rcsta.7 = 1 'turn on the USART
            rcsta.6 = 0 'setting 8 bit receive mode, no parity, etc.
            rcsta.4 = 0
            rcsta.4 = 1 'toggle the rcsta.4 bit to make-ready
            
            while rcif = 0 : wend   'hover until start code is received
            
            startcode = rcreg 'read the startcode somewhere, tho most likely we'll never look at it
    
            if dmx_channel = 1 then  'if DMX address is 1, do this special case
                dummy = rcreg
                goto exit_readDMX
            endif        
            
            'else, do this code for DMX addresses 2-512:        
            count0 = 0       
            While count0 < (dmx_channel-1) 'set up loop to count up to just 1 shy of target address
                while rcif = 0 : wend   'wait for a byte
                dummy = rcreg
                count0 = count0 + 1           
            WEND        
        exit_readDMX:   
            DMX_data = rcreg         'put the DMX byte into a variable and exit
        noshow_exit:
            rcsta.7 = 0              'turn off the USART
            if intensity > 0 then
                PIE1 = 1                        'restore interrupt
            else
                PIE1 = 0                        'if the intensity is >0, let the elapsed timer run
            endif
        return

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alanmcf View Post
    ... could this have something to do with BANK0, BANK1, etc?
    On an 18F, banking problems don't show up till you have more than ~200 bytes worth of variables.... You have 3. Not including the array, which is handled nicely by the FSR0 indirect.

    One thing your PBP version has, that the ASM doesn't, is clearing an OERR condition (CREN toggle).

    OERR locks up the USART until cleared, and many bytes could be received before the program looks for data. So it's probably overflowed before it gets to the ASM routine.
    <br>
    DT

  3. #3
    Join Date
    Mar 2006
    Posts
    41


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by Darrel Taylor View Post
    On an 18F, banking problems don't show up till you have more than ~200 bytes worth of variables.... You have 3. Not including the array, which is handled nicely by the FSR0 indirect.

    One thing your PBP version has, that the ASM doesn't, is clearing an OERR condition (CREN toggle).

    OERR locks up the USART until cleared, and many bytes could be received before the program looks for data. So it's probably overflowed before it gets to the ASM routine.
    <br>

    Sir Darrel;
    I'd like to ask which would you most prefer and or convenient with PIC18F data ram addressing "Access Ram" or "Indirect Addressing"

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by leisryan View Post
    I'd like to ask which would you most prefer and or convenient with PIC18F data ram addressing "Access Ram" or "Indirect Addressing"
    They're really two completely different things.
    But if I had to choose one, I'd say "Indirect Addressing".

    Access Ram is more for optimizing the code, reducing the size by letting you do things with less bank switching. It doesn't really give any additional functionality.

    But "Indirect Addressing" let's you use the entire RAM space like it's a big array, which adds just a TON of functionality. Strings, packets, buffers, software stacks, etc. etc.
    <br>
    DT

  5. #5
    Join Date
    Mar 2006
    Posts
    41


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Darrel Taylor View Post
    They're really two completely different things.
    But if I had to choose one, I'd say "Indirect Addressing".

    Access Ram is more for optimizing the code, reducing the size by letting you do things with less bank switching. It doesn't really give any additional functionality.

    But "Indirect Addressing" let's you use the entire RAM space like it's a big array, which adds just a TON of functionality. Strings, packets, buffers, software stacks, etc. etc.
    <br>
    Wow!!! I really appreciate it really enlightening!!! Is bank switching still occurs in "Indirect Addressing" Un-noticeably though?
    Last edited by leisryan; - 5th September 2008 at 00:29.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    > Is bank switching still occurs in "Indirect Addressing" Un-noticeably though?

    Well, YES and NO.

    But, if I had to choose one ...
    I'd say NO.

    On 18F's, the FSRx registers are 12-bits wide.
    Which means it can address any location from 0 to 4095 ($000 to $FFF).
    It can access memory locations in ANY BANK without having to change the current bank (BSR). It's just a single address.

    The beauty of this, is that no matter what bank your program is currently using, you can read/write from any other bank without switching the banks back and forth. Which may be where your original question was aimed, because Indirect addressing can be a good tool for optimization, much like the Access RAM.
    DT

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. PBP, ASM and LST files
    By HenrikOlsson in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th January 2010, 13:43
  3. Compiler differences between PBP 2.33 & 2.46
    By nikopolis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd May 2006, 19:01
  4. Newby- PBP wont compile for 18F (MPLAB)
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th December 2005, 23:30
  5. Replies: 2
    Last Post: - 8th August 2004, 16:00

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