MANAGING LARGE NO OF VARIABLE

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

Dear All,

 

I am working on a DAQ project and I have to manage 100 global variable for MODBUS. I read some manual of VFD having address more then 400 address, so please suggest how to manage this no of variable on micro controller like ATMEGA128. 

This topic has a solution.
Last Edited: Fri. Apr 27, 2018 - 02:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounds like you need to explore Structures.

#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

400 x 2 = 800 bytes. (Modbus regs are 16bits). Mega128 ram is 4096 bytes. I cannot ser a problem here.
Why does the mega128 need to store the registers of the VFD? I would expect many of those are configuration.

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

Sounds like you need to explore Structures.

Or at least arrays.

 

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

I need to only 100 to manage . So any example ??

 

Last Edited: Fri. Apr 27, 2018 - 06:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Example of what? You’ve not told us much.

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

As the others have said, it's not at all clear what you're asking for!

 

What do you mean by, "manage" ?

 

Why do you see that as a problem?

 

Arrays and structures have been mentioned - you do know what they are, don't you?

 

A common approach when something seems overwhelming - like one hundred variables surprise - is to just think about how you'd do it with a smaller, less daunting, number.

 

So why not try it with just, say, five variables?

 

Start by just implementing it a five separate, individual, variables.

 

Then look for common stuff, and think how you could generalise - this is where the arrays and/or structures could come in ...

 

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

Sorry 

I not clear my point. As I told I am working on DAQ and I have to connect it using MODBUS. For example I give address of 0X1FF and it go upto 0X2FF for different parameter so in this example I have to manage nearly 250 variable in my program. I found this is difficult to manage and transfer it on MODBUS or GPRS.  I want too know what data structure is used for this type of application. Is array or struct is sufficient???  or any other method

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

No, that doesn't clarify anything at all!

 

samic45mit1 wrote:
I found this is difficult to manage and transfer it on MODBUS or GPRS. 

Why did you find it difficult, exactly?

 

What problem(s), exactly, did you find?

 

At its simplest, managing 250 variables is no harder than managing a single one - you just do the same thing 250 times!

 

So where are you stuck?

 

Again, if you find the large number daunting, why not just start out with a smaller, less daunting number?

 

Why not try it with just, say, five variables?

 

Start by just implementing it as five separate, individual, variables.

 

Then look for common stuff, and think how you could generalise - this is where the arrays and/or structures could come in ...

 

 

I want too know what data structure is used for this type of application

This has already been answered - several times

 

Is array or struct is sufficient?

That is what everybody has suggested - isn't it?

 

So think about the distinguishing features of arrays and structures - which is most appropriate or helpful to your task ... ?

 

This is a basic software design exercise - nothing specifically to do with AVR or Modbus...

 

EDIT

 

This couple of chapters from am online 'C' textbook might help:

 

Arrays: http://publications.gbdirect.co.uk/c_book/chapter5/

 

Structures: http://publications.gbdirect.co.uk/c_book/chapter6/

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...
Last Edited: Fri. Apr 27, 2018 - 11:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

samic45mit1 wrote:
I found this is difficult to manage
Like Andy I haven't a clue what you mean by this. Either you have 250 variables all of the same type so if you had something like:

char c0;
char c1;
char c2;
char c3;
etc.

then clearly the way to manage that "better" is to create an array such as:

char c[250];

and now you can easily access char[3] or char[81] or whatever and if you need to perform the same task on all the variables you can just use a for() loop to iterate over the data.

 

If on the other hand your 250 variables are different kinds of data:

int vol;
unsigned char pressure;
long overflow_limit;
unsigned short wheel_speed;

then the obvious this to do to "keep them together" and, more importantly, "keep them in the right order" is to use a struct:

struct {
   int vol;
   unsigned char pressure;
   long overflow_limit;
   unsigned short wheel_speed;
} modb_vars;

if it's the case that you first receive an "annonymous" buffer of 250+ bytes and then you need to apply this interpretation to them you do something like:

typedef struct {
   int vol;
   unsigned char pressure;
   long overflow_limit;
   unsigned short wheel_speed;
} modb_var_t;

uint8_t buffer[250];

modbus_receive_vars(buffer);

modb_var_t * pVars;

pVars = (modb_var_t)buffer;

if (pVars->overflow_limit > 0xBABEFACE) { ...
etc.

But, really, you are a not giving enough information about what it is you want to achieve and the problems you are facing in doing that so the above are just guesses at possible suggestions until you can describe your situation in more detail.

 

BTW you seem to be assuming we all know what "DAQ" means. I have no idea. If it's a well known format/protocol/whatever perhaps provide a link to what it is you mean?

 

PS a quick google suggests that the DA in DAQ may have something to do with "Data Acquisition" but my google-fu is not good enough to locate what the Q bit stands for.

Last Edited: Fri. Apr 27, 2018 - 11:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
you seem to be assuming we all know what "DAQ" means

 

Indeed (s)he is.

 

I'm guessing at "Data AcQuisition [system]" - but who knows ...

 

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

 manage 100 global variable

     Maybe the question is more referring to using the display with menus, such as:

If I had a hundred parameters to view & adjust on a display, how do would I create display menus and such to select the value(s) display, and adjust them?

 

Of course then it would be nice to know specifically what display is being used.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

But #8 talks about transferring the data over MODBUS and GPRS.

 

MODBUS does seem to be the focus.

 

Anyhow - apparently it is solved now

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

Anyhow - apparently it is solved now

That seemed too easy   surprise

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!