Go Down

Topic: RAM address overflow? (Read 1 time) previous topic - next topic

MathiasVDA

Jul 16, 2013, 04:37 pm Last Edit: Jul 17, 2013, 03:48 pm by MathiasVDA Reason: 1
Hello all,

I think I know the answer to this question but just to be sure I'd like to know your opinion. I'm adressing an external 23LC1024 SRAM by SPI and use a function that sends a uint32_t as address for the byte to be stored/retrieved. I would like to take samples every 5 ms and fill the memory that way. Is it ok if I just let the address uint32_t overflow to restart from zero?

thanks!

lesto

it is ok unless the module has less ram than the overflow value.
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

MathiasVDA

Ok stupid me, so it is a problem because uint32 goes up to 4294967296 and I only have 125k addresses... :smiley-mr-green:

thanks!

lesto

well 4294967296  - 125K = your starting value... just remember to subtract it every time :)
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

MathiasVDA

#4
Jul 16, 2013, 11:56 pm Last Edit: Jul 17, 2013, 12:37 am by MathiasVDA Reason: 1

well 4294967296  - 125K = your starting value... just remember to subtract it every time :)

Better: address_mod = address-(address/125000)*125000;

:-)

lesto

#5
Jul 17, 2013, 11:33 am Last Edit: Jul 17, 2013, 11:40 am by lesto Reason: 1
i think you mean
Code: [Select]
address_mod = (address-(address/125000))*125000;

but i can't understand how it should work. Imho you are tryng to do somethink like the map(), so it is

Code: [Select]
address_mod = address*(MAX_address/125000);

but that way every access to RAM have a multiplication with long (witch is really slow, because the chip "think" in 8bit and not 64bit), withg the starting value you have just a "if" in the best case (witch is really fast)

BTW i can't find anywhere your chip's datasheet.
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

MathiasVDA


i think you mean
Code: [Select]
address_mod = (address-(address/125000))*125000;

but i can't understand how it should work. Imho you are tryng to do somethink like the map(), so it is

Code: [Select]
address_mod = address*(MAX_address/125000);

but that way every access to RAM have a multiplication with long (witch is really slow, because the chip "think" in 8bit and not 64bit), withg the starting value you have just a "if" in the best case (witch is really fast)


address is an uint32_t. So when I calculate address/125000, it gives me an int in return that i can use to multiply 125000 and make sure address_mod is again in the limits of my SRAM memory. No 'long' involved. I'll check out the map function.


BTW i can't find anywhere your chip's datasheet.

Sorry, i meant chip 23LC1024. Little error in my first post. Here is the datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/25142A.pdf

MathiasVDA

It's not like the map() function because:

Adresses from 0 -> 124.999 need to be what they are and don't get modified
Adresses from 125.000 -> 2^32 need to be substracted by x times 125.000 in order to get the right address. x is the amount of times the address can be lowered by 125k without turning negative.

lesto

i've understand your logic, should work but is expansive, as you do 2 multiplication, also you still have to use long.

but from datasheet:
Quote
Sequential Operation
- is selected when bits 7 and 6
in the MODE register are set to
01
. Sequential opera-
tion allows the entire array to be written to and read
from. The internal address counter is automatically
incremented and page boundaries are ignored. When
the internal address counter reaches the end of the
array, the address counter will roll over to
0x00000
(
Figure 2-5
,
Figure 2-6
)


can this be usefull? but you will not know when the overflow occurr. At the end of the write you can read the actual adress value (i think it is the first free, maybe the last used, take to look at DS)

interanlly it rool back to 0x1FFFF, so you can use bitmask to hide the first 14bit of uint32
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

MathiasVDA

Ok maybe that (being a slow function) might explain some crashes I'm experiencing.

If I understand the documentation correctly then you need to keep pin CS low, thus keeping that SPI device selected, in order to use the sequential mode. I need the SPI for other devices also. I'm taking measurements every 5ms and safe those to the RAM.

Is there someway I can convert the address faster to the proper limits?

lesto

if your time limit is 5ms just use the method you prefer.
Code: [Select]
address_mod = address % 125000;
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Mr_arduino

No there is a much easier way just put the 23LC1024 into sequential mode and it will increment for you it will also roll over for you see the data sheet
http://ww1.microchip.com/downloads/en/DeviceDoc/25142A.pdf
All you have to do is send data no need to send the address ever time just once at the beginning.

MathiasVDA


No there is a much easier way just put the 23LC1024 into sequential mode and it will increment for you it will also roll over for you see the data sheet
http://ww1.microchip.com/downloads/en/DeviceDoc/25142A.pdf
All you have to do is send data no need to send the address ever time just once at the beginning.


Thank you mr. arduino for your comment but lesto already told me about this. However I do not think I can use it as I need to address other SPI devices at the same time. And I'll need the adresses of the data I'm writing to.

Mr_arduino

#13
Jul 23, 2013, 10:05 pm Last Edit: Jul 23, 2013, 10:07 pm by Mr_arduino Reason: 1
No lesto did not already tell you about that. What this mode does is you first send the mode then you send the address after that you send the data and you don't have to send the address for every byte. The ram chip increments for you. Here is some sample code for the arduino uno. I do not like the spi library so I just made my own. If you are using the arduino ide change int main to void setup
Code: [Select]

#include <avr/io.h>
inline void spiWrB(uint8_t dat){
SPDR = dat;
while(!(SPSR & (1<<SPIF))) {}// Wait for transmission complete
}
inline void spiCSt(void){
//toggles spi CS used for reseting sram
PORTB|=4;//cs high pin 10
PORTB&=~4;//cs low
}
int main(void){
SPCR=80;//spi enable master
SPSR=1;//double speed
spiCSt();//this needs to be called before sending the mode byte
spiWrB(2);//sequental write mode change to 3 for read mode
spiWrB(0);//24 bit address
spiWrB(0);
spiWrB(0);
uint32_t x;
uint8_t y=0;
for (x=0;x<131072;++x)
spiWrB(y++);//see we don't have to send the address x everytime the external ram auto incrments the address for us
while(1){}//ram is filled
}

Go Up