(SOLVED)Atmel Studio- Life time of variable? + String exception

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First of all i have been asking too many questions lately, questions are not stopping me from developing my projects but i can not stop thinking about them unless i find an answer.

I was making myself a ds3231 based lcd clock i wrote a lot of functions for each register in ds3231. Read_Seconds Read_Hour .... why not just use one ? well because for every data i retrieve from ds3231 i have to make some calculations to get the real char value of real time and it is different for every register. So program works fine not going to post it all here because it is very long and none would take time to read it. I ll move on and ask the question. After compiling the the whole project i get these values for ram and data usage

 

Program Memory Usage : 7246 bytes   22.1 % Full

Data Memory Usage : 240 bytes   11.7 % Full (Yes i still have plenty of ram but seeing this is bothering me as of i am not using ram efficiently)

 

Now what i think is 240 bytes is very large for variables given in functions. I did not use any global variable so this brought up the question is the 240 value compile time ram usage?(All the variables in ram at the same time) Because from what i read and know is every variable i declare in a scope will end up getting deleted if not deleted will be available for overwriting for other datas when the scope ends.If i am correct my program should not consume more than around 50 byte at a time. 

 

I tried to find an answer to this by starting up a simple project writing variables in functions and globally setting them to port b ... but this time data usage was less then the variables i declared globally.
It is maybe because i set them only once and the compiler did not take them as variable because i never changed their value again? ... I really do not know how it gets handled by compiler.

 

I once heard from my teacher that ram handling in assembly is better then C because control of the ram addresses is all the time in your hands. Is this the kind of problem i am facing now?

 

Here is my ds3231 header file to be an example

#define     DS3231  0b11010000
#define 	I2C_READ   1
#define 	I2C_WRITE   0

unsigned char read_ds3231(unsigned char Rdata)
{
	    unsigned char ret;
		i2c_start_wait(DS3231+I2C_WRITE);     // set device address and write mode
		i2c_write(Rdata);                        // write address = 1
		i2c_rep_start(DS3231+I2C_READ);       // set device address and read mode
		ret = i2c_readNak();                    // read one byte from EEPROM
		i2c_stop();
		return ret;
}

void write_ds3231(unsigned char Wdata_adress, unsigned char Wdata_data)
{
		i2c_start_wait(DS3231+I2C_WRITE);
		i2c_write(Wdata_adress);
		i2c_write(Wdata_data);
		i2c_stop();
}

unsigned char Read_second(void)
{
	unsigned char ret;             //returning data byte
	unsigned char data;            //read data byte
	unsigned char seconds;         //data byte for second section
	unsigned char seconds10;       //data byte for 10sec section
	data=read_ds3231(0x00);        // read the second register
	seconds10=data&0b01110000;     //bitwise operation for 10sec section
	seconds10=(seconds10>>4);      //bitwise operation to left to read out value
	seconds10=seconds10*10;        //give the real 10sec value
	seconds=data&0b00001111;       //give the real seconds value
	ret=seconds10+seconds;         //Seconds in unsigned char
	return ret;                    //retrun the value
}

unsigned char Read_minutes(void)
{
		unsigned char ret;             //returning data byte
		unsigned char data;            //read data byte
		unsigned char minutes;         //data byte for minute section
		unsigned char minutes10;       //data byte for 10minute section
		data=read_ds3231(0x01);        // read the second register
		minutes10=data&0b01110000;     //bitwise operation for 10min section
		minutes10=(minutes10>>4);      //bitwise operation to left to read out value
		minutes10=minutes10*10;        //give the real 10min value
		minutes=data&0b00001111;       //give the real minutes value
		ret=minutes10+minutes;         //minutes in unsigned char
		return ret;                    //retrun the value
}

unsigned char Read_hour_24(void)
{
        unsigned char ret;              //returnning data byte
		unsigned char data;             //read data byte
		unsigned char hour;             //data byte for hour section
		unsigned char hour_1;           //data byte for 10hour section
		unsigned char hour_2;           //data byte for 20hour section
		data=read_ds3231(0x02);
		hour_2=data&0b00100000;
		hour_2=(hour_2>>5);
		hour_2=hour_2*20;               //if 20 hour is set 10 hour bit is 0
		hour_1=data&0b00010000;
		hour_1=(hour_1>>4);
		hour_1=hour_1*10;               //10 hour bit
		hour=data&0b00001111;
		ret=hour_2+hour_1+hour;
		return ret;
}

unsigned char Read_day(void)
{
	    unsigned char ret;
		unsigned char data;
		unsigned char day;
		data=read_ds3231(0x03);
		day=data;
		ret=day;
		return ret;
}

unsigned char Read_date(void)
{
	    unsigned char ret;
		unsigned char data;
		unsigned char date;
		unsigned char date_10;
		data=read_ds3231(0x04);
		date_10=data&0b00110000;
		date_10=(date_10>>4);
		date_10=date_10*10;
		date=data&0b00001111;
		ret=date_10+date;
		return ret;
}

unsigned char Read_month(void)
{
	   unsigned char ret;
	   unsigned char data;
	   unsigned char month;
	   unsigned char month_10;
	   data=read_ds3231(0x05);
	   month_10=data&0b00010000;
	   month_10=(month_10>>4);
	   month_10=month_10*10;
	   month=data&0b00001111;
	   ret=month_10+month;
	   return ret;
}

unsigned char Read_year(void)
{
	   unsigned char ret;
	   unsigned char data;
	   unsigned char year;
	   unsigned char year_10;
	   data=read_ds3231(0x06);
	   year_10=data&0b11110000;
	   year_10=(year_10>>4);
	   year_10=year_10*10;
	   year=data&0b00001111;
	   ret=year_10+year;
	   return ret;
}

void Write_second(unsigned char second)
{
	unsigned char send;
	unsigned char _10second;
	unsigned char _second;
	_10second=second/10;
	_10second=(_10second<<4);
	_second=second%10;
	send=_second|_10second;
	write_ds3231(0x00,send);
}

void write_minute(unsigned char minute)
{
	unsigned char send;
	unsigned char _10minute;
	unsigned char _minute;
	_10minute=minute/10;
	_10minute=(_10minute<<4);
	_minute=minute%10;
	send=_minute|_10minute;
	write_ds3231(0x01,send);
}

void write_hour_24(unsigned char hour)
{
	unsigned char send;
	unsigned char _hour;
	unsigned char _10hour;
	unsigned char _20hour;
	if(hour>=20)
	{
		_20hour=1;
		_20hour=(_20hour<<5);
	}
	if(hour<20 && hour>=10)
	{
		_10hour=1;
		_10hour=(_10hour<<4);
	}
	_hour=hour%10;
    if(hour>=20)
	{
		send=_20hour|_hour;
		write_ds3231(0x02,send);
	}
	if(hour<20 && hour>=10)
	{
        send=_10hour|_hour;
		write_ds3231(0x02,send);
	}
	if(hour<10)
	{
		send=_hour;
		write_ds3231(0x02,send);
	}
}

void write_day(unsigned char day)
{
	unsigned char send;
	unsigned char _day;
	_day=day;
	send=_day;
	write_ds3231(0x03,send);
}

void write_date(unsigned char date)
{
	unsigned char send;
	unsigned char _date;
	unsigned char _10date;
	_10date=date/10;
	_10date=(_10date<<4);
	_date=date%10;
	send=_10date|_date;
	write_ds3231(0x04,send);
}

void write_month(unsigned char month)
{
	unsigned char send;
	unsigned char _month;
	unsigned char _10month;
	_10month=month/10;
	_10month=(_10month<<4);
	_month=month%10;
	send=_10month|_month;
	write_ds3231(0x05,send);
}

void write_year(unsigned char year)
{
	unsigned char send;
	unsigned char _year;
	unsigned char _10year;
	_10year=year/10;
	_10year=(_10year<<4);
	_year=year%10;
	send=_10year|_year;
	write_ds3231(0x06,send);
}

unsigned char Read_A1M1_seconds(void)
{
	unsigned char ret;             //returning data byte
	unsigned char data;            //read data byte
	unsigned char seconds;         //data byte for second section
	unsigned char seconds10;       //data byte for 10sec section
	data=read_ds3231(0x07);        // read the second register
	seconds10=data&0b01110000;     //bitwise operation for 10sec section
	seconds10=(seconds10>>4);      //bitwise operation to left to read out value
	seconds10=seconds10*10;        //give the real 10sec value
	seconds=data&0b00001111;       //give the real seconds value
	ret=seconds10+seconds;         //Seconds in unsigned char
	return ret;                    //retrun the value
}

unsigned char Read_A1M2_minutes(void)
{
	unsigned char ret;             //returning data byte
	unsigned char data;            //read data byte
	unsigned char minutes;         //data byte for minute section
	unsigned char minutes10;       //data byte for 10minute section
	data=read_ds3231(0x08);        // read the second register
	minutes10=data&0b01110000;     //bitwise operation for 10min section
	minutes10=(minutes10>>4);      //bitwise operation to left to read out value
	minutes10=minutes10*10;        //give the real 10min value
	minutes=data&0b00001111;       //give the real minutes value
	ret=minutes10+minutes;         //minutes in unsigned char
	return ret;                    //retrun the value
}

unsigned char Read_A1M3_Hour(void)
{
	unsigned char ret;              //returnning data byte
	unsigned char data;             //read data byte
	unsigned char hour;             //data byte for hour section
	unsigned char hour_1;           //data byte for 10hour section
	unsigned char hour_2;           //data byte for 20hour section
	data=read_ds3231(0x09);
	hour_2=data&0b00100000;
	hour_2=(hour_2>>5);
	hour_2=hour_2*20;               //if 20 hour is set 10 hour bit is 0
	hour_1=data&0b00010000;
	hour_1=(hour_1>>4);
	hour_1=hour_1*10;               //10 hour bit
	hour=data&0b00001111;
	ret=hour_2+hour_1+hour;
	return ret;
}

void Write_A1M1_Seconds(unsigned char second)
{
	unsigned char send;
	unsigned char _10second;
	unsigned char _second;
	_10second=second/10;
	_10second=(_10second<<4);
	_second=second%10;
	send=_second|_10second;
	write_ds3231(0x07,send);
}

void Write_A1M2_Minutes(unsigned char minute)
{
	unsigned char send;
	unsigned char _10minute;
	unsigned char _minute;
	_10minute=minute/10;
	_10minute=(_10minute<<4);
	_minute=minute%10;
	send=_minute|_10minute;
	write_ds3231(0x08,send);
}

void Write_A1M3_Hour(unsigned char hour)
{
	unsigned char send;
	unsigned char _hour;
	unsigned char _10hour;
	unsigned char _20hour;
	if(hour>=20)
	{
		_20hour=1;
		_20hour=(_20hour<<5);
	}
	if(hour<20 && hour>=10)
	{
		_10hour=1;
		_10hour=(_10hour<<4);
	}
	_hour=hour%10;
	if(hour>=20)
	{
		send=_20hour|_hour;
		write_ds3231(0x09,send);
	}
	if(hour<20 && hour>=10)
	{
		send=_10hour|_hour;
		write_ds3231(0x09,send);
	}
	if(hour<10)
	{
		send=_hour;
		write_ds3231(0x09,send);
	}
}

void Write_A1M4_Date(void)
{
	write_ds3231(0x0A,0b11111111);
}

unsigned char Read_Control(void)
{
	unsigned char ret;
	unsigned char data;
	data=read_ds3231(0x0E);
	ret=data;
	return ret;
}

void Write_Control( unsigned char action) // 1 for setting bit 0 for unsetting bit
{
	if(action==1)
	{
		write_ds3231(0x0E,0b00011101);
	}
	if(action==0)
	{
		write_ds3231(0x0E,0b00011100);
	}
}

void Write_Status(unsigned char status)
{
	unsigned char data;
	data=read_ds3231(0x0F);
	data=status&data;
	write_ds3231(0x0F,data);
}

 

 

 

 

 

 

Last Edited: Tue. Jan 23, 2018 - 01:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The map file should answer your question of what is stored where in memory...

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This seems like quite a lot of code for a clock:

yorem_kastor wrote:
Program Memory Usage : 7246 bytes 22.1 % Full

 

I think you should read a good C book. (Such as Kernighan & Ritchie Ansi version).

 

(Almost) all your variables are defined inside functions.

This means they are "automatic". They are made on the stack, or in registers only and they do not even exist after the function returns.

So these variables are not among your 240 bytes RAM.

So the question remains, what are those 240 bytes?

