I have it in the back of mind that I can only store a numeric value to a maximum of 255 onto an EEPROM Y/N
I want to be able to store a numeric value from between 4000 of up to 6525. The Dark Arts folks (Arduino) can do but I can't follow how it works. is it possible? if so how do I do it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great Cow BASIC will try automatically detect the type of the table depending on the values in it. Great Cow BASIC can be explicitly instructed to cast the table to a variable type, as follows:
Addresssing the Table Data
Item 0 of a lookup table stores the size of the table. If the ReadTable command attempts to read beyond the end (number of data items) of the table, the value 0 will be returned. For tables with more than 255 elements it is mandatory to use a WORD variable to read the size of the table.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you are trying to store a 'word' into Eeprom you could try this:
SubPutWEeprom(HiAddrAsByte,EWordAsWord)'Places a Word into two bytes of'Eeprom, HiAddr is the first Byte'location in Eeprom, the lower Byte'is placed into the adjacent byte'LetTHi=EWord/256LetTLo=EWord-(THi*256)EpWrite(HiAddr,THi)EpWrite(HiAddr+1,TLo)EndSubSubGetWEeprom(HiAddrAsByte,OutEePromWValAsWord)'Takes the address of the High Byte and returns'a Word made from the HiAddr and the adjacent'byte in Eeprom''The sequence of this 'Rebuild' appears important.'The order of Low byte - High must be maintained.EpRead(HiAddr+1,EePromWVal)EpRead(HiAddr,EePromWVal_H)EndSub
These are called like this:
DimTHiAsByteDimTLoAsByteDimWordVariableAsWord#DefineEePromStartAddress0' This stores a word variable across two byte locations - next free EeProm location is 2
Other code here...
GetWEeProm(EePromStartAddress,WordVariable)
And:
PutWEeProm(EePromStartAddress,WordVariable)
Last edit: Ccin E Crout 2023-02-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
A thought, that would need investigation.. or may be you have already, but using the EEAddress rather than epMemLoc could save a variable. Check this idea in the ASM... the compiler may already do the optimisation.
:-|
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Variable "EEAddress" is used with both EPRead and EPWrite, so might as well reuse it here. And a few instructions are saved by not moving data from variable to variable.
The only gotcha that I can see is if code was shuffling data around in EEPROM, like a in nested loop of Reads and Writes. In that rare case it may have been better to have different address variables for reads and writes
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That implies that the code was written with the intention of placing it in a library where 2 subs with the same name (overloaded) makes sense. These were posted with the intention of a user ( Keith) grabbing one or 2 and placing it in his source code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My Spindle Motor Temp Controller.gcb (270): Error: Array/Function
EPWRITEWORD has not been declared
My Spindle Motor Temp Controller.gcb (270): Error: Syntax Error
putting the EPWRITEWORD in the DIM statements as a Word does nothing for it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That is not my code! Not even close. It won't compile because you changed it . I think you may be misunderstanding that I gave you new subroutines to use. Use them exactly as I wrote them (as subroutines).
EPWriteWord is a subroutine that I created (you must copy it into your code). Then you call that subroutine when you want to write a Word to EEPROM. Same goes for all of the others.
Note that each WORD written to EEPROM takes up 2 memory locations. IN the example below the value of 4127 uses Locations 10 and 11.
' ----------- Main Code Starts Here ---------DimTestWordasWORDEPWriteWord10,4127'// Write Val of 4127 to EEPROM location 10 EPReadWord10,TestWord'// Read it back into a variablePrintTestWord'// Show the Variable on LCDEnd'------------ Sub Routines Start Here ------------' ---- DO NOT CHANGE OR MODIFY THESE ! -------SubEPWriteWord(INEEAddress,INepWordVarasWORD)EPWRITEEEAddress,epWordVarEPWRITE(EEAddress+1),epWordVar_HEndSubSubEPReadWord(INEEAddress,OUTepWordVarasWord)EPREAD(EEAddress,epWordVar)EPREAD(EEAddress+1),epWordVar_HEndsub
Last edit: William Roth 2023-02-17
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you so much William, That has settled my threshold temperature issue, I'm not sure where it is being stored in either the 16F18326 EEPROM or the 256k EEPROM on the i2c Bus.
I have seen a small i2c program which gives me a dump of the EEPROM contents but I don't seem to be able to find it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have it in the back of mind that I can only store a numeric value to a maximum of 255 onto an EEPROM Y/N
I want to be able to store a numeric value from between 4000 of up to 6525. The Dark Arts folks (Arduino) can do but I can't follow how it works. is it possible? if so how do I do it?
In the Help.
https://gcbasic.sourceforge.net/help/_lookup_tables.html
Great Cow BASIC will try automatically detect the type of the table depending on the values in it. Great Cow BASIC can be explicitly instructed to cast the table to a variable type, as follows:
Addresssing the Table Data
Item 0 of a lookup table stores the size of the table. If the ReadTable command attempts to read beyond the end (number of data items) of the table, the value 0 will be returned. For tables with more than 255 elements it is mandatory to use a WORD variable to read the size of the table.
If you are trying to store a 'word' into Eeprom you could try this:
These are called like this:
Other code here...
And:
Last edit: Ccin E Crout 2023-02-14
@cc
Very nice. May I lift and put into Help? I will attribute the knowledge to yourself.
By all means.
If you prefer to use Williams, I won't cry!
I knocked these up for Terry Platt in another thread a couple a weeks ago. Seem to work ok
Cleaned up and added Integers to support negative numbers
A thought, that would need investigation.. or may be you have already, but using the EEAddress rather than epMemLoc could save a variable. Check this idea in the ASM... the compiler may already do the optimisation.
:-|
I was more focused on how it could be easily done than saving a single byte of memory. But I do think that using "EEAddress" would save that byte.
Here they all are . Used "EEAddress" to save a variable and a few instructions
Please ....someone test these routines
Bill
Last edit: William Roth 2023-02-15
I'm struggling to see how this saves a Byte. Is 'EEAdress' a system variable?
Variable "EEAddress" is used with both EPRead and EPWrite, so might as well reuse it here. And a few instructions are saved by not moving data from variable to variable.
The only gotcha that I can see is if code was shuffling data around in EEPROM, like a in nested loop of Reads and Writes. In that rare case it may have been better to have different address variables for reads and writes
Heads Up!
I forgot that many Chips have more than 256 Bytes of EEPROM. In these cases "EEAddress" must be a Word Variable
William
Use an overloaded Sub(). That will resolve.
That implies that the code was written with the intention of placing it in a library where 2 subs with the same name (overloaded) makes sense. These were posted with the intention of a user ( Keith) grabbing one or 2 and placing it in his source code.
OK.
I have tried using William's initial example but I cannot get it compile
If ENCODER_SW = 0 Then
Wait until ENCODER_SW = 1
it tells me :-
Errors have been found:
My Spindle Motor Temp Controller.gcb (270): Error: Array/Function
EPWRITEWORD has not been declared
My Spindle Motor Temp Controller.gcb (270): Error: Syntax Error
putting the EPWRITEWORD in the DIM statements as a Word does nothing for it.
That is not my code! Not even close. It won't compile because you changed it . I think you may be misunderstanding that I gave you new subroutines to use. Use them exactly as I wrote them (as subroutines).
EPWriteWord is a subroutine that I created (you must copy it into your code). Then you call that subroutine when you want to write a Word to EEPROM. Same goes for all of the others.
Note that each WORD written to EEPROM takes up 2 memory locations. IN the example below the value of 4127 uses Locations 10 and 11.
Last edit: William Roth 2023-02-17
Thank you so much William, That has settled my threshold temperature issue, I'm not sure where it is being stored in either the 16F18326 EEPROM or the 256k EEPROM on the i2c Bus.
I have seen a small i2c program which gives me a dump of the EEPROM contents but I don't seem to be able to find it.