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 21st November 2007, 05:59 PM   (permalink)
Default errors in mplab simulator

I'm having trouble in MPLab Sim. I've written a small program to see if I have grasped some of the theory behind the programming language. Everytime I try to debug/simulate it, it gives the error: "CORE-E0002: Stack under flow error occurred from instruction at 0x000005".

Can someone look at the program and see where I'm messing up? I've got it assigned to program a 16F628A. I've got the watch window open and viewing the data on PORTA, and that's really all that the program is supposed to do is make the PORTA data go 0000 > 0001 > 0011 then repeat.

Thanks,
Joe



;************************************************* *********************
; *
; Files required: *
; 16F628A.lkr *
; *
; *
;************************************************* *********************

list p=16F628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file

__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT



;***** VARIABLE DEFINITIONS (examples)

PORTA EQU 05h
TRISA EQU 85h

;************************************************* *********************

MAIN CODE


main

;******SETUP PORTA******
BSF STATUS, 5
MOVLW 00H
MOVWF TRISA
BCF STATUS, 5

START BSF PORTA, 0
BSF PORTA, 1
BSF PORTA, 2
MOVLW 00h
MOVWF PORTA

GOTO START



END ; directive 'end of program'
danuke is offline  
Old 21st November 2007, 06:08 PM   (permalink)
Default

You forgot to include an
Code:
org 0x000
at the beginning

Also no need to redefine the PORTA & TRISA, your include file does that for you.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 21st November 2007 at 06:10 PM.
blueroomelectronics is online now  
Old 21st November 2007, 06:17 PM   (permalink)
Default

Quote:
Originally Posted by blueroomelectronics
You forgot to include an
Code:
org 0x000
at the beginning

Also no need to redefine the PORTA & TRISA, your include file does that for you.
included as follows:
Quote:
org 0x000
list p=16F628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
I also removed the defining of the TRISA and PORTA as suggested. It still comes up with the error after rebuilding all.
danuke is offline  
Old 21st November 2007, 06:30 PM   (permalink)
Default

Quote:
Originally Posted by danuke
included as follows:


I also removed the defining of the TRISA and PORTA as suggested. It still comes up with the error after rebuilding all.

disregard the last post. I got it to working now. Thanks for the help!
danuke is offline  
Old 21st November 2007, 06:44 PM   (permalink)
Default

Put a comment ; in front of the words "MAIN CODE" or remove it.
This is being treated as a code command by the linker.

You have the org statment in the wrong place.
It should be on line above the word "main" for this example.

You don't need to compile with the linker - that is for re-locatable code.
picasm is offline  
Old 21st November 2007, 06:53 PM   (permalink)
Default

Quote:
Originally Posted by danuke
BSF PORTA, 1
BSF PORTA, 2
That is not good practice.

You should not change one bit in a port on the line after you have changed another line.

The reason is that each instruction reads the port, modifies one bit, and writes all 8 bits back to the port.

The voltage on the port is read only about 1 oscillator cycle after it has been set. If there is some small capacitance on the port, the voltage will not have been established, and the second instruction will read porta, 1 as low so it will be written as low just as porta, 2 goes high.
Diver300 is offline  
Old 21st November 2007, 07:08 PM   (permalink)
Default

Quote:
Originally Posted by picasm
Put a comment ; in front of the words "MAIN CODE" or remove it.
This is being treated as a code command by the linker.

You have the org statment in the wrong place.
It should be on line above the word "main" for this example.

You don't need to compile with the linker - that is for re-locatable code.
When I remove the MAIN CODE line and move the org line to be right above the "main", it starts giving an error of "Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00000000, length=0x00000012".

I'm new to the MPLab software so I probably sound green behind the ear to some of you more knowledgeable people.


Quote:
Originally Posted by Diver300
That is not good practice.

You should not change one bit in a port on the line after you have changed another line.

The reason is that each instruction reads the port, modifies one bit, and writes all 8 bits back to the port.

The voltage on the port is read only about 1 oscillator cycle after it has been set. If there is some small capacitance on the port, the voltage will not have been established, and the second instruction will read porta, 1 as low so it will be written as low just as porta, 2 goes high.
I will try to refrain from doing back to back bit changing in my coding from now on. I'm mainly trying to get some experience with MPLab. If looking to change more than one bit I'd write the to the w register then to the porta register. I appreciate the help in coding practice and will try to keep it in mind for the future.
danuke is offline  
Old 21st November 2007, 07:27 PM   (permalink)
Default

Back to back bit changing is fine in any register except a port.
Diver300 is offline  
Old 21st November 2007, 07:31 PM   (permalink)
Default

Works fine.
Code:
        list    p=16F628A 
        include <p16F628A.inc> 
        errorlevel -302 
        __CONFIG _LVP_OFF & _WDT_OFF & _INTOSC_OSC_NOCLKOUT
MAIN
;******SETUP PORTA******
        BSF     STATUS, RP0
        clrf    TRISA
        BCF     STATUS, RP0

START   BSF     PORTA, 0
        BSF     PORTA, 1
        BSF     PORTA, 2
        clrf    PORTA
        GOTO    START

        END
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is online now  
Old 21st November 2007, 08:23 PM   (permalink)
Default

Quote:
Originally Posted by danuke
When I remove the MAIN CODE line and move the org line to be right above the "main", it starts giving an error of "Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00000000, length=0x00000012".
I think that error is caused by using the linker script,which adds a bit too much complexity at this stage of learning.
To remove the linker script, click on "project" "remove file from project" then click on the "16f628a.lkr" file to remove it.
picasm is offline  
Old 21st November 2007, 08:31 PM   (permalink)
Default

thanks. Removing the linker file fixed the error I was receiving.

Whenever I'm in the watch mode watching the PORTA, it doesn't change the values as I single step through it using the debugger. Any ideas on what may be causing that? The values of TRISA change from FF to 20 though. But PORTA never changes values?
danuke is offline  
Old 21st November 2007, 08:54 PM   (permalink)
Default

Quote:
Originally Posted by danuke
Whenever I'm in the watch mode watching the PORTA, it doesn't change the values as I single step through it using the debugger. Any ideas on what may be causing that? The values of TRISA change from FF to 20 though. But PORTA never changes values?
Add these lines to your program:
Code:
main
    movlw    0x07    
    movwf    CMCON
and re-start the simulation.
eng1 is offline  
Old 21st November 2007, 10:25 PM   (permalink)
Default

Quote:
Originally Posted by eng1
Add these lines to your program:
Code:
main
    movlw    0x07    
    movwf    CMCON
and re-start the simulation.

WHOO HOO! It's working! Thanks everyone for the help!
danuke is offline  
Old 25th November 2007, 01:22 AM   (permalink)
Default

list p=16f84a ; initialize to the correct PIC type
#include <p16f84a.Inc>
errorlevel -302

org 0x0000 ;Reset vector



Bsf 03h,5
Movlw 01h
Movwf 85h
Bcf 03h,5


end


I ALSO GOT THE SAME Error "CORE-E0002: Stack under flow error occurred from instruction at 0x000005"

can anyone help me pls?
MIT-SoiT is offline  
Old 25th November 2007, 10:08 AM   (permalink)
Default

I think that the problem is what your program does after it has executed all your code. You haven't got a goto at the end to make it loop somewhere, and line 0x000005 is after the 4 lines of code in your example.

Most programs have an initialise that runs once, then a loop that cycles forever after that.

There a a couple of ways you could make things easier for yourself.

1) Use a pic16F627a. It is newer, better and cheaper than a pic16F84A

2) Use the names of registers and bits. It makes code easier to read. That is why you have the include file. The geeks and anoraks (http://en.wikipedia.org/wiki/Anorak_%28slang%29) here will know that:-

Bsf 03h,5
means
Bsf status, rp0

which sets the banking bit to page 1, but there is no point making it more difficult to read.

Similarly, 85h is the TRISA register (short for Tri-state, port A) and it is easier to refer to it as that.
Diver300 is offline  
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
Debugging 877A with MPLAB williB Micro Controllers 10 7th May 2007 04:53 PM
Need help badly on Inchworm and MPLAB thushy Micro Controllers 14 11th March 2007 07:05 PM
Inchworm project started williB Micro Controllers 69 5th March 2007 07:56 PM
MPLAB SIM ERROR gastonanthony Micro Controllers 7 28th April 2005 06:03 PM



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


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

eXTReMe Tracker