Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 28th January 2008, 10:06 PM   (permalink)
Default Viewing amount of memory used

I've been busy writing a clock and LCD program in asm for the 16F628 and after some kind I worked out it kept crashing due to its size.

I loaded the program up in a simulator and the LCD displays what its supposed to. If however I make the program too big it keeps crashing.

From the datasheet the program memory is 2K. I think I might have exceeded that but I don't know where to check? In MPLAB there's a memory usage guide, but program and data memory display 0.
gregmcc is offline  
Old 28th January 2008, 10:08 PM   (permalink)
Default

Quote:
Originally Posted by gregmcc
In MPLAB there's a memory usage guide, but program and data memory display 0.
You have to 'import' the hex file (File->Import...). Then it'll show the memory usage.

Or open the .LST file.

Last edited by eng1; 28th January 2008 at 10:11 PM.
eng1 is offline  
Old 28th January 2008, 10:14 PM   (permalink)
Default

In MPLAB View->Memory Usage Gauge.
felis is offline  
Old 28th January 2008, 10:21 PM   (permalink)
Default

Aghh thanks eng1. As easy as that It doesn't work if you don't import the hex file.

That leads onto my second problem The amount of program memory showing is 340 out of 2048. I thought it was a memory problem but it doesnt look like it.

I've now taken Nigel's LCD tutorial and simulated the problem. I've put in a bunch of NOP's in the code and it falls over on the simulator. If its not memory related, what's causing it?

I've attached the asm file. If someone could please have a look and tell me if it memory related or something more sinister.
Attached Files
File Type: asm lcd.asm (5.5 KB, 7 views)
gregmcc is offline  
Old 28th January 2008, 10:40 PM   (permalink)
Default

Quote:
Originally Posted by gregmcc
I've attached the asm file. If someone could please have a look and tell me if it memory related or something more sinister.
I doubt that it can be related to the memory space available (there's plenty of free memory). Try moving the tables right next to Stop: goto Stop and see if that helps



EDITED: typos corrected.

Last edited by eng1; 28th January 2008 at 10:58 PM.
eng1 is offline  
Old 28th January 2008, 10:46 PM   (permalink)
Default

Holy smokes - it now works!!

Now I'm confused - what difference does the table location make? Its all part of the same program memory isn't it?
gregmcc is offline  
Old 28th January 2008, 10:54 PM   (permalink)
Default

It looks like a 'page boundary' problem. See Microchip's Application Note 556.

http://ww1.microchip.com/downloads/e...tes/00556e.pdf - link added.

Last edited by eng1; 28th January 2008 at 11:25 PM.
eng1 is offline  
Old 29th January 2008, 08:59 AM   (permalink)
Default

Thanks - I'll check out the note.

You learn something new every day
gregmcc is offline  
Old 30th January 2008, 02:57 AM   (permalink)
Default

In MPLAB you can also use View->Program Memory. This is very crucial when dealing with tables. You can easily see when a table crosses a 256 byte boundary as an address rolls over from XFF to (X+1)FF.

Wait until you come against the 2046 byte program boundary in larger sized word chips. God bless Microchip.
donniedj is offline  
Old 30th January 2008, 06:13 AM   (permalink)
Default

A little bit of code I picked up somewhere:

Code:
Table1: 
        ADDWF   PCL, f   ;jump forward by value of W 
        retlw   'A' 
        retlw   'B' 
        retlw   'C' 
        retlw   'D' 
        retlw   'E' 
        retlw   'F'  ;end of table 
 IF HIGH($)!=HIGH(Table1) 
 ERROR "End of table is not in same page as start of table" 
 ENDIF
It will give an error at compile time if Table1 crosses a page boundary.
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline  
Old 30th January 2008, 12:02 PM   (permalink)
Default

donniedj/kchriste - awesome thanks. That will really help me. Had no idea bout the page boundry.
gregmcc is offline  
Old 30th January 2008, 03:38 PM   (permalink)
Default

That is a good one kchriste.

I wonder if that idea couldn't be expanded upon to conditionally assemble the extra instructions for "256 byte boundary tolerant" code only when it's actually needed?

Mike
Mike, K8LH is offline  
Old 30th January 2008, 03:44 PM   (permalink)
Default

Quote:
Originally Posted by Mike, K8LH
That is a good one kchriste.

I wonder if that idea couldn't be expanded upon to conditionally assemble the extra instructions for "256 byte boundary tolerant" code only when it's actually needed?

Mike
No it can't. I tried writing such a macro and due to forward references the compiler throws a wobbly. First pass the assembler doesn't know the end address of the table and so can't calculate the offset needed. Second pass it inserts the required space and all labels after that are now a different value. I also tried to write a conditional far call macro and that suffered the same problem.

Mike.
Pommie is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Question about Inchworm+ Quan Micro Controllers 54 28th October 2007 01:21 AM
memory addressing samcheetah General Electronics Chat 4 29th September 2004 07:33 PM
PIC Micro Data vs Program Memory CoTang Micro Controllers 4 14th January 2004 08:04 PM
8051 "data" storage within program memory - how? L0D|Mr_B Micro Controllers 1 11th January 2004 03:56 PM
Memory upgrades electrogeek General Electronics Chat 1 19th January 2003 04:33 PM



All times are GMT. The time now is 05:25 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker