Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Storing literals for in Access RAM on a PIC18F for later use in program

Status
Not open for further replies.

crash@home

New Member
I am writing a program where i am timing an external event, i am using the capture module to do this, however what i would like to do is to copy the value stored in the timer (relating to the length of the event, or in this case the distance between events since it is the users input which triggers the capture start/stoop mechanism) to a register such that i may be able to store up to 10 values, for averaging and subsequently serial transmission. From my reading the Access RAM seems tailored for this kind of operation however the data sheet has me stuck.

Therefore my question is twofold:

how would i address Access RAM in 16bit extended literal mode (i'm writing this in assembly), and can i configure it such that it stores the values in a "vector" of sorts with a maximum of 10 literals.

Any advice would be much appreciated! :)
 
Hi,

Typically you first specify what Ram Bank you want to use for your general registers.

eg movlb D'1' ; define bank1

Your registers that need to be Accessed from any bank are first defined by

; Bank0 variables 0x000 to 0x07F** check this address - varies according to chip used.

cblock 0x000
ave1
ave2
ave3 etc
endc


cblock0x100 ; bank1 variables
user1
user2
user3

endc



eg when in Bank 1

movff ave2,user2

movff user3,ave3

movwf user1

movwf ave1


16bit extended literal mode
??
 
Thanks for the reply, so judging by what i'm reading user 1,2,3 ect.. refer to the different addresses in a particular bank and by referencing those addresses separately i can simply move the literal from the original location to the specified address. how i would typically do it using the movff instruction. The trouble is, using view>special function registers. In MPLab i can open a window to view the addresses of the SFR's but i cant see anywhere where the addresses the general RAM registers are, first so i may reference them and second so that when i compile and simulate i can see that the values are actually moving to the desired location
 
Hi,

Viewing the SFR will do just that, display just the Systems Registers, what the pic chip uses to do its functions.

You are wanting to see your USER registers or also called Variables that you set up in the RAM banks.
Its normal to assign names/labels to all your user registers, though there are other ways of addressing large contiguous areas without doing that.

The picture shows the two View windows, in the Watch window you can view selected System Registers and User Registers/Symbols.

Hope thats clearer ?
 

Attachments

  • watch.jpg
    watch.jpg
    109.3 KB · Views: 158
Thank you SO much, you have been exceptionally clear, and i 100% understand what you are saying to me, however what i am asking is (and i am aware even while typing this that it is a probably terribly trivial question, and i do ask with much trepidation) your vectors with custom assigned labels i.e. "tens", "huns", where were you able to understand/find the address of the vacant location of which to store these variables because the SFR window shows addresses of registers used for program functions intrinsic to the pic but if i wanted to reference a vacant location in a general register, where would i find the address of that such a location

Screen Shot 2013-01-26 at 19.00.18.png

the screenshot of the data sheet shows GPR from address 060h, would that refer to

Screen Shot 2013-01-26 at 19.01.43.png

this 600 i have highlighted in program memory, and then to address 3 adjacent registers for instance it would be the addresses on lines 769-771?

and if thats the case how would i then assign my own labels to these registers and add them to the watch window
since watch window only allows me to "add SFR" in the top left, and these addresses are not included in SFR rather program memory.

thanks
 
Hi,

When the pic starts all the RAM is empty.

One of the first lines of your code is the Include statement - see code below.

This is the complete list of the Pics own system registers that it loads into those dedicated RAM locations, typically the high bytes on the 18F chips.

Everything else below them is still empty.

To run your program your need work files / user registers.

You can address the RAM directly by is location like movwf 0x101 and movwf 0x504, very confusing .

So you assign a label / name in Assembly to the RAM locations, the Assembler then converts your labels into the direct addresses to go into your completed code.

Like the system registers, you have to load in your Users registers, this is done by a couple of methods, but I prefer the Cblock directives, again see the code example.
Its up to you to enter these labels and keep track of them.

