Weird problem with large(ish) array access


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,703


    Did you find this post helpful? Yes | No

    Default Re: Weird problem with large(ish) array access

    can't see any reason to it. the pause is not inserted where the banks rollover , its not on a code page boundary
    there is no difference in the lst that indicates a difference between loads.
    perhaps the flash did wear out or the bootloader wierds out somewhere
    i don't have one of those chips and my proteus has not got that model so i cant add much more than
    try loading the buffer this way ,for a different perspective
    [on a 18f26k22 but you can work it out]
    Code:
    #CONFIG
      CONFIG  FOSC=INTIO67, PLLCFG=OFF, PRICLKEN=OFF, FCMEN=OFF, IESO=OFF
      CONFIG  PWRTEN=OFF, BOREN=SBORDIS, BORV=190, WDTEN=ON, WDTPS=32768
      CONFIG  CCP2MX=PORTC1, PBADEN=OFF, CCP3MX=PORTB5, HFOFST=ON, T3CMX=PORTC0
      CONFIG  P2BMX=PORTB5, MCLRE=EXTMCLR, STVREN=ON, LVP=OFF, XINST=OFF, DEBUG=OFF
      CONFIG  CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF, WRT0=OFF
      CONFIG  WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF, EBTR0=OFF
      CONFIG  EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
    #ENDCONFIG
    
    define  OSC 64 
    OSCCON    = $70   ; 64Mhz
    OSCTUNE.6 = 1     ; Enable 4x PLL
    
    flashcount var word
    goto overasm
     ASM
    Flash2Ram macro buffer, msg,size ; Fills the buffer from flash msg
       movlw   UPPER msg
       movwf   TBLPTRU
       movlw   HIGH msg
       movwf   TBLPTRH
       movlw   LOW msg
       movwf   TBLPTRL
       movlw   low buffer        
       movwf   FSR2L
       movlw   High buffer
       movwf   FSR2H
       MOVE?CW  size ,_flashcount
       L?CALL  bfill
       endm 
            
    bfill
       tblrd   *+
       movf   TABLAT,w
       movwf  POSTINC2
       CHK?RP _flashcount
       MOVF  _flashcount,w ;DECREMENT 16 
       BTFSC STATUS,Z
       DECF  _flashcount +1, f   
       DECF  _flashcount , f
       BNZ     bfill
       MOVF  _flashcount +1,w
       BNZ     bfill 
       RST?RP 
       return     
     ENDASM    
     overasm:  
     
    DEFINE DEBUG_REG PORTB
    DEFINE DEBUG_BIT 7
    DEFINE DEBUG_BAUD 9600
    DEFINE DEBUG_MODE 0
    
    TRISB.7=0  ;DEBUG
    LATB.7=1   ;DEBUG
      
       
    ansela=0
    trisa=%11001111
    BTN1            VAR Porta.2
    BTN2            VAR Porta.3
    LD1             VAR LATa.4
    LD2             VAR LATa.5
    
    CRC             VAR WORD
    Number_Of_Bytes VAR BYTE
    
    Buffer          VAR BYTE[256]
    
    
    
    
       
    LD1 = 0
    LD2 = 0
    T0CON = %10000111       ' 1:16 prescaler TMR0 on
    
    Main:
        IF INTCON.2 = 1 THEN        ' TMR0 interrupt flag? 
            LD2 = ~LD2              ' Toggle LED so we know we're alive and kickin'
            INTCON.2 = 0
        ENDIF
        
    
        If BTN1 = 0 THEN
            LD1 = 1
            GOSUB SendMsg_1
            LD1 = 0
            WHILE BTN1 = 0 : WEND
        ENDIF
        
        IF BTN2 = 0 THEN
            LD1 = 1
            GOSUB SendMsg_2
            LD1 = 0
            WHILE BTN2 = 0 :WEND
        ENDIF
    
    Goto Main
    
    
    SendMsg_1:
    @ Flash2Ram  _Buffer, _msg1,110
    '    Buffer[0] = $87
    '    Buffer[1]  = $02
    '    Buffer[2]  = $06
    '    Buffer[3]  = $00
    '    Buffer[4]  = $40
    '    Buffer[5] = $00
    '    Buffer[6]  = $00
    '    Buffer[7]  = $ea
    '    Buffer[8]  = $c4
    '    Buffer[9]  = $50
    '    Buffer[10] = $00
    '    Buffer[11] = $62
    '    Buffer[12] = $3b
    '    Buffer[13] = $30
    '    Buffer[14] = $00
    '    Buffer[15] = $b8
    '    Buffer[16] = $9d
    '    Buffer[17] = $80
    '    Buffer[18] = $01
    '    Buffer[19] = $6c
    '    Buffer[20]  = $00
    '    Buffer[21]  = $b8
    '    Buffer[22]  = $d5
    '    Buffer[23]  = $80
    '    Buffer[24]  = $01
    '    Buffer[25]  = $70
    '    Buffer[26]  = $00
    '    Buffer[27]  = $b8
    '    Buffer[28]  = $b7
    '    Buffer[29]  = $80
    '    Buffer[30]  = $01
    '    Buffer[31]  = $6a
    '    Buffer[32]  = $00
    '    Buffer[33]  = $b8
    '    Buffer[34]  = $57
    '    Buffer[35]  = $80
    '    Buffer[36]  = $01
    '    Buffer[37]  = $6c
    '    Buffer[38]  = $00
    '    Buffer[39]  = $b8
    '    Buffer[40]  = $c4
    '    Buffer[41]  = $80
    '    Buffer[42]  = $01
    '    Buffer[43]  = $7c
    '    Buffer[44]  = $00
    '    Buffer[45]  = $b8
    '    Buffer[46]  = $a7
    '    Buffer[47]  = $80
    '    Buffer[48]  = $01
    '    Buffer[49]  = $69
    '    Buffer[50]  = $00
    '    Buffer[51]  = $27
    '    Buffer[52]  = $0f
    '    Buffer[53]  = $80
    '    Buffer[54]  = $01
    '    Buffer[55]  = $8b
    '    Buffer[56]  = $00
    '    Buffer[57]  = $8b
    '    Buffer[58]  = $73
    '    Buffer[59]  = $80
    '    Buffer[60]  = $00
    '    Buffer[61]  = $0b
    '    Buffer[62]  = $00
    '    Buffer[63]  = $b8
    '    Buffer[64]  = $a3
    '    Buffer[65]  = $80
    '    Buffer[66]  = $01
    '    Buffer[67]  = $6c
    '    Buffer[68]  = $00
    '    Buffer[69]  = $b8
    '    Buffer[70]  = $88
    '    Buffer[71]  = $80
    '    Buffer[72]  = $01
    '    Buffer[73]  = $6c
    '    Buffer[74]  = $00
    '    Buffer[75]  = $b8
    '    Buffer[76]  = $ce
    '    Buffer[77]  = $80
    '    Buffer[78]  = $01
    '    Buffer[79]  = $7c
    '    Buffer[80]  = $00
    '    Buffer[81]  = $b8
    '    Buffer[82]  = $aa
    '    Buffer[83]  = $80
    '    Buffer[84]  = $01
    '    Buffer[85]  = $6e
    '    Buffer[86]  = $00
    '    Buffer[87]  = $f6
    '    Buffer[88]  = $71
    '    Buffer[89]  = $80
    '    Buffer[90]  = $00
    '    Buffer[91]  = $0b
    '    Buffer[92]  = $00
    '    Buffer[93]  = $2c
    '    Buffer[94]  = $88
    '    Buffer[95]  = $80
    '    Buffer[96]  = $01
    '    Buffer[97]  = $93
    '    Buffer[98]  = $00
    '    Buffer[99]  = $14
    '    Buffer[100]  = $a5
    '    Buffer[101]  = $80
    '    Buffer[102]  = $01
    '    Buffer[103]  = $84
    '    Buffer[104]  = $00
    '    Buffer[105]  = $b8
    '    Buffer[106]  = $ae
    '    Buffer[107]  = $80
    '    Buffer[108]  = $01
    '    Buffer[109]  = $69 
        Number_Of_Bytes=0
        debug 13,10
        while    Number_Of_Bytes <109
            debug hex Buffer[Number_Of_Bytes]
            Number_Of_Bytes=Number_Of_Bytes+1
            if   Number_Of_Bytes//10 then
                debug ","
            else
                debug 13,10
            endif
        wend
        debug hex Buffer[Number_Of_Bytes],13,10 
    RETURN
    
    
    SendMsg_2:
    @ NOP 
    RETURN
    
    
    msg1:
    ASM
        DB 0X87,0X02,0X06,0X00,0X40,0X00,0X00,0Xea,0Xc4,0X50,0X00,0X62,0X3b,0X30,0X00,0Xb8
        DB 0X9d,0X80,0X01,0X6c,0X00,0Xb8,0Xd5,0X80,0X01,0X70,0X00,0Xb8,0Xb7,0X80,0X01,0X6a
        DB 0X00,0Xb8,0X57,0X80,0X01,0X6c,0X00,0Xb8,0Xc4,0X80,0X01,0X7c,0X00,0Xb8,0Xa7,0X80
        DB 0X01,0X69,0X00,0X27,0X0f,0X80,0X01,0X8b,0X00,0X8b,0X73,0X80,0X00,0X0b,0X00,0Xb8
        DB 0Xa3,0X80,0X01,0X6c,0X00,0Xb8,0X88,0X80,0X01,0X6c,0X00,0Xb8,0Xce,0X80,0X01,0X7c
        DB 0X00,0Xb8,0Xaa,0X80,0X01,0X6e,0X00,0Xf6,0X71,0X80,0X00,0X0b,0X00,0X2c,0X88,0X80
        DB 0X01,0X93,0X00,0X14,0Xa5,0X80,0X01,0X84,0X00,0Xb8,0Xae,0X80,0X01,0X69
    ENDASM
    Warning I'm not a teacher

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,624


    Did you find this post helpful? Yes | No

    Default Re: Weird problem with large(ish) array access

    Thanks Richard!
    This one's got me stumped for sure. After posting yesterday I had to get on with what I was doing so I just left the PAUSE 5 in there and added the remaining pieces of code back in and it worked fine. Then, this morning, after seeing your post about that there "should not be" any difference I removed the PAUSE 5 and it still worked (!)

    Then, even more stumped, I went back to the code I posted yesterday and it's repeatable. Without the PAUSE 5 it hangs. If I then remove the declaration of the CRC variable it works again. With the CRC variable declared AND the PAUSE 5 it also works.

    This piece of code is just something that I need to send messages to the device I'm actually trying to write the code for. As it stands I've probably spent 3/4 of the time on the code for the "helper" device and 1/4 of the time on the ACTUAL device. The end device is also using the 87J50 so I can't help worrying that something bad might be happening.

    Over the years I've come to trust what the PBP compiler produces and I can not remember a single time that an issue has not been MY fault but, honestly, this thing I do not understand.

    Thank you for the ASM array loader routines, I will most certainly try those when I get this piece of code out the door. Doing it "my way" is uggly and using ARRAYWRITE doesn't really work for hundreds of bytes.

    /Henrik.

Similar Threads

  1. Array variable access time
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2020, 08:48
  2. Replies: 9
    Last Post: - 14th September 2014, 20:38
  3. Weird Problem
    By isaac in forum General
    Replies: 9
    Last Post: - 22nd September 2008, 20:30
  4. Access array in PBP and .asm
    By JEC in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th September 2008, 01:35
  5. Large-ish PCB order...others wanted...
    By skimask in forum Off Topic
    Replies: 0
    Last Post: - 16th June 2006, 03:43

Members who have read this thread : 1

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