News:

Let's find out together what makes a PIC Tick!

Main Menu

Alias for an array

Started by keytapper, Apr 14, 2024, 02:45 PM

Previous topic - Next topic

keytapper

Hi there,
I was expecting to make an alias from a bigger array.

Symbol ARRAYLEN 64
Symbol MIDARRAY ARRAYLEN / 2

Dim person[ARRAYLEN] As Byte
' just an example to look into the second half
Dim surname As array.MIDARRAY

Str person = "Billy",0
Str surname = "Unknown",0

I think is not there, but simple to implement. Accepting the fact that only constant are allowed to address the alias. In fact, in the assembler each byte is well defined.

The only advantage is to look into an allocated block of RAM to modify part of it. The idea is to avoid to make two separated arrays, because there's a difficulty to make it like a record.
But I doubt if it is useful or I'm looking for an useless complication  ;D
Ignorance comes with a cost

Stephen Moss

Not sure what you are trying to achieve here, but it sounds like you are trying to create a two dimantional array in a single array rather than using two differnt arrays, storing the Forename in one half of the array and Surname in the the other depending on which you are searching for would it not be something like...

Symbol ARRAYlen as Byte = 64
Symbol MIDARRAY as byte ARRAYlen / 2
Dim MyArray[ARRAYlen] as Byte  'Create a 64 byte array
Dim Person as byte

'Find/Search by Forname
For Person = 0 to MIDARRAY-1
  Person = MyArray[Person]              'Get/Set Forename location within the array
  Surname = MayArray[Person + MIDARRAY] 'Get/Set Surname location within the array

  'Do something with the array location data here
Next

'Find/Search by SurName
For SurName = MIDARRAY to ARRAYlen -1
  Surname = MayArray[SurName]           'Get/Set Surname location within the array
  Person = MyArray[Surname - MIDARRAY]  'Get/Set Forename location within the array
 

  'Do something with the array location data here
Next

If your are only Storing ForeNames and Surnames when why not keep them together, i.e. Forename 1 = Array,0 and Surname 1 = Array,1. To enter/retrieve data from the would be something like...
For X = 0 to ARRAYlen step 2
   Person = MyArray[X]      'Get/Set Forename location within the array
   Surname = MyArray[X + 1] 'Get/Set SurName location within the array

  'Do something with the array location data here
Next
 

keytapper

I also came across this fact, which might be one of the convenient option.
Well, it's not a good point to make a subarray by an alias.
Ignorance comes with a cost

top204

If it is String arrays you are wanting, I did create a simple, experimental, String array set of meta-macros a few years ago, that works well.

Because of the RAM mechanisms in PICmicro devices, the String array meta-macros only work with 18F devices.

Below is a demo code listing showing how to use the String Array routines, and it also allows for flash memory strings:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate RAM and Flash memory string array handling using the "String Array.inc" meta-macros
' For 18F devices only
'
' Written by Les Johnson for the Positron8 BASIC compiler
'
    Device = 18F25K20                                               ' Tell the compiler what device to compile for
    Declare Xtal = 16                                               ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Setup USART1
'
    Declare Hserial1_Baud = 9600
    Declare HRSOut1_Pin = PORTC.6

    Include "String Array.inc"                                      ' Load the String array macros into the program
'
' Create a 10 string flash memory array, with each String 24 characters in length (including the null)
' The flash memory string must be an even amount of bytes (including the null)
'
    Create_FlashStringArray(MyFlashString, 10, 24)= {"My Flash String Array 0", 0,
                                                     "My Flash String Array 1", 0,
                                                     "My Flash String Array 2", 0,
                                                     "My Flash String Array 3", 0,
                                                     "My Flash String Array 4", 0,
                                                     "My Flash String Array 5", 0,
                                                     "My Flash String Array 6", 0,
                                                     "My Flash String Array 7", 0,
                                                     "My Flash String Array 8", 0,
                                                     "My Flash String Array 9", 0}
'
' Create variables here
'
    Dim bIndex As Byte                                              ' Temporary byte used by the demo
    Dim TempString As String * 32 Heap                              ' Temporary string used by the demo
'
' Create a 10 string RAM array, with each string 20 characters in length (not including the null)
'
    Create_StringArray(MyString, 10, 20) = {"RAM String Array   0", 0,
                                            "RAM String Array   1", 0,
                                            "RAM String Array   2", 0,
                                            "RAM String Array   3", 0,
                                            "RAM String Array   4", 0,
                                            "RAM String Array   5", 0,
                                            "RAM String Array   6", 0,
                                            "RAM String Array   7", 0,
                                            "RAM String Array   8", 0,
                                            "RAM String Array   9", 0}