In the disassembly listing what you are seeing is the Program Memory, the actual program code instructions, this a memory area called PROM and is totally separate from the RAM data memory ( and also EEprom)

Do not worry about asking the seemingly obvious, apart from a few Einsteins, we have all been there :D


What chip are you using, it looks like a large one with all that ram, the big ones can be quiet complex to set up.


Code:
;	Processor Type
;	==============

	LIST P=18F4520,r=hex,n=80,x=off,st=off
	errorlevel -302		; no bank warnings

	#include <P18F4520.INC>	
;******************************************************************************
; 
;	Configuration bits 
;	==================
  
; specified here are changes to the .inc file defaults

 CONFIG OSC=INTIO67, PWRT=ON, BOREN=OFF, WDT=OFF, LPT1OSC=OFF, PBADEN=OFF, MCLRE=ON  ; MCLRE  ON !!!!
 CONFIG LVP=OFF, XINST=OFF, DEBUG=OFF

;	Bank0 variables  0x000 to 0x07F access ram
	cblock  0x000
	crash1
	crash2
	ENDC

;	Bank1 variables 0x100 to 0x1FF

	cblock	0x100		; BANK1		
	crash3
	crash4
	endc


	cblock	0x200		; BANK2	 etc,etc
	crash5
	crash6
	endc


;******************************************************************************
;
;	Reset vector
;	============

		ORG	0x0000

bootup	goto	Main		;go to start of main code

; ******************************
;
;	Start of main program
;	=====================


Main	movlw	b'01100010'		; set internal osc to 4 mhz
		movwf	OSCCON
								; BANK1 specifed

		movlw	0X7F
		movwf	crash1				; in access ram bank 0

		movlw	0xF7
		movwf	crash1

		movff	crash1,crash2

		goto	main
 
I'm using the PIC18F26J11.

Im sure im now using the cblock directive correctly because im able to compile with no runtime or debugging errors so the syntax is seems correct, my only concern now is that i am unable to see the contents of the addresses i have just specified in the watch window, as you showed me earlier. when i type the name into symbol name it gives value "Not found".

In the assembly window it has the newly defined address label names the same colour as the labels i use when combining, is that to be expected.
 
Hi,

Yes I know what you mean.

Your user registers should show up in that blank dropdown box next to the 'add symbol' icon; you do not need to type in the name.

It did work for me last night and does work on my other projects but it will not do it on that example I gave, even after adding in some Config paramenters.

You can see your User registers as direct addresses by viewing the 'File Registers' and either single step or Animate though your code.


You could try creating another new Project and see if that allows the Watch window to work.


Think either there is some parameter we have missed or its a quirk of Mplab, of which their are a few.


Hopefully some other member might come in with the answer...
 
Hi, i think i have found the answer, just thought id share it as it may be beneficial to you in the future also,

https://www.microchip.com/forums/tm.aspx?m=147648

from project>build options> project>MPASMC17/C18 Suite i was able to verify that i was using relocatable code as oppose to absolute. Im going to rebuild the program and that should rectify the issue.

Thanks so much for your expertise its been priceless. Honestly! :eek::eek:
 
Hi,

Well found !

I always build in Absolute Code, so quiet surprised when I found that project set for Relocatable.
Suggest you stick to Absolute for the near future, Relocatable and Linked coding is not all its cracked up to be according to many who have tried it.

You have also found another very good source of help and info with the Microchip forum.
 
Crash
Just in case you may be missing it, as I did, on the far right of the watch screen you posted, just under the red close box, is another drop down arrow where all of your user variables will show up.

Also, provided that the variable is spelled with all caps, you can get the running value during simulation by hovering the mouse curser over its name. You have to set up the simulator to allow that.

Hope this helps. Aaron
 
Thanks Aaron ill give that a try too, with my project in Relocatable i'm unable to access the drop down menu as it is 'grayed-out' however ill rebuild and see how i get on

Thanks again
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top