Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

EEprom viewer

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Peter Huijssen

Bascom Member



Joined: 09 Apr 2004
Posts: 49

netherlands.gif
PostPosted: Sun Sep 29, 2024 7:46 pm    Post subject: EEprom viewer Reply with quote

Hello,

In order to increase EEprom writecycles I'm trying to built 32 circular buffers with 8 positions each to store 32 variables in ERAM using an ATtiny84.
I do this to declare a 2-dimensional array :

Code:
Dim Ring_buffer(32 , 8) As Eram Byte  


I can init the buffers to a certain value.

Code:
Sub Init_buffers


Local Prst As Byte
Local Pos As Byte


  For Prst = 1 To 32

    For Pos = 1 To 8
      Ring_buffer(prst , Pos) = 9                                               'all positions to reset value
    Next Pos

  Next Prst

  Init_done = 1                                                                 'init done

End Sub
 


My first question is : is it possible to see in Bascom where in the eeprom all the individual bytes are. Like a memorymap for the eeprom?
With Atmel studio I can read back the whole eeprom but it's really confusing to see whats what.
I was expecting adres 0 -7 = buffer1, 8-15 = buffer2, etc.

Best regards,

Peter

(BASCOM-AVR version : 2.0.8.6 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Sun Sep 29, 2024 8:24 pm    Post subject: Reply with quote

use the simulator. it will show where you write.
_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Sun Sep 29, 2024 10:41 pm    Post subject: Re: EEprom viewer Reply with quote

Peter Huijssen wrote:
Code:
Dim Ring_buffer(32 , 8) As Eram Byte  

With Atmel studio I can read back the whole eeprom but it's really confusing to see whats what.

Your confusion may result out of the internal mapping of the two-dimensional array into the one-dimensional EEPROM memory range.
Look up the help for "Dim" and there for arrays, which shows internal representation.

This means a Dim Ring_buffer(x , y) will have first the "x"'s in row indexed by the "y"'s, for functionality of your code it makes no difference, but if you nonetheless expect
Quote:
I was expecting adres 0 -7 = buffer1, 8-15 = buffer2, etc.

you better dimension it different and change your code accordingly
Code:
Dim Ring_buffer(8 , 32) As Eram Byte

Btw.
albertsm wrote:
use the simulator. it will show where you write.

Between the simulator's EEPROM representation and the one of a memory window within the mentioned Atmel Studio is only a marginal design difference, but none in functionality.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Mon Sep 30, 2024 12:35 pm    Post subject: Reply with quote

Quote:
Between the simulator's EEPROM representation and the one of a memory window within the mentioned Atmel Studio is only a marginal design difference, but none in functionality.


The TS wrote : With Atmel studio I can read back the whole eeprom

So i understood he was downloading it. Not simulating the write to see where is written what.

_________________
Mark
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Mon Sep 30, 2024 3:37 pm    Post subject: Reply with quote

albertsm wrote:
The TS wrote : With Atmel studio I can read back the whole eeprom

So i understood he was downloading it. Not simulating the write to see where is written what.

If the TO would need to look into the downloaded EEPROM file, then he needs an Intel-Hex viewer.
Another option is to use the Studio's simulator and via Debug --> Up/Download Memory, upload the downloaded EEPROM data and show it within a memory window.
At least it is this way in AVR Studio 4.

Of course I understand your suggestion by running the code within simulator and check the EEPROM tab.
This works because of the simplicity of code, it can be expected 100 percent that data representation looks identical to real hardware.

The words "reading back" in this context are in fact ambiguous and surly I did expect from somebody using Atmel Studio to be aware it displays EEPROM data.
Quote:
...but it's really confusing to see whats what. I was expecting adres 0 -7 = buffer1, 8-15 = buffer2, etc.

My guess was the TO is puzzled because his 8 byte data block gets scattered all over the array, first block bytes at positions 0, 32, 64, 96, ...
Which however can be easily fixed by Dim'ing the consecutive byte-block index first.
Back to top
View user's profile
Peter Huijssen

Bascom Member



Joined: 09 Apr 2004
Posts: 49

netherlands.gif
PostPosted: Mon Sep 30, 2024 3:46 pm    Post subject: Reply with quote

Thank you Albert and MWS,

I was to focussed on the expected mapping of the EEprom and I had a bug in my testsoftware.

Knowing what to look for I did a simple test :
Fill buffer(1,pos 1-Cool with 01, buffer(2,pos 1-Cool with 02 etc. and it all became clear.

Code:
:10000000 FF0102030405060708090A0B0C0D0E0F 79
:10001000 101112131415161718191A1B1C1D1E1F 68
:10002000 20
 


address 0 (FF) is not used.
Adres 1-32 contain the first postions of each of the 32 buffers.

I now can get a good look on the workings of my code both in the simulator (which I had forgotten that's a possiblity too) and when downloading the eeprom content with AVR studio.

Thanks !

Peter
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2335

blank.gif
PostPosted: Mon Sep 30, 2024 4:19 pm    Post subject: Reply with quote

Peter Huijssen wrote:
Adres 1-32 contain the first postions of each of the 32 buffers.

Surprise, surprise. Very Happy
As written, with
Code:
Dim Ring_buffer(8 , 32) As Eram Byte

instead of
Code:
Dim Ring_buffer(32 , 8) As Eram Byte

you'll get the desired order, of course indexes in code have to be exchanged too.
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2165

netherlands.gif
PostPosted: Mon Sep 30, 2024 8:15 pm    Post subject: Reply with quote

Long long time ago I have converted the High Endurane Eeprom application note from Atmel to Bascom.
This should do what you want/need, or can get you helping finishing your code
Can't find the main program anymore to see how to implement this library.

Have fun.

Code:

$nocompile

Const Ee_param_high_buffer_size = 16
Const Ee_status_buffer_size = Ee_param_high_buffer_size
Const Ee_param_low_buffer_size = Ee_param_high_buffer_size
Const Ee_param_1 = &HA0
Const Ee_param_2 =(ee_param_1 + Ee_param_high_buffer_size + Ee_status_buffer_size + Ee_param_low_buffer_size)
Const Ee_param_3 =(ee_param_2 + Ee_param_high_buffer_size + Ee_status_buffer_size + Ee_param_low_buffer_size)       ' And So Forth


Dim Eebufptrparam1 As Word
Dim Eebufptrparam2 As Word                                  ' And So Forth

Eebufptrparam1 = Ee_param_1
Eebufptrparam2 = Ee_param_2                                 ' And So Forth





Sub Inithighenduranceeeprom()                               'Need to do when boot mcu
 Eebufptrparam1 = Findcurrenteepromaddr(ee_param_1)
 Eebufptrparam2 = Findcurrenteepromaddr(ee_param_2)
End Sub



Function Findcurrenteepromaddr(byval Eebufptr As Word) As Word       'Identify the last WRITTEN element of the status buffer
Local Eebufferend As Word , Eebufferpointer As Word
Local Temp As Byte , Temp2 As Byte
Eebufferpointer = Eebufptr + Ee_param_high_buffer_size      'Starts scanning at address eebufptr + buffer size
Eebufferend = Eebufferpointer + Ee_status_buffer_size       'Scan until buffer end

Do
   Readeeprom Temp , Eebufferpointer
   Temp = Temp + 1
   Incr Eebufferpointer
   If Eebufferpointer = Eebufferend Then Exit Do            'Break if end of buffer, so we don't compare out-of-bounds
   Readeeprom Temp2 , Eebufferpointer
Loop Until Temp <> Temp2
Temp = Ee_param_high_buffer_size + 1
Findcurrenteepromaddr = Eebufferpointer - Temp              'Point to the last used element of the parameter buffer
End Function



Sub Eewritebuffer(byval Parameter As Byte , Byref Address As Word , Byval Dat As Word)
Local Eeoldstatusvalue As Byte , Temp2 As Byte , Tempw As Word , Tempdat As Byte

Tempw = Address + Ee_param_high_buffer_size
Readeeprom Eeoldstatusvalue , Tempw                         ' Store the old status value and move pointer to the next element in the buffer
Tempw = Parameter + Ee_param_high_buffer_size
Incr Address

If Address = Tempw Then Address = Parameter                 'Wraparound if necessary

Tempdat = High(dat)
Writeeeprom Tempdat , Address                               'Update the parameter in the EEPROM buffer
Tempw = Address + Ee_param_high_buffer_size
Tempw = Tempw + Ee_status_buffer_size

Tempdat = Low(dat)
Writeeeprom Tempdat , Tempw
Tempw = Address + Ee_param_high_buffer_size
Temp2 = Eeoldstatusvalue + 1
Writeeeprom Temp2 , Tempw
End Sub

Function Eereadeeprom(adres As Word) As Word                'read eeprom value back
Local Highbyte As Byte , Lowbyte As Byte , Tempw As Word
Readeeprom Highbyte , Adres
Tempw = Adres + Ee_param_high_buffer_size
Tempw = Tempw + Ee_status_buffer_size
Readeeprom Lowbyte , Tempw
Tempw = Makeint(lowbyte , Highbyte)
If Tempw = &HFFFF Then Tempw = Startcountat25pointer        'If eeprom is empty then start at...
Eereadeeprom = Tempw
End Function
 

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
Peter Huijssen

Bascom Member



Joined: 09 Apr 2004
Posts: 49

netherlands.gif
PostPosted: Tue Oct 01, 2024 11:24 am    Post subject: Reply with quote

Evert, thanks for your code !
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum