| Author |
Message |
meenbombs
Joined: 20 Nov 2008
|
|
Posted: 14 June 2009, 22:48 PM Post subject: External EEPROM for ZX-328 |
|
|
I am pretty sure the answer is no because I cannot find anything that says "yes," and my life would be easier if the answer was yes.
Is there a relatively easy way to add program space by adding an external EEPROM? I need about 45K total. Thanks. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 14 June 2009, 23:11 PM Post subject: Re: External EEPROM for ZX-328 |
|
|
| meenbombs wrote: | | Is there a relatively easy way to add program space by adding an external EEPROM? | No. None of the native mode devices can execute code other than from internal Flash memory.
The alternative is to move to the ZX-44n or ZX-40n. The ZX-44n is probably smaller than a ZX-328n and certainly smaller than a ZX-328n plus an EEPROM. |
|
| Back to top |
|
 |
meenbombs
Joined: 20 Nov 2008
|
|
Posted: 14 June 2009, 23:44 PM Post subject: |
|
|
| Thanks for the clarification. I am not that concerned with size but I already have a cut and paste board layout I use for all my products and it has the 328 with all the support circuits for IO, power, and comms and also addresses some other issues. Basically, it is just easier to have all my products use the same uC but it isn't the end of the world to have one that is different. Also, the 328 seems to be the best bang for the buck by far. |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 15 June 2009, 0:17 AM Post subject: Re: External EEPROM for ZX-328 |
|
|
| meenbombs wrote: | | I need about 45K total. | Is that all code or is part of it data? All ZX devices can use external storage for data but you would have to add routines for retrieving the data from the external device. |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 15 June 2009, 0:43 AM Post subject: Re: External EEPROM for ZX-328 |
|
|
| dkinzer wrote: | | Is that all code or is part of it data? All ZX devices can use external storage for data but you would have to add routines for retrieving the data from the external device. | I had the same question. My largest ZBasic program to date takes 27K which is 95% code. My guess is that you do have quite a large quantity of data which could be stored in an external SPI EEPROM. You may want to write a cache which loads data as required because clearly the 2K RAM on the ZX-328n is insufficient to hold everything.
Oak Micros (which I own) sells both 32K and 64K SPI EEPROMs in a PDIP-8 format. I offer USPS first class mail as well to keep down shipping costs.
This may be all moot because judging by the code example you posted previously, there is a lot of duplicated code that could easily be reduced in size. I wouldn't be surprised if the code size couldn't be cut in half. You have a serious code bloat problem and I hope you didn't pay the contractor by lines of code written. |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 15 June 2009, 4:27 AM Post subject: Re: External EEPROM for ZX-328 |
|
|
| mikep wrote: | | You have a serious code bloat problem | Here is an example. I separated out this piece of function into a routine so I could compare before and after. I used a "few" tricks like compiler computed constants to keep the code size down. In the end I was able to save 1426 bytes on this routine alone.
Looking at the specification, I also noticed that it doesn't calculate correctly the latitude letters for the poles (A, B, Y and Z).
Before | Code: | Private Function findLatLetter(ByVal lat as Single) as String
If (84.0 >= Lat) And (Lat >= 72.0) Then
findLatLetter = "X"
ElseIf (72.0 > Lat) And (Lat >= 64.0) Then
findLatLetter = "W"
ElseIf (64.0 > Lat) And (Lat >= 56.0) Then
findLatLetter = "V"
ElseIf (56.0 > Lat) And (Lat >= 48.0) Then
findLatLetter = "U"
ElseIf (48.0 > Lat) And (Lat >= 40.0) Then
findLatLetter = "T"
ElseIf (40.0 > Lat) And (Lat >= 32.0) Then
findLatLetter = "S"
ElseIf (32.0 > Lat) And (Lat >= 24.0) Then
findLatLetter = "R"
ElseIf (24.0 > Lat) And (Lat >= 16.0) Then
findLatLetter = "Q"
ElseIf (16.0 > Lat) And (Lat >= 8.0) Then
findLatLetter = "P"
ElseIf (8.0 > Lat) And (Lat >= 0.0) Then
findLatLetter = "N"
ElseIf (0.0 > Lat) And (Lat >= -8.0) Then
findLatLetter = "M"
ElseIf (-8.0 > Lat) And (Lat >= -16.0) Then
findLatLetter = "L"
ElseIf (-16.0 > Lat) And (Lat >= -24.0) Then
findLatLetter = "K"
ElseIf (-24.0 > Lat) And (Lat >= -32.0) Then
findLatLetter = "J"
ElseIf (-32.0 > Lat) And (Lat >= -40.0) Then
findLatLetter = "H"
ElseIf (-40.0 > Lat) And (Lat >= -48.0) Then
findLatLetter = "G"
ElseIf (-48.0 > Lat) And (Lat >= -56.0) Then
findLatLetter = "F"
ElseIf (-56.0 > Lat) And (Lat >= -64.0) Then
findLatLetter = "E"
ElseIf (-64.0 > Lat) And (Lat >= -72.0) Then
findLatLetter = "D"
ElseIf (-72.0 > Lat) And (Lat >= -80.0) Then
findLatLetter = "C"
Else
findLatLetter = "Z"
End If
End Function |
After | Code: | Private Function findLatLetter2(ByVal lat As Single) As String
Dim l as Byte
' use Z for the poles - can also be A, B, and Y but ignored
l = Asc("Z")
If (Lat <= 84.0) And (Lat >= -80.0) Then
l = Asc("B")
' normalize latitude
lat = lat + 80.0
' keep incrementing while normalized latitude is positive
Do While lat > 0.0
lat = lat - 8.0
l = l + 1
Loop
' skip "I' and "O" letters
If l >= ASC("I") Then
l = l + 1
End If
If l >= ASC("O") Then
l = l + 1
End If
End If
' return the letter
findLatLetter2 = Chr(l)
End Function |
|
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 15 June 2009, 14:30 PM Post subject: |
|
|
I can improve on my own code a little. You of course do not need the loop and can use Integer math instead which both improve performance. The extra library routines take up 40 bytes more but this can divided over all the conversion routines when they are converted to Integer math. The technique shown below can be used to improve the other routines to eliminate the nested if then else routines that repeat the same calculation multiple times. | Code: | Private Function findLatLetter2(ByVal lat As Single) As String
Dim l as Byte
' use Z for the poles - can also be A, B, and Y but ignored
l = Asc("Z")
If (Lat <= 84.0) And (Lat >= -80.0) Then
' calculate letter by first normalizing the Latitude
l = Asc("C") + CByte(CInt(lat + 80.0)\8)
' skip "I' and "O" letters
If l >= ASC("I") Then
l = l + 1
End If
If l >= ASC("O") Then
l = l + 1
End If
End If
' return the letter
findLatLetter2 = Chr(l)
End Function |
|
|
| Back to top |
|
 |
twesthoff
Joined: 17 Mar 2006
Location: Virginia, USA
|
|
Posted: 15 June 2009, 17:50 PM Post subject: External EEPROM for ZX-328 |
|
|
Mike,
Do you really want
If l >= ASC("I") Then
or
If l = ASC("I") Then
for the two exceptions "I" and "O"in your code?
Tom |
|
| Back to top |
|
 |
mikep
Joined: 24 Sep 2005
Location: Austin, TX
|
|
Posted: 15 June 2009, 17:57 PM Post subject: Re: External EEPROM for ZX-328 |
|
|
| twesthoff wrote: | Mike,
Do you really want
If l >= ASC("I") Then
or
If l = ASC("I") Then
for the two exceptions "I" and "O"in your code?
Tom | Yes I believe I need the former (as previously written) because essentially I and O are skipped. That means everything above I has to be increased by 1 and everything above O has to be increased by 2.
If I was going to improve this code more by working on the other letter conversions I would actually use a separate routine that maps indices 0 through 21 to letters A through X, skipping letters I and O. |
|
| Back to top |
|
 |
twesthoff
Joined: 17 Mar 2006
Location: Virginia, USA
|
|
Posted: 15 June 2009, 18:01 PM Post subject: External EEPROM for ZX-328 |
|
|
| Gotcha... |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Location: Portland, OR
|
|
Posted: 15 June 2009, 19:32 PM Post subject: Re: External EEPROM for ZX-328 |
|
|
| twesthoff wrote: | | Do you really want [the] two exceptions "I" and "O"in your code? | I also believe that the code was correct. Another way to implement it is this: | Code: | ' skip "I' and "O" letters
If l >= ASC("O") Then
l = l + 2
ElseIf l >= ASC("I") Then
l = l + 1
End If | This is probably slightly faster (on average) and slightly smaller. It might also be less likely (than Mike's code) to lead an observer to conclude that it was implemented incorrectly. |
|
| Back to top |
|
 |
|