PBP array in ASM statements


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    The same is happening with @ CLRF _Counter +1.
    And ISR stops, sometimes begins to run, sometimes I have to reset my pic

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


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    I'm tad rusty, for ease... I would bet your should assign your array to BANK0 instead...

    post your PIC model and code, we'll try to help
    Steve

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

  3. #3
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    Here it is ISR
    Code:
    if PIR2.1=1 then
       T3CON=%00000110
       Wp= Wp & uwp
       Xn.0=IN1
       Xn.1=IN2
    
       
       IF (Xn.0<Xs.0 AND Trf=0) OR  (Xn.0<Xs.0 AND Xn.1=1 AND Trf=1) THEN
    @     INCF _Counter,F 'this work
          IF Counter[0] = Mtp2[0] OR (Counter=256 AND Mtp2[0]=0)THEN
    @      CLRF _Counter ' and this
              CNT[0]=CNT[0] + Add[0]
          ENDIF
       ENDIF
       
       IF (Xn.1<Xs.1 AND Trf=0) OR (Xn.0<Xs.0 AND Trf=1 AND Xn.1=0) THEN
    @     INCF _Counter+1,F 'Counter[1] = Counter[1] + 1  'won't work
          IF Counter[1] = Mtp2[1] OR (Counter[1]=256 AND Mtp2[1]=0)THEN
    @      CLRF _Counter+1'Counter[1]=0 'won't work
              CNT[1]=CNT[1]+Add[1]
          ENDIF
       ENDIF
       Xs=Xn
    
    @  CLRF PIR2
    endif
    Pic is 18LF14K50
    EDIT:
    bank0 or bankA is same...
    I tried RTC,it works fine with both.
    Last edited by pedja089; - 28th May 2011 at 22:14.

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


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    weird... a simple loop works here,

    Code:
    start:
        asm
            incf _MyArray,F
            incf _MyArray+1,F
        endasm    
        myvar=myarray[0]
        myvar2=myarray[1]
        goto start
    but as you're using a blend mix of ASM and PBP in an ISR, you must make sure you're always on the good BANK case not, hell yeah it may goes to lalaland... what you could try is to set all variable that goes in the ISR to BANKA.

    And yes I know I miss something

    EDIT: The more I think, the more it looks like a bank switching issue,
    Code:
        MyArray VAR BYTE[8] BANK1
        
        MyVar var byte BANK0
        MyVar2 var byte BANK0
        clear
    
    start:
        asm
            CHK?RP _MyArray
            incf _MyArray,F
            incf _MyArray+1,F
        endasm    
        pause 500
        myvar=myarray[0]
        myvar2=myarray[1]
        goto start
    The above work... commentout the CHK?RP line.. and nope... it doesn't.

    And NOPE, BANK0 !=BANKA
    Code:
    BANKA   $0000, $005F
    BANK0   $0060, $00FF
    Finger crossed before the real ASM/Compiler gurus came here and slap me a good one
    Last edited by mister_e; - 28th May 2011 at 22:58.
    Steve

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

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    As you can see, my isr have both and asm and pbp... All variables is in bankA.
    Somewhere i read that bank for 18F doesn't matter...
    How to setup correctly banks?
    But if I use i = i +1 instead INCF everything works. INCF and CLRF work if I make a array to separate variables...

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


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    Since we don't have the full code, or .LST file, I'll leave the more in deep & technical explanation of Access Ram, BSR and plah plah plah of section 3.3.3 to better guys (I hope I'm right though ).

    Again, the compiler keep track of everything for you, hence why the PBP lines will always works.

    add
    @ CHK?RP _Counter
    just before your INCF, DECF and or CLRF to see what happen
    Last edited by mister_e; - 28th May 2011 at 23:31.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    Are all of your variables in the same bank?
    Regards,

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

  8. #8
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: PBP array in ASM statements

    Same thing...
    Here it's complite code
    Code:
    DEFINE        OSC 4         ' We're using a 10MHz oscillator
    Define        INTHAND myint    ' Define interrupt handler
    DEFINE HSER_BAUD 2400
            OSCCON=%01010110
            OSCCON2.2=0
            OSCTUNE.7=1
            OSCTUNE.6=1
            REFCON0=0
            REFCON1=0
            ADCON1=0
            ADCON2=0
            ANSEL =0           
            ANSELH=0
            CM1CON0=0
            CM2CON0=0
            SRCON0=0
            SRCON1=0
            WPUA=0
            WPUB=0
            WDTCON=0   
            SLRCON=0           
            RCON.7=0
            RCON.6=0   
            UCON=0  
            IOCA=0
            IOCB=0
            T0CON=0
            T1CON=%00001111  
            T2CON=0
            T3CON=%00000110
            INTCON=192  
            INTCON2=0  
            INTCON3=0 
            PIR1=0
            PIR2=0
            PIE1=1
            PIE2=2
            IPR1=0
            IPR2=0
            porta=0
            portb=0
            portc=0
            trisa=255
            trisb=255
            trisc=255
    'RTC_________________________
    Seconds        VAR BYTE bankA  ' variables within myint must be in bank 0.
    Minutes        VAR Byte bankA       ' Elapsed minutes
    Hours          var byte bankA
    Day            var byte bankA     
    Month          var byte bankA
    Year           var byte bankA
    Ticks          var byte bankA
    DMonth         var byte bankA
    'IO________________
    SYMBOL Ul1  =PORTB.5
    SYMBOL Ul2  =PORTB.6
    SYMBOL Pull =PORTC.4
    SYMBOL UWp  =PORTC.3
    'TRIS______________
    INPUT  Ul1
    INPUT  Ul2
    OUTPUT Pull
    INPUT  uwp
    'Brojaci___________
    Brojac  VAR LONG[3] bankA
    PomBroj VAR WORD[2] bankA
    Mtp1    VAR BYTE[2] bankA
    Mtp2    VAR BYTE[2] bankA
    Add     VAR BYTE[2] bankA
    Xn      VAR BYTE    bankA
    Xs      VAR BYTE    bankA
    Wp      VAR BIT     bankA
    Trf     var byte    bankA
    
    
        year=0
        month=0
        day=0
        hours = 4
        minutes = 0       ' Pre Set time here then add seconds to clock using button
        seconds = 0
        ticks=0 
        PomBroj[0]=0
        PomBroj[1]=0
        Brojac[0]=0
        Brojac[1]=0
        mtp1[0]=1
        mtp1[1]=1
        mtp2[0]=1
        mtp2[1]=1
        add[0]=1
        add[1]=1
        Trf=0
       GoTo mainloop         
                           
    @myint 
    If PIR1.0 =1 then               
       TMR1H=252
    @  INCF _Ticks,F           
       if ticks=32 then 
    @     INCF _Seconds,F  
    @     CLRF _Ticks
          if seconds > 59 then
    @        CLRF _Seconds   
    @        INCF _Minutes,F
             if minutes > 59 then
    @          CLRF _Minutes
    @          INCF _Hours,F
               if hours > 23 then 
    @             CLRF _Hours
    @             INCF _Day,F
                  If month=2 then
                     If year//4<>0 then
                        DMonth=29
                     else
                        DMonth=28
                     endif
                  else
                  Dmonth=30+month.0 
                  endif   
                  If day>Dmonth then
    @                CLRF _Day
    @                INCF _Month,F
                     If month>12 then
    @                   CLRF _Month
    @                   INCF _Year,F
                        if year>99 then year=0
                     endif
                  endif
               endif
             endif
        endif 
       endif
       Pull=1
       TMR3H=255
       TMR3L=207
       T3CON=%00000111
    @  CLRF PIR1
    endif
    if PIR2.1=1 then
       T3CON=%00000110
       Wp= Wp & uwp
       Xn.0=ul1
       Xn.1=ul2
       Pull=0
        
       IF (Xn.0<Xs.0 AND Trf=0) OR  (Xn.0<Xs.0 AND Xn.1=1 AND Trf=1) THEN
    @     INCF _PomBroj,F 'PomBroj[0] = PomBroj[0] + 1 
          IF PomBroj[0] = Mtp2[0] OR (PomBroj=256 AND Mtp2[0]=0)THEN
           Brojac[0]=Brojac[0] + Add[0]
    @      CLRF _PomBroj'PomBroj[0]=0
          ENDIF
       ENDIF
        
       IF (Xn.1<Xs.1 AND Trf=0) OR (Xn.0<Xs.0 AND Trf=1 AND Xn.1=0) THEN
          PomBroj[1] = PomBroj[1] + 1  '  @     INCF _PomBroj+1,F '
          IF PomBroj[1] = Mtp2[1] OR (PomBroj[1]=256 AND Mtp2[1]=0)THEN
           Brojac[1]=Brojac[1]+Add[1]
           @ CHK?RP _PomBroj
    @      CLRF _PomBroj+1'PomBroj[1]=0'  
          ENDIF
       ENDIF
       Xs=Xn
    
    @  CLRF PIR2
    endif 
    @ retfie  FAST     
    
    
    mainloop:
    if ticks = 0 then
     trisb.7=0      
     hserout ["B1: ",dec9 brojac[0]," B2: ",dec9 brojac[1],13,10]'["Time: ",DEC hours, ":", DEC2 minutes, ":", DEC2 seconds,13,10]
    endif
    
    GoTo mainloop       
    
    End
    If i don't use PBP for clearing and increment variable here
    Code:
       IF (Xn.1<Xs.1 AND Trf=0) OR (Xn.0<Xs.0 AND Trf=1 AND Xn.1=0) THEN
          PomBroj[1] = PomBroj[1] + 1  '  @     INCF _PomBroj+1,F '
          IF PomBroj[1] = Mtp2[1] OR (PomBroj[1]=256 AND Mtp2[1]=0)THEN
           Brojac[1]=Brojac[1]+Add[1]
           @ CHK?RP _PomBroj
    @      CLRF _PomBroj+1'PomBroj[1]=0'  
          ENDIF
       ENDIF
    Counter(Brojac) Is incremented only on first falling edge. If I use PBP, everything work fine, but code is larger for 6 bytes. I need 4 counter. Becouse device have cr3203 batery, I'm trying to make smallest possible code. Maybe I can save on space by removing or's from IF's.

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