Pages: [1]   Go Down
Author Topic: Memory Allocation  (Read 964 times)
0 Members and 1 Guest are viewing this topic.
bangalore
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Folks,

1. I'm having a doubt, where does the program downloaded to Arduino go and sit in the memory?
2. I understand that evry time we download a new program into the Arduino, it will go overwrite the old program and make a seat for it in the memory. Am I correct?
3. Is there any possibility to store two different programs in different memory locations of Arduino and let them exectute one after the other during operation?

can somebody help me with this stuff?


thnx,
chiru
Logged

chiru

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Hey,

1. I'm having a doubt, where does the program downloaded to Arduino go and sit in the memory?

I don't understand.

Quote
2. I understand that evry time we download a new program into the Arduino, it will go overwrite the old program and make a seat for it in the memory. Am I correct?

Correct.

Quote
3. Is there any possibility to store two different programs in different memory locations of Arduino and let them exectute one after the other during operation?

Yes.  That's exactly how the bootloader works.
Logged

bangalore
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But bootloader is like unaccessble part of a program sitting and doing its work in the controller. Like-wise can i make my sketch into two parts so that part -1 runs first and then part-2
Logged

chiru

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
like-wise can i make my sketch into two parts so that part -1 runs first and then part-2
Yes, they're called "functions".
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6373
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there any possibility to store two different programs in different memory locations of Arduino and let them exectute one after the other during operation?
Theoretically possible, but not "easy" and not within the Arduino environment.
And you'd need essentially a third program to figure out which of the other two to run, and when.  An "operating system."

I think "bitlash" can do this for it's interpreted "programs."
FORTH can do it.  sort of.
Logged

bangalore
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can i try this way?, i shal define my two programs in different functions and can i terminate the program as and when i needed?( i would give a condition, if it reached, second function will execute else terminate the complete program).
Logged

chiru

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16523
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can i try this way?, i shal define my two programs in different functions and can i terminate the program as and when i needed?( i would give a condition, if it reached, second function will execute else terminate the complete program).

Sure. However you can never truly 'terminate' the complete program, but what you would do would be to perform the statements to cause the program to run an endless do nothing loop and doing nothing but looping until the chip is reset or powered off and on. there is no halt instuction in the AVR machine language.

while(1) { }    that is an example of a do nothing loop that won't stop until the chip is reset or power cycled.


 
Logged

bangalore
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that would be helpful. i shall try this way. thnq Lefty.
    Now one moe thing i should worry about is, is there any way that i cut run two sections parallelly?

Let me put it in  this way, section-1 would get the data from sensors and go after some mathematical calculations and repeat the same.
    section-2 would print the results obtained from section-1 on serial moniter and output some through the pins.

Its not an issue even if its not the current data. its ok even if it can communicate the past data through section-2
Logged

chiru

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16523
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that would be helpful. i shall try this way. thnq Lefty.
    Now one moe thing i should worry about is, is there any way that i cut run two sections parallelly?

Let me put it in  this way, section-1 would get the data from sensors and go after some mathematical calculations and repeat the same.
    section-2 would print the results obtained from section-1 on serial moniter and output some through the pins.

Its not an issue even if its not the current data. its ok even if it can communicate the past data through section-2


I think you are thinking wrong about 'sections' and 'programs'. It's very possible and desirable to think about just one overall program, the sketch, that can do all though tasks at the proper time all under your single program's control. It's called program structure and the programming language gives you all the commands needed to structure the control of your one large program that performs as many different task when and only when you need them to be performed.

 You limiting your thinking and learning with this seperate programs/sections and running them parallelly.

Lefty
Logged

bangalore
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 You limiting your thinking and learning with this seperate programs/sections and running them parallelly.



let us forget about sections. could u plz tell me if i could get things done parallelly in a single program? becoz the execution time is crucial for me

chiru
Logged

chiru

Greenville, IL
Offline Offline
Edison Member
*
Karma: 11
Posts: 1309
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 You limiting your thinking and learning with this seperate programs/sections and running them parallelly.



let us forget about sections. could u plz tell me if i could get things done parallelly in a single program? becoz the execution time is crucial for me

chiru

 It depends on what functions you are try to run. Examples: Pins can maintain status while other actions occur.  However, some things like writing to an SD card need a small block of time to complete. Serial communications requires a bit of time to complete. You can blink many LEDs on an off so, quickly that they appear to be lit continuously.

 Most of the time the processors runs so quickly, that the user can not perceive any delay between actions. 
Logged


South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1023
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It sounds like you are trying to aquire some data, manipulate it and then output the results. That could be considerred 3 main steps -

You would write 3 functions


void getdata() {
}

void manipulatedata() {
}

void outputdata() {
}

and inside of loop you would do something like this

void loop() {

   whatever code needs to run before you aquire data or to time the data aquisition..   

   getdata;
   manipulatedate;
   outputdata;
   

   other code you want to run..
}

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
let us forget about sections. could u plz tell me if i could get things done parallelly in a single program? becoz the execution time is crucial for me
You keep going on about that, but you never specify in what way it is critical, or by how much you're missing the mark.
Until you come up with specifics (code, timings and specifications), you're just wasting everyone's time.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You keep going on about that, but you never specify in what way it is critical, or by how much you're missing the mark.
Until you come up with specifics (code, timings and specifications), you're just wasting everyone's time.

exactly, even if it was executed in parallel your using a single processor, and multitasking is really just an illusion of switching priorities, even in multicore super nasty high speed computers of today, its sharing resources and must wait in que at some point.
Logged


Pages: [1]   Go Up
Jump to: