CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Weird problem with global variable int dat[64]?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

Weird problem with global variable int dat[64]?
PostPosted: Thu Jun 23, 2005 1:53 am     Reply with quote

Hi

I have an accelerometer which outputs in PWM. I use the PIC16F873 to time the pulse duty cycle.
Things work well.

Then I add the following lines at the top of file:

#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3

#define EEPROM_SIZE 32000
#define PAGE_SIZE 64
#define NO_EEPROMS 1

#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL)
//--------------------------------
int dat[64];
//====================

Things work fine if I dont include the int dat[64] line.
If I do add it in, the program does not perform as expected.
i.e. initially i get 0x82 output to my RS232 port, and now I get
a mixture of 0x82, and 0X56 data. The 0x56 should not be there.
So somehow things have changed, when I only include some definitions,
and space allocation. (I have not changed the program, and do not
do anything with the dat variable).

Can someone please tell me what I am doing wrong?

Thank you
arrow
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jun 23, 2005 7:13 am     Reply with quote

Sounds like a banks switching problem. By adding the new array of data your memory map has changed. You didn't mention your compiler version but some bugs related to bank switching have been solved in the past.

PIC processors are more memory efficient when the large global variables are placed at the end of memory. Check your symbol table (*.sym file) for variables crossing bank borders. Try moving the array to another bank (#locate directive).
Guest








PostPosted: Thu Jun 23, 2005 7:18 am     Reply with quote

Hi Ckielstra

My compiler version is:

2.686

I dont seem to have the #locate directive.
Can I use some other directive/ command? to specify the exact position in memory?
and if so, can you please give me an example?

Thank you very much
arrow
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 23, 2005 11:03 am     Reply with quote

With your version, you can use a #byte statement after the
array declaration to set the address of the array at the
beginning of RAM Bank 3. See the test program below.

After compiling, the the .SYM file has this entry:
Code:
190-1CF  DAT


Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)

int dat[64];
#byte dat = 0x190
//========================================
void main()
{

dat[0] = 0x55;

dat[63] = 0xAA;

}
Guest








PostPosted: Fri Jun 24, 2005 2:00 am     Reply with quote

Hi PCM programmer

I hvae tried doing what you suggest.
I had to use

#byte dat = 0x20

to get even the first part of the code to work.

When i was accessing the data (first writting and then reading),
the data came out in a mess.

Can you please tell me what I am doing wrong?

Thank you
arrow

My code snippet is:

#fuses LP,PROTECT,NOWDT,NOBROWNOUT

#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7,ERRORS)

#define ACCELEROMETER_X PIN_C2

#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3

#define EEPROM_SIZE 32000
#define PAGE_SIZE 32
#define NO_EEPROMS 1

#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL, NOFORCE_SW )

int dat[PAGE_SIZE];
#byte dat = 0x20
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 24, 2005 12:44 pm     Reply with quote

I was just answering that specific question. I didn't expect it to solve
any of your problems.

Quote:
#fuses LP,PROTECT,NOWDT,NOBROWNOUT
#use delay(clock=4000000)

Your code has so many problems, that I wonder if you have read
this forum. For example, you have never seen anyone in this forum
use "LP" mode for a 4 MHz crystal. The 16F877 data sheet says "LP"
mode is for 200 KHz maximum.
Also, the "PROTECT" option is useless during development. You only
need it when you are shipping your product, so your program can't
be copied. You don't need it now.


Quote:
#define EEPROM_SIZE 32000
#define PAGE_SIZE 32
#define NO_EEPROMS 1

You have defined the eeprom size incorrectly. The 24LC256
data sheet says on the very first page that it has 32K bytes,
which is 32768 bytes, not 32000.
Quote:
The Microchip Technology Inc. 24AA256/24LC256/
24FC256 (24XX256*) is a 32K x 8 (256K bit) Serial
Electrically Erasable PROM, SENSE AMP

You have defined the page size as 32, but again, the data
sheet says on the first page:
Quote:
• 64-byte page-write mode available



Quote:
#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL, NOFORCE_SW )

Your version of the compiler doesn't support Hardware i2c.
CCS didn't even claim support for that mode until vs. 2.721.
Your version accepts the NOFORCE_SW parameter, but produces
junk code if you use it. Don't use it.
From their old versions page:
Quote:

2.721 I2C hardware master mode now works on chips that have it
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group