data storage and retreival -from newbie

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

Hi,
Im using a Mega 48 to control some mechatronics bits and bobs, and I'd like to store results from an AtoD Conversion, say 10 or 20 results, then retreive them and do some maths with them, for example find the average. The storage can be in the on board RAM I guess.
I've never used memory for this type of application before and I'm not sure how to go about it, if there is for example a conventional way in C.
I've used some excellant tutorials on other subjects butc an't find one on this.
I'd realy appreciate any suggestions or guidance of where to look or how to do it.
Thanks
Mark

markah

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

Quote:

if there is for example a conventional way in C.

Just read about "array"s in your C manual. For example:

uint8_t data[10];

int main(void) {
  uint8_t i;
  uint16_t total = 0, average;
  for (i=0; i<10; i++) {
    data[i] = read_value();
  }
  for (i=0; i<10; i++) {
    total += data[i];
  }
  average = total / 10;
}

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

Many thanks, I think I get it. Needed the pointer though :-]

markah

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

Quote:

Needed the pointer though :-]

There's a rather wonderful pun sitting in there somewhere but I won't point it out at this early stage as it'll just add confusion ;-)