Pages: [1]   Go Down
Author Topic: RAM address overflow?  (Read 1118 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: July 17, 2013, 08:48:30 am by MathiasVDA » Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10466
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it is ok unless the module has less ram than the overflow value.
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

thanks!
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10466
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well 4294967296  - 125K = your starting value... just remember to subtract it every time smiley
Better: address_mod = address-(address/125000)*125000;

:-)
« Last Edit: July 16, 2013, 05:37:07 pm by MathiasVDA » Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10466
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i think you mean
Code:
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:
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.
« Last Edit: July 17, 2013, 04:40:28 am by lesto » Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i think you mean
Code:
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:
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
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10466
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10466
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if your time limit is 5ms just use the method you prefer.
Code:
address_mod = address % 125000;
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Sr. Member
****
Karma: 11
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 106
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 11
Posts: 330
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
}
« Last Edit: July 23, 2013, 03:07:50 pm by Mr_arduino » Logged

Pages: [1]   Go Up
Jump to: