code freezes after one run

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

code freezes after one run

Post by toyman » Fri Dec 09, 2016 7:09 pm

this code freezes up after one run through the code but only when using battery power. runs fine if the pickit2 still connected.using an 18F24K20 pic const array has 112 bytes. compiler says 512 bytes program bytes used and 42 variables. I am thinking its a memory issue?? but it should still freeze w/ pickit2 being connected.

Code: Select all

DIM RedLEDs AS PORTb
DIM GreenLEDs AS PORTa
DIM Anodes AS PORTC




DIM GreenBuffer(8) AS BYTE
DIM RedBuffer(8) AS BYTE
DIM x AS BYTE
DIM ScrollingTextOffset AS WORD
DIM ScrollingTextSpeed AS BYTE
DIM DefaultScrollingTextSpeed AS BYTE

SUB UpdateScrollingText()

    IF ScrollingTextSpeed <> 0 THEN
        DEC(ScrollingTextSpeed)
    ELSE
        ScrollingTextSpeed = DefaultScrollingTextSpeed 
        INC(ScrollingTextOffset)
        
        IF ScrollingTextOffset >= (BOUND(RedData)-7) THEN ' we need to check if we have reached the start of the last eight columns of data that's why we take away 8
            ScrollingTextOffset = 0
        ENDIF
    ENDIF         
END SUB

SUB SaveGraphics()
    FOR x = 0 TO 7
        ''GreenBuffer(x) = GreenData(x + ScrollingTextOffset)
        RedBuffer(x) = RedData(x + ScrollingTextOffset)
    NEXT
END SUB

SUB DisplayGraphics()
    FOR x = 0 TO 7
        ''GreenLEDs = GreenBuffer(x) XOR %11111111
        RedLEDs = RedBuffer(x) XOR %11111111
        Anodes.bits(7 - x) = 1
        DELAYUS(520)
        Anodes.bits(7 - x) = 0
    NEXT
END SUB

SetAllDigital

TRISA = %00000000           ' PORTA outputs 
TRISB = %00000000           ' PORTB outputs
TRISC = %00000000           ' PORTC outputs
'TRISD = %00000000           ' PORTC outputs
'TRISE = %00000001           ' PORTC outputs  except pin 0

// Start Of Program
OSCCON = %01100000          ' Internal oscillator running at 8mHz
'OSCTUNE.bits(6) = 1         ' enable PLL so we can run this thing at 32Mhz

//GreenLEDs = %00000000   ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
RedLEDs = %00000000   ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
Anodes = %00000000

ScrollingTextOffset = 0     
DefaultScrollingTextSpeed = 45  
ScrollingTextSpeed = DefaultScrollingTextSpeed
 
// Main Loop
WHILE True()                        // This creates an infinite loop
    UpdateScrollingText  
    SaveGraphics
    DisplayGraphics 

Jerry Messina
Swordfish Developer
Posts: 1265
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: code freezes after one run

Post by Jerry Messina » Fri Dec 09, 2016 8:48 pm

What you posted won't compile, and it certainly won't compile for an 18F24K20 all by itself.

If you want someone to look at your code, I'd suggest you paste it EXACTLY the way you have it,
or better yet attach it as a zip file.

There's probably no "memory issue"... the chip has a lot more memory available than that small program
looks like it wants to use.

toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

Re: code freezes after one run

Post by toyman » Fri Dec 09, 2016 9:26 pm

here is the complete code. I added the config BOREN = off and looks like it fixed the freezing up issue.
Thanks for looking at it. I need to research what Boren is, something to do with low operating voltage??

Code: Select all

' 8x8 RG Matrix Scrolling text test
' PORTB = RED LED Cathodes
' PORTB = GREEN LED Cathodes
' PORTC = Anodes


DEVICE = 18F24K20           ' Tell the compiler what chip we are using
CLOCK = 8                  ' Tell the compiler what we will be setting the clock to (in Mhz)           
CONFIG MCLRE = OFF          
CONFIG FOSC = intio67       ' Internal oscillator, IO on pins 6 and 7
CONFIG  BOREN = OFF
INCLUDE "utils.bas"



CONST RedData(112) AS BYTE =     (%00110111,%01000000,%00100000,%01000000,%00110111,%00000000,%01110111,%01010100,
                                  %01000010,%00000000,%01110111,%01000001,%01110010,%00000100,%00000000,%01111110,
                                  %01000001,%01110001,%00000010,%00000100,%00000000,%01100000,%00010000,%00000111,
                                  %00010000,%01100000,%00000000,%00000000,%00000000,%01110111,%01000100,%01000100,                                
                                  %00000000,%01110111,%00010000,%00010000,%01110111,%00000000,%01110111,%01000001,
                                  %00110010,%00000100,%00000000,%01110111,%00000000,%01110100,%01010100,%01010111,
                                  %00000000,%01000000,%01000000,%01110111,%01000000,%01000000,%00000000,%00110111,
                                  %01000000,%01000000,%00100000,%01000000,%01110111,%00000000,%00110111,%01010000,
                                  %01010000,%01110111,%00000000,%01110100,%01010100,%01010111,%00000000,%00000000,// custom
                                  %01110111,%01010100,%01000100,%00000000,%01110111,%00000100,%00000100,%00000000,
                                  %01110111,%01010100,%01000100,%00000000,%01110111,%01000100,%01000100,%00000000,
                                  %01110111,%01000001,%01110010,%00000100,%00000000,%00110011,%01000100,%01000100,
                                  %00110010,%00000000,%01110111,%00000100,%00000011,%00000100,%01110111,%00000000,
                                  %00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000)

''CONST GreenData(105) AS BYTE = (%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01111100,%10000010,%10000010,%01000100,%00000000,%11111110,%00010000,%00010000,%11111110,%00000000,%11111110,%00010010,%00010010,%11101100,%00000000,%10000010,%11111110,%10000010,%00000000,%01001100,%10010010,%10010010,%01100100,%00000000,%00000010,%11111110,%00000010,%00000000,%11111110,%00000100,%00011000,%00000100,%11111110,%00000000,%11111100,%00010010,%11111100,%00000000,%01001100,%10010010,%10010010,%01100100,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000)



DIM RedLEDs AS PORTb
DIM GreenLEDs AS PORTa
DIM Anodes AS PORTC




DIM GreenBuffer(8) AS BYTE
DIM RedBuffer(8) AS BYTE
DIM x AS BYTE
DIM ScrollingTextOffset AS WORD
DIM ScrollingTextSpeed AS BYTE
DIM DefaultScrollingTextSpeed AS BYTE

SUB UpdateScrollingText()

    IF ScrollingTextSpeed <> 0 THEN
        DEC(ScrollingTextSpeed)
    ELSE
        ScrollingTextSpeed = DefaultScrollingTextSpeed 
        INC(ScrollingTextOffset)
        
        IF ScrollingTextOffset >= (BOUND(RedData)-7) THEN ' we need to check if we have reached the start of the last eight columns of data that's why we take away 8
            ScrollingTextOffset = 0
        ENDIF
    ENDIF         
END SUB

SUB SaveGraphics()
    FOR x = 0 TO 7
        ''GreenBuffer(x) = GreenData(x + ScrollingTextOffset)
        RedBuffer(x) = RedData(x + ScrollingTextOffset)
    NEXT
END SUB

SUB DisplayGraphics()
    FOR x = 0 TO 7
        ''GreenLEDs = GreenBuffer(x) XOR %11111111
        RedLEDs = RedBuffer(x) XOR %11111111
        Anodes.bits(7 - x) = 1
        DELAYus(520)
        Anodes.bits(7 - x) = 0
    NEXT
END SUB

SetAllDigital

TRISA = %00000000           ' PORTA outputs 
TRISB = %00000000           ' PORTB outputs
TRISC = %00000000           ' PORTC outputs
'TRISD = %00000000           ' PORTC outputs
'TRISE = %00000001           ' PORTC outputs  except pin 0

// Start Of Program
OSCCON = %01100000          ' Internal oscillator running at 8mHz
'OSCTUNE.bits(6) = 1         ' enable PLL so we can run this thing at 32Mhz

//GreenLEDs = %00000000   ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
RedLEDs = %00000000   ' we will be xor'ing the led data to make sure it sends logic 0's to turn on the LED
Anodes = %00000000

ScrollingTextOffset = 0     
DefaultScrollingTextSpeed = 45  
ScrollingTextSpeed = DefaultScrollingTextSpeed
 
// Main Loop
WHILE True()                        // This creates an infinite loop
    UpdateScrollingText  
    SaveGraphics
    DisplayGraphics 
    'for x = 0 to 7
     'RedBuffer(x)= %00000000
     'next  
     'DefaultScrollingTextSpeed  = 45 
     'ScrollingTextSpeed = DefaultScrollingTextSpeed                             
WEND                                // Loop back to the while loop as long as we havent finished.



User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: code freezes after one run

Post by Coccoliso » Sat Dec 10, 2016 10:46 am

Hi Toyman,

pickit2 set also MCLR .. have pull-upped MCLR in your HW?

bitfogav
Registered User
Registered User
Posts: 167
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: code freezes after one run

Post by bitfogav » Sat Dec 10, 2016 11:47 am

I just thought I would share where this post started off, as MrDeb sorry toyman likes to share the same question all over several forums.

http://www.bradsprojects.com/forum/view ... =17&t=1269

Jerry Messina
Swordfish Developer
Posts: 1265
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: code freezes after one run

Post by Jerry Messina » Sat Dec 10, 2016 12:18 pm


toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

Re: code freezes after one run

Post by toyman » Sat Dec 10, 2016 3:05 pm

I see nothing wrong with getting two or three different opinions on same subject or project issue.
If this is an issue well I am sorry if I offended anyone.
I take and try out EVERY SUGGESTION just to see what and why a piece of code does this or that. Yes I copy and paste code just to get an idea what each section of a code does.
As an example I am trying to figure this ptype or pmove is doing (Grahams Tetris code over at DDIY).
Brad over at Brads Projects has got me hooked on led matrix projects.
I appreciate all the help I get and have thanked every one for their help and suggestions.
Especially thank David Barker for Swordfish basic. It keeps my mind working. Terrible getting old.

Jerry Messina
Swordfish Developer
Posts: 1265
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: code freezes after one run

Post by Jerry Messina » Sun Dec 11, 2016 12:26 pm

I'm not offended, but if you're going to ask for help in multiple places then at least give us links to where else you've posted.
That way we can see what's already been done, and see that like in this case, the problem was already solved.

Keeping it all in one place helps other people, especially somebody who might come along later with a similar problem.
If the solution is in three different threads on three different forums, they'll probably never know that.

toyman
Posts: 39
Joined: Tue Feb 18, 2014 8:25 pm

Re: code freezes after one run

Post by toyman » Sun Dec 11, 2016 2:45 pm

Good point Jerry
Will do as suggested.

Post Reply