'--------------------------------------------------------------------------------------
' Test the string array meta-macros by loading then retrieving values
'
Main:
'
' Read the RAM String array's default content
'
    For bIndex = 0 To 9
        TempString = Read_StringArray MyString, [bIndex]            ' Retrieve the RAM string array
        HRSOutLn TempString                                         ' Transmit the string's text to a serial terminal
    Next
'
' Load and Read the RAM String array
'
    Clear MyString
    For bIndex = 0 To 9
        TempString = "MyString RAM Array " + Str$(Dec bIndex)       ' Fill the string to load and retrieve
        Write_StringArray MyString,[bIndex], TempString             ' Load the RAM string array
        TempString = Read_StringArray MyString, [bIndex]            ' Retrieve the RAM string array
        HRSOutLn TempString                                         ' Transmit the string's text to a serial terminal
    Next
'
' Read the Flash memory String array
'
    For bIndex = 0 To 9
        TempString = Read_FlashStringArray MyFlashString, [bIndex]  ' Retrieve a Flash memory string array
        HRSOutLn Dec bIndex, "...", TempString                      ' Transmit the string's text to a serial terminal
    Next

I have attached the String Array sources and the demo and a proteus project showing the above demo working in the simulator:

keytapper

Many thanks for your attention, Mr Les.
I admit that I should dig some more into the given includes.  :-[
Well, my attempt is to make a double buffering and trying to catch all income data. I started to think to use a swapping method so when one buffer still reading, the other will allow one more stream to come in.
As one condition will determine the end of message, then the swap will take place.

I think I looked for a complication.
Ignorance comes with a cost

JackB

#5
Hello everyone,

this is a request about  "String Array routines" program.

I read about and find interesting to do some coding with "Create_FlashStringArray(MyFlashString, 1000, 40)"

I have an PIC18F27Q84T-I/SO 128 Kbytes flash ram 64Mhz and looking to use it for an array of 1000 records, of 40

characters per record (about 40 Kbytes of Flash Ram).

my project consist to load an external ASCII file and create an array, and be able to search, edit part of a record and

save it back to the array so when the PIC get disconnected, the array remain intact until the next

power-up. Also how fast (just an estimation) this PIC can find any record within the array by searching the 3 first

characters of each record by using:

For bIndex = 0 To 999
"    code
"    code
next

eg :

"001,xxxx
"002,xxxx
"003,xxxx

here's a record sample:

"001123456789012Baseball accepppppp01999",0
"002123456789012Baseball accepppppp01999",0
"003123456789012Baseball accepppppp01999",0
"004123456789012Baseball accepppppp01999",0
"
"
"
"998123456789012Baseball accepppppp01999",0
"999123456789012Baseball accepppppp01999",0

Is this possible and what is the life cycle of flash ram before corrupting the array.

welcome any comments.

Thank's to all.




JackB


BTW,

I like to find if there's a way to import ASCII value to an array table into the flash memory

either via serial or I2c or other way.

Thank's again

trastikata

Hello JackB,

the flash cell write endurance for those devices is rated only 1k write cycles and erasures in FLASH is done in 128b pages. If this is not acceptable, there's no point diving further into details, better use external FLASH memory with 100k endurance or better some NVRAM if higher write cycles is required.

However if this is acceptable endurance rate, let us know and we'll explain in details some quirks of your code design.

JackB

#8
Hello and thank you trastikata
for taking time to reply.

as you mention, the best option is with external Flash or NVRAM IC.

what could be the outcome to get an array to work as "String Array routines" as editing, and saving in external memory.

is it feasible and what it's involving as code & parts.

Thank's again.









trastikata

Hi JackB,

some more information will be required to choose the optimal memory option, in any case I'd opt for SPI version if design allows it:

- what is the maximum expected number of write cycles per file entry for the lifespan of the end-product?
- do you require record redundancy in case of unexpected power failure while the file is being updated?
- what is the desired minimum record update time?

For the code part everything is more or less straightforward.

- Usually best way to update data in memory is to write in pages which can vary in size in different products - typically from 64 to 256 bytes per page.

- Some types of memory require the entire page to be erased before it can be written again.

- If pre-erasure is required, then usually one reads the data from the entire page into internal PIC RAM buffer array, modifies the data and writes back the entire page. 

- Optional when redundancy is required and memory allows it I triple the data record. Before usage I read the three data records. Then by comparing them if an error is detected I arbitrate 2 of 3 and correct the erroneous record. Further use it as usual.

- Optional if the memory has finite number of write cycles and I expect it to be reached at some point I keep another record counter in the memory or the end of each file entry, which I increment every time an update occurs.
   
- in your case you need 1000 records where every record will be 40 bytes, given the early mentioned memory page organization, I'd partition (virtually) the memory in chunks of 64 bytes. Then it's either 1,2 or 4 records per memory page and dealing with it is very easy.

- 64 bytes file entry = ASCII data(40 bytes) + Optionally(2 bytes CRC + 4 bytes write counter + 18 bytes free)

- You don't need a search function looking through the first 3 ASCII codes which represent a sequential number, simply start reading it from memory position = Record_Number * 64

JackB


Hello, Trastikata

Just looked at some SPI flash ram like SST25VF010A to get a sense what can be the outcome.

to answer:
- what is the maximum expected number of write cycles per file entry for the lifespan of the end-product?
       from the SST25VF010A Datasheet Endurance: 100,000 Cycles (typical)
- do you require record redundancy in case of unexpected power failure while the file is being updated?
       Not for now , main file will be backup every day
- what is the desired minimum record update time?
      from the Datasheet :  Block Erase ~ 25ms / my perspective: 100ms for read/write cycle or less.

Keep in mind I have limited experience in PIC in general

The project is to hold in external memory a parts number table of about 1000~1200 records of 40~50 characters per

record this table is to be read/write as the same as an POS/ECR, and daily report will be generated everyday.

The table or part of it can be updated on a transaction basis when inventory changes.

I understand the point of memory pages access, in this case the table can be modified to accommodate the process.

since reports has to be generated, I looking for 2/3 table to be accessible.

Hope this brief explanation is helping.

Thanks again






trastikata

I think there's some misunderstanding here.

Quote- what is the maximum expected number of write cycles per file entry for the lifespan of the end-product?
       from the SST25VF010A Datasheet Endurance: 100,000 Cycles (typical)

- Say for example your product will update data records 4x per day.
- The device in question will be used no more than 15 years ...

Assuming worst case scenario where the same memory page is updated all the time (not probable but possible) - there will be maximum 15 * 365 * 4 = 21900 writes to the same page - this is the minimum memory endurance required. A 100k endurance memory can suffice.

Quote- what is the desired minimum record update time?
      from the Datasheet :  Block Erase ~ 25ms / my perspective: 100ms for read/write cycle or less

Say for example there's a possibility that two records have to be updated within 6 mS, then you'd need a device that has faster than 6 mS write times, seems not the case in your situation. So a FLASH memory chip is OK.

QuoteThe table or part of it can be updated on a transaction basis when inventory changes.

You'd still need a mechanism for data corruption check and correction - tripling the record, as I mentioned earlier is the easiest and quite reliable way to implement data corruption check and correction. Therefore you'd need 3x larger memory chip.

QuoteThe project is to hold in external memory a parts number table of about 1000~1200 records of 40~50 characters per record

Given the early presented scenarios of triple record entry, you'd need 4 Mbit FLASH memory, ergo 4194304 bits / 8 = 524288 Bytes / 64 = 8192 records / 3 = 2730 product entries maximum.

 

JackB

I understand better now the scope of this project, with your advices.

I've got in transit 2 SPI Flash IC (8Mb,32Mb), SST25VF080B-50-4C, SST25VF032B-80-4I

I think either one can do the job fine.

Have you ever build a PIC + SPI Flash storage project similar to this one.

Let me know your idea.

Many thanks for all the help you providing me on this project.






trastikata

Quote from: JackB on Sep 27, 2024, 06:15 PMHave you ever build a PIC + SPI Flash storage project similar to this one.
Let me know your idea.
Many thanks for all the help you providing me on this project.

:) JackB, is this a school project?

JackB


no, I'm retired just a project for me


trastikata

I see, sorry if my comment sounded rude.

To answer your latest question - yes, I have some experience with FLASH memory  ;)

QuoteI've got in transit 2 SPI Flash IC (8Mb,32Mb), SST25VF080B-50-4C, SST25VF032B-80-4I

Unfortunately those are not good, Microchip's FLASH memory I've seen do not offer page erasure, minimum is 4k sector erase which is not practical in your case.

JackB

don't worry, you help me a lot.

Thanks again.