Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

fifo buffer in c for msp430??

Status
Not open for further replies.

skarthikshines

Member level 5
Joined
Feb 21, 2011
Messages
81
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
2,060
hi all ..


anybody please suggest me to how to write a FIFO buffer for size of (1024) in c for my msp430controller??? and also i need to know what care should i take while am choosing a particular controller in msp430 family..??
 

well,
msp430 does not support external memory addressing, meaning if you need more memory you will have to interface it yourself with a cost of both GPIO's and efficiency...
so, either you choose a msp430 series with enough ram for your needs, or you will have to use external memory... there are IC's that provide lot of solutions on this subject.. you can have them interfaced by a bus, or by SPI or I2C. I've suggested that FIFO as an example for an DAC or ADC bus interfacing...

sorry, but I don't know much more about the subject... If ram is really an issue you should have a look on ATmega uC... I know there a few models that support external memory addressing..
 

well,
msp430 does not support external memory addressing, meaning if you need more memory you will have to interface it yourself with a cost of both GPIO's and efficiency...
so, either you choose a msp430 series with enough ram for your needs, or you will have to use external memory... there are IC's that provide lot of solutions on this subject.. you can have them interfaced by a bus, or by SPI or I2C. I've suggested that FIFO as an example for an DAC or ADC bus interfacing...

sorry, but I don't know much more about the subject... If ram is really an issue you should have a look on ATmega uC... I know there a few models that support external memory addressing..
thanks for valuable commands.. my doubt is how to choose ram size.. for example if i want to store 1024 value in buffer. each value size will be in 2byte so my ram size should be more than 2k byte (1024x2=2048)..
am i wright??
 

That is true if you are allocating words on 1024 array...

But a FIFO is a linked list...
each node is a struct with the value and a pointer to next value


Code C - [expand]
1
2
3
4
5
struct fifo_node
{
  struct fifo_node *next;
  value_type value;
};



meaning each node will use
total_node_size = sizeof(struct*) + sizeof(value_type);

since in msp430 the size of a pointer is 16 bits,

your fifo of words will need 1024 * 2 *2 byte, plus two words for start of list pointer, and last node pointer;
so , at least 4096 + 4 bytes for the fifo
 
Last edited:

why can t we use FIFO by means of array?? what s the advantage of using structure instead of array??
 

well, if is an array, is not a fifo =);

the advantage of the struct is that the data does not need to use sequential physical positions on the memory, so you can add nodes in any free position available, or delete nodes this way having a dynamic size... to do that with an array, you will have to copy the full modified array to another place in memory (than you still using the double of the memory and plus, it need to be sequential free space).. anyway, you wouldn't have that problem since you are using a fixed size array, but you will have a processor overhead while processing the reorganization of the list when it changes) ... for example if you have 1000elements, each time you eliminate one element you will have to reorganize 999 elements... no problem if processor efficiency is not an issue for your application, but when it comes about FIFO's it usually is...


_______
I'm sorry, I'm feeling quite stupid now... I totally forgot that with a fixed size you can have a "ring FIFO", https://en.wikipedia.org/wiki/Circular_buffer , (.. this way the array is a good option.. only need to check the overflow...)

so with ring fifo, you only need
2048 + 2 for buffer array
2 for current last position
2 for current first position
 
Last edited:
well, if is an array, is not a fifo =);

the advantage of the struct is that the data does not need to use sequential physical positions on the memory, so you can add nodes in any free position available, or delete nodes this way having a dynamic size... to do that with an array, you will have to copy the full modified array to another place in memory (than you still using the double of the memory and plus, it need to be sequential free space).. anyway, you wouldn't have that problem since you are using a fixed size array, but you will have a processor overhead while processing the reorganization of the list when it changes) ... for example if you have 1000elements, each time you eliminate one element you will have to reorganize 999 elements... no problem if processor efficiency is not an issue for your application, but when it comes about FIFO's it usually is...


_______
I'm sorry, I'm feeling quite stupid now... I totally forgot that with a fixed size you can have a "ring FIFO", https://en.wikipedia.org/wiki/Circular_buffer , (.. this way the array is not a good option.. only need to check the overflow...)

so with ring fifo, you only need
2048 + 2 for buffer array
2 for current last position
2 for current first position



hi ..
I tried the coding by means of array its working properly but the problem is if my array size is 1000 value means after reading the one value from FIFO i need to swap the array location .. so for this it s taking large time.. so i thought to use external fifo memory..so please guide me regarding how to interface external FIFO buffer with msp430. Is there any sample code is available for interfacing FIFO??
 

I'm sorry,
I mean to say that the array is a good option (in my last post that is quoted above, witch I've just corrected)... my bad..

I know of any example for interfacing fifo in msp430... but if you search this forum you will find some examples on other uC

Regards,
 
Hello!

The most difficult about giving you advice here is that we don't know what you are planning to do.
From my point of view, MSP430 is a low power device and it has been designed to drive a whole
system from a single chip. Therefore, if you need external memory, probably you should use another
device, possibly Stellaris if you want to stick to TI.
The MSP430 series have limited internal RAM. So I think the above mentioned solution is just a loss
of memory. You need 1024 samples, and you end using twice the space. So you should use this
solution only if it's absolutely necessary. Once again, I don't know the application and therefore
cannot rule out this solution. For instance, if you want to perform an operation of all the members,
be aware that the access to myfifo->next will take more time than the access to an array (indirect
addressing). Even if it's only a few clocks, it will be multiplied by the number of samples.

Now if you use external devices, be aware that accessing the external device will also take more
time than accessing the RAM directly. If you add to that more hardware complexity, more power
consumption, I think you may consider another solution.

hi ..
I tried the coding by means of array its working properly but the problem is if my array size is 1000
value means after reading the one value from FIFO i need to swap the array location ..
so for this it s taking large time.. so i thought to use external fifo memory..so please guide me
regarding how to interface external FIFO buffer with msp430. Is there any sample code is available
for interfacing FIFO??

You mean that you are shifting all the array by one sample?
Of course, you should NEVER shift an array, but use a pointer to the array.
Example:

Code:
#define BUFSIZE 1024
uint16 MyBuffer[BUFSIZE];
uint16 * read_ptr;
uint16 * write_ptr;

At start, you do:

Code:
    read_ptr = MyBuffer;
    write_ptr = MyBuffer;

If you want to write a value:

Code:
    *write_ptr = new_val;
    write_ptr++;     // By the way, you can do directly *write_ptr++ = new_val, but this might be better at debug time
    if(write_ptr >= MyBuffer + BUFSIZE) write_ptr -= BUFSIZE;

If you want to access a value:

Code:
    val_to_read = *read_ptr;
    read_ptr++;     // By the way, you can do directly val_to_read = *read_ptr++, same as above
    if(read_ptr >= MyBuffer + BUFSIZE) read_ptr -= BUFSIZE;

With this method, (called circular buffer and mentioned a few posts earlier by mgate), you never have to copy data.
Copy takes time, so it should absolutely be avoided.
Careful: you should make sure that you don't read faster than you write. And not slower either. This
security processing is not written in the above code.

Dora.
 
[/COLOR]thanks lot dora.. its working properly and not taking too much time as like array... one more thing now am selecting the micro controller having 8k internal RAM..whether its enoughy for my 1024 samples ??how can i verify this?? and how can we check it in compiler how much memory occupied by our coding after writing the code.. (am using code composer studio)..



Careful: you should make sure that you don't read faster than you write. And not slower either. This
security processing is not written in the above code.

Dora.[/QUOTE]

what care in coding i have to take here??
 

You need to protect buffer over-run and buffer under-run... Basically you need to check if is empty before reading and check if is full before write, otherwise you will end up collecting garbage (risk of overwriting older data, or reading older "erased" data)...

One easy way is keep track of the buffer size...


_________
By the way, I thought you where already implementing the circular buffer when you first said it was working... I'm sorry if that array explanation got you confused... (It was just valid for dynamic allocation size buffers...)
 
Last edited:

Hello!

whether its enoughy for my 1024 samples ??how can i verify this??

skarthikshines, nobody can reply this question because you don't give any information about what you
want to do. The only thing you are saying is that you want a FIFO on MSP 430, therefore so far you
got replies according to what you ask. You have been talking about 1024 samples, I cannot tell you
whether it's enough or not. But the best thing to do is to think about it yourself. You sample something,
you have a given sample rate, you get outputs, and you get some processing in between, so you
just have to verify that at any time you will have just enough samples buffered (more would be a loss
of space, too few would yield problems of garbage as explained above).

Dora.
 

ok dora. i agree with your reply.. but after finishing the total project code with the help of compiler is there any thing possible to know my code size and memory utilization of my code ..(am a beginner that's why asking this kind of questions)
 

Hello!

is there any thing possible to know my code size and memory utilization of my code

As for the code size, there should be a way to get that information from the IDE.
But when you are running in debug mode, you can also view the memory. With IAR, you can
directly choose to show either the RAM or Flash, etc. If you have a flash view, you can
easily scroll it to see at which point there are only 0xFFs (i.e. flash not used).

As for the RAM size, you should know it. It depends directly on how many variables you use.
Be aware that you need to leave some space for the stack. But the compiler will tell you
anyway if you don't.

Dora.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top