It's all global data declared outside of functions.

It's all data declared with the "static" keyword.

A few arrays quickly add up...

 

It is good that you realise that resources such as RAM are quite limited on a small uC.

octave:1> 7246/.22
ans =    3.2936e+04

AVR with 32k Flash.  M328? -> 2kiBi RAM.

240 bytes ram for a program of 7kB also is nothing extraorninary. Looks like normal memory usage.

 

One thing you have to be aware of is that there is a "stack", and it is at the end of RAM.

It "grows" downward (during (nested) function calls) into the "heap".

Heap is for stuff as alloc() / malloc() and such and you should NOT use this in small uC's.

 

Some other / none related remarks, in this code:

1)	data=read_ds3231(0x08);        // read the second register
2)	minutes10=data&0b01110000;     //bitwise operation for 10min section
3)	minutes10=(minutes10>>4);      //bitwise operation to left to read out value
4)	minutes10=minutes10*10;        //give the real 10min value
5)	minutes=data&0b00001111;       //give the real minutes value

There is absolutely no need for line 2). It does nothing.

Compare with:

minutes10 = data>>4;    // Lowest 4 bits are shifted into oblivion.

You also have quite a bit of repitition in your code.

A lot of conversions between packed BCD and numbers.

If you write a separate function for this then:

1). Your code is easier to read for human beings.

2). The compiler generates more compact code.

3). Your code is easier to debug (If you find an error in BCD -> decimal conversion, you only have to change 1 subroutine).

 

For a C compiler an " unsigned char" is the same as an uint8_t, but for a human it is not.

Use char if your data represents characters (Ascii) Use uint8_t ( or int8_t for singed)  if your data represents numbers.

// Old Code:
unsigned char Read_A1M2_minutes(void)
{
	unsigned char ret;             //returning data byte
	unsigned char data;            //read data byte
	unsigned char minutes;         //data byte for minute section
	unsigned char minutes10;       //data byte for 10minute section
	data=read_ds3231(0x08);        // read the second register
	minutes10=data&0b01110000;     //bitwise operation for 10min section
	minutes10=(minutes10>>4);      //bitwise operation to left to read out value
	minutes10=minutes10*10;        //give the real 10min value
	minutes=data&0b00001111;       //give the real minutes value
	ret=minutes10+minutes;         //minutes in unsigned char
	return ret;                    //retrun the value
}

// Proposal for new code:

uint8_t Bcd_To_Decimal( uint8_t data) {
    uint8_t ret;

    ret = byte >> 4;    // Get high nibble.
    ret *= 10;
    ret += byte &0x0F;  // Add low nibble.
    return ret;
}

uint8_t Read_A1M2_minutes(void) {

    return Bcd_To_Decimal( read_ds3231(0x08);       // read the second register
}

 

I also want to advise against writing too much comment.

Only write comment if it is usefull to add meaning to the code.

Writing comments like that is a waste of time to write.

Comment like below also distracts a human reading the code whichs wastes time every time anyone reads it.

It adds abolutely nothing usefull to the code it is supposed to comment.

And on top of that it has a typo.

	return ret;                    //retrun the value

Addition:

If you only write comments where they are usefull then you will motivate others (and yourself) to read it.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Mon. Jan 22, 2018 - 06:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Paulvdh wrote:
I think you should read a good C book.

+1

 

Most of your questions in recent threads would seem to be answered by a better understanding of the 'C' language - nothing to do with Atmel or microcontrollers.

 

Here are some 'C' learning & reference resources: http://blog.antronics.co.uk/2011...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

+1 on reading a good C textbook.

 

Here's a simple example you could do:

 

Start with an "empty" AVR project.

 

Add a global variable. Rebuild. Look at what happened with the memory report that comes out at the end of the build.

 

Add a variable local to a function. Build, look at the memory report.

 

Add a constant string that you use somewhere in your program (e.g. to send out on a USART). Bulid, look...

 

Add different types of variables globally, and locally to a function. Build, look...

 

Etc.

 


 

You seem to rely an awful much on assumptions and fixed ideas. Don't do that. Either find actual information by looking in reference material etc. Or do some good experiments.

 


 

Please tell us that the code you presented in your first post here isn't actually a "header file" (i.e. filetype .h and that you do #include it into other files). If so you have made an assumption about C tool chains that will eventually bite you firmly. When that happens, come back her and ask why you get "multiple definition" errors from the linker. ;-)

 

Rule of thumb is: Executable code goes into .c files that are compiled separately into .o object files. Those object files  are combined into one executable by the linker.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jan 22, 2018 - 08:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.avrfreaks.net/forum/explanation-avr-memory-usage

 

Here clawson said

Quote

"1,398 bytes of flash occupying 17.1% of the flash of the mega88.

 

The other figure is how much of the RAM will be used for linked variables that are positioned at compile time (but does not including anything for run time stack based usage). However as long as your Data: percentage remains below about 75% you should be OK and when it exceeds that look into using "PROGMEM" which shifts some things from RAM to be in flash only.

"

 

From this comment i come up with that my assumptions were right, my program is never using total of 240 bytes of ram that is what compiler sees as whole in program code.
But then if this assumption is right? what happens when compiler sees 100% data usage but in run time it is never %100?

Yes i might missed or forgotten about common basics of C but going back to reading C book from the beginning is much more of time loss than searching for solutions on forums/internet. Also while reading you do not encounter these kind of problems as you do when applying them.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yorem_kastor wrote:
Yes i might missed or forgotten about common basics of C but going back to reading C book from the beginning is much more of time loss than searching for solutions on forums/internet.

 

There are many here that would disagree with you on that.

 

yorem_kastor wrote:
Also while reading you do not encounter these kind of problems as you do when applying them.

By reading the book you should know how to spot these issues when you encounter them.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yorem_kastor wrote:
my program is never using total of 240 bytes of ram
Depends upon your meaning of "using"...

The compiler has "recognized" 240 bytes of ram usage (not including "automatic" variables).

 

Have you defined strings that are to be printed?

Unless they are assigned to PROGMEM, they will also consume RAM space and be included in the ram usage figure.

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yorem_kastor wrote:
From this comment i come up with that my assumptions were right, my program is never using total of 240 bytes of ram that is what compiler sees as whole in program code.

 

If the memory report in the build says 

 

yorem_kastor wrote:
Data Memory Usage : 240 bytes   11.7 % Full

then that is the minimum RAM that will be consumed during run-time. The compiler does not report RAM used for local variables in that number. The consumption caused by local variables is, by the very nature of it, quite hard to compute. Sometimes it's impossible.

 

Yous assumption "my program is never using total of 240 bytes of ram" is both correct and wrong. If you believe your program uses less than that, then you're wrong. It uses at least that much. In practice always more than that, so it does not use exactly 240 bytes and you're correct - but not in the way you think.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jan 22, 2018 - 08:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yorem_kastor wrote:
From this comment i come up with that my assumptions were right, my program is never using total of 240 bytes of ram that is what compiler sees as whole in program code.
JohanEkdahl wrote:
If you believe your program uses less than that, then you're wrong.

 

After taking the time to compose a lengthy response, did you take the small amount of time it will take to LOOK AT THE MAP FILE which will tell you what the toolchain put into the 240 byte total? 

 

Do it.  And/or paste that piece of the map file.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
yorem_kastor wrote: Yes i might missed or forgotten about common basics of C but going back to reading C book from the beginning is much more of time loss than searching for solutions on forums/internet.

 

It is much easier for you to offload the hard word to us reading your posts and answering all your questions...

 

Now for some homework:

Copy al the text of all the threads you started into a text file and multiply them all by the amount of time those threads have been "viewed".

Now go read them that many times yourself.

So only this tread you should read 50 times.

 

Read the topic Example, instead of DDRB=0xff; with #include
 ">Writing to registers in C without using any library
  279 times.

And so on...

 

Or get some good docuentation about C / C++ and read that.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yorem_kastor wrote:
going back to reading C book from the beginning is much more of time loss than searching for solutions on forums/internet

I missed this in your previous post (so thanks to Paul for making me aware of your attitude).

 

The reading of a well-written book will get you a whole and complete picture. The snippety nature of the Interweb gives you fragmented, possibly unrelated knowledge.

 

You are offloading your own work onto the Web community. Makes you look spoiled. Makes you look impatient. Makes you look like wanting special treatment.

 

Combine that with the cocky, hubris-like attitude (e.g. you show blatant ignorance re a lot of basic programming in C, but still mock the Arduino community for not knowing how to do things).

 

You need to straighten all this out or you will wear out your welcome faster than you wish.

 

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
I missed this in your previous post (so thanks to Paul for making me aware of your attitude).

Check post #7....wink

 

The author of that one was being unusually polite.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This topic has gone off from what i intended to me getting mucked and being bullied for what i do not know which i was in need of your help.My intentions were not to make fun of any community what so ever, i do not know why you generalized my words there.Who i meant was the people using ardunio boards using libraries connecting some wires and calling what they made I MADE just by following tutorials(Do you still think i am mucking anyone?). While a lot more questions still remain asked in badly manners like GIVE ME CODE, DO THIS FOR ME in past forum topics is it mine that gathered all the known people in this community to muck me around just for asking something simple with enough info provided about the question? 

 

Anyway i found why this is happening. I used some strings to write to lcd and they seem to be taking most of the ram and without any of those strings my ram usage is around 50byte as i guessed. I did not think that anonymous strings would take place in ram. Tell me this is something about C because i know it is not and it is AVR related. Also to be informative who encounters this kinda problem like me life of variables are as explained in ANSI C but strings acts different.I aslo edited to topic to life of variables + string exception for AVR

 

Here is a small part from my main in while loop i will use PROGMEM if i run out of ram but this seems to be not going to be case because i am nearly about be done with this after some tidy up. 

Komut(Sil);
		  Komut(BirinciSatir);
		  unsigned char writen_data;
		  VeriDizi("Enter alarm Hour");
		  while(1)
		  {
			  _delay_ms(500);
			  writen_data=0;
			  First_Digit_Alarm_Hour:
			  data=Scan_KEYPAD();
			  if(data==11) {goto End_Alarm_Hour;}
			  if(data!=99) {Komut(IkinciSatir); sprintf(clock_data,"%d",data); VeriDizi(clock_data); writen_data=data*10; _delay_ms(500);}
			  else {goto First_Digit_Alarm_Hour;}
			  Second_Digit_Alarm_Hour:
			  data=Scan_KEYPAD();
			  if(data==11) {goto End_Alarm_Hour;}
			  if(data!=99) {Komut(IkinciSatir+1); sprintf(clock_data,"%d",data); VeriDizi(clock_data); writen_data=writen_data+data; _delay_ms(500);}
			  else{goto Second_Digit_Alarm_Hour;}
			  if(writen_data>23){Komut(IkinciSatir+6); VeriDizi("Error"); _delay_ms(1000); Komut(IkinciSatir); VeriDizi("                "); writen_data=0; goto First_Digit_Alarm_Hour;}
			  else{Write_A1M3_Hour(writen_data);}
			  End_Alarm_Hour:
			  Komut(Sil);
			  break;
		  }......
		  
		   data=Read_day();
	  if(data==1){VeriDizi("Monday     ");}
	  if(data==2){VeriDizi("Tuesday     ");}
	  if(data==3){VeriDizi("Wednesday     ");}
	  if(data==4){VeriDizi("Thursday     ");}
	  if(data==5){VeriDizi("Friday     ");}
	  if(data==6){VeriDizi("Saturday     ");}
	  if(data==7){VeriDizi("Sunday     ");}

 

 

And about my old topics i asked whether returning 1 or 0s had special meaning for atmel studio and yet again i was mucked for not knowing what return does, how could i write my own NRF library if i had not known this very basic thing. On the other topic i asked how could i write to registers directly for a startup guide but yet again was mucked. As most of you said if i were to reading a C book right now probably i was still reading not knowing why this is happening.(Please do not take this as personal but this is the truth that no only for C would answer this)

 

I sense some threat in your comment the one that i seen in many forums i participated but i did not expect i would come across one in technology related forum.

I apologize for questions i asked and offloading the forums with my cocky, hubris-like attitude i will no longer post or contribute/participate in this community. Thank you for your toleration.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If YOU would have simply followed some very good advice and looked in your MAP file you would have had your answer.  YOU chose otherwise.

 

yorem_kastor wrote:
i will no longer post or contribute/participate in this community.

Until you do not feel like reading a book because it's a waste of time?

 

I wish you all the best in your quests.  Be well

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, Yorem -

 

I think you are seeing criticism where there really is not so much. I have read your posts and the responses but have stayed pretty much out of things, just watching. 

 

What conflict that we do have seems to be more of style than substance. There seem to be particular things and ways that you want to follow, but these often a more than a bit different from the perceived wisdom of those who are more experienced. I have often been in a similar situation in the group, but with a difference - I come because I want to learn and I am willing to discard ideas that are not so useful in exchange for things that will work. I truly believe that approaching things this way will benefit me much more, in the end, than being dogmatic about what I am trying to do. This is just my personal opinion and my "style". 

 

Lets consider the question that you started this thread with. Persistence of variables is a standard topic for every C-language reference I have seen. I was amazed that you seem to ask such a question without looking it up first. I expected to see statements like "I looked it up on StackOverflow and it said ----. Is that really correct?" A statement like that shows that the poster really has done a bit of searching but is confused or uncertain about the information that was found. Eight posters will be happy to give you 10 different answers to any question like that. What does seem to upset folks is lack of even attempting to find an answer, on your own. 

 

Your question about memory usage of strings is one of those things that constantly trips up people, here. It points at something that is in the C standard. Some details are listed as "implementation dependent" and this may be one of them (not really sure). But, there are many threads, here, on exactly this subject. Again, if you had looked, it probably would have been likely that you would have found at least one of them and would understand how they use RAM. Then, there would have been no great surprise. Those same threads would have, most likely, also showed you how to avoid the ram usage. Its not rocket science. 

 

So, when you detect hostility, please understand that it is much more about not looking for answers first, then coming here for clarification. Frankly, I don't see the hubris that you mention, nor cocky, nor the other things you point to.

 

Cheers and very best wishes

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Usually we are regarded as a quite friendly community.

There is obviously some kind of mis-communication going on here.

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what does ‘mucked’ mean? It doesn’t translate into my vocabulary. It it started with an ‘f’ it might be somewhat more meaningful but the context of usage doesn’t fit.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.thefreedictionary.co...

muck
Also found in: Thesaurus, Medical, Legal, Financial, Acronyms, Idioms, Encyclopedia, Wikipedia.
Related to muck: muck up, muck soil
muck  (mŭk)
n.
1. A moist sticky mixture, especially of mud and filth.
2. Moist farmyard dung; manure.
3. Dark fertile soil containing decaying vegetable matter.
4. Something filthy or disgusting.
5. Earth, rocks, or clay excavated in mining.
6. The pile of discarded cards, as in poker: threw his hand into the muck.
v. mucked, muck·ing, mucks
v.tr.
1. To fertilize with manure or compost.
2. To make dirty, especially with muck.
3. To remove muck or dirt from (a mine, for example).
4. To fold (one's hand) in a card game, especially by pushing one's cards away.
v.intr.
To muck one's hand in a card game.
Phrasal Verbs:
muck about Chiefly British
To spend time idly; putter.
muck up Informal
To bungle, damage, or ruin.

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rats - just typed a long explanation of PROGMEM/__flash/etc and how to avoid too much _do_copy_data() only to have the cat stand on the keyboard and erase it just before I posted. Ho hum!

 

Bottom line is that AVR is Harvard not Von Neumann and the C compiler has to make some assumption about default address space and so it assumes (because most/many data in a program are mutable) that the default is RAM not flash.

 

Use PROGMEM (old C compilers and still in C++) or __flash to coerce data into flash only space (no _do_copy_data()) then either implicitly (__flash) or explicitly using pgm_read_byte() etc for PROGMEM arrange for the (immutable) data to be accessed using LPM rather than the default LD/LDS.

 

Also for anonymous strings use PSTR() and if using printf()/sprintf() switch to printf_P()/sprintf_P().

 

If using your own print routine like VeriDizi() then you either need two variants (convention would suggest VeriDizi() and VeriDizi_P()) or the single routine must be modified to take a pointer to flash rather than pointer to RAM (and then dereference the pointer in the correct way).

 

(wish I hadn't lost the long version of this!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

muck = mess

 

as in...

 

he mucked me around = he messed me around = he wasted my time

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Somehow i think i was taken too literally. I understand the usual use of ‘muck’. Maybe I’m getting mucked and bullied? Or i need more hubris with my cornflakes......