Propeller DATA
Newzed
Posts: 2,503
I wrote:
DAT
xpos··· word··· 400
then I wrote:
PUB start | i
· 'start the tv terminal
· term.start(12)
· getdata·
and then I wrote:
PUB getdata
· term.str(string("Position X· "))
· posit := word[noparse][[/noparse]xpos][noparse][[/noparse]0]
· term.dec(posit)
· term.out(13)··
When I run it, my TV displays:
Position X 548
Why does it say 548 instead of the 400 I was expecting?
Thanks
Sid
DAT
xpos··· word··· 400
then I wrote:
PUB start | i
· 'start the tv terminal
· term.start(12)
· getdata·
and then I wrote:
PUB getdata
· term.str(string("Position X· "))
· posit := word[noparse][[/noparse]xpos][noparse][[/noparse]0]
· term.dec(posit)
· term.out(13)··
When I run it, my TV displays:
Position X 548
Why does it say 548 instead of the 400 I was expecting?
Thanks
Sid
Comments
·posit := word[noparse][[/noparse]@xpos][noparse][[/noparse]0] ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
On page 4-58 of the Prop manual it says:
PUB GetData | Temp
Temp := Byte[noparse][[/noparse]MyData][noparse][[/noparse]0]
I think that should be changed to agree with what you just told me.· Also, I think "temp" is a reserved word - the program would not let me use it.
Thanks again.
Sid
DAT
trav· word· "L",100,"I",200,"P", "L", 300,"I", 400, "R", 0,· "O",0,"L",600,"I",400,"Q"
which is 8 "operations" all appearing on one line in Propeller.· When making a board I may have 200 or more operations.· I can't put all that on one line, so how do I organize my data list· so it can be read in its entireity. It starts off reading byte 0, the pointer is incremented by 1, it reads the next byte, and so on.· I tried writing:
DAT
trav· word· "L",100,"I",200,"P", "L", 300,"I", 400,
······· word "O",0,"L",600,"I",400,"Q"
but that didn't work.· Help, please.
Thanks
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?
I've killed a fly with my bare mind.
trav· word· "L",100,"I",200,"P", "L", 300,"I", 400
············ ·· "R", 0,· "O",0,"L",600,"I",400,"Q"
and got an error saying the second line must be proceeded by byte, word or long.· So then I wrote:
DAT
trav· word· "L",100,"I",200,"P",0,"L", 300
···· · word· "I", 400,· "R", 0,· "O",0,"L",600,"I",400,"Q"
and that worked!
Thanks again, Mike.
Sid
trav[noparse][[/noparse]index]
...same as...
word[noparse][[/noparse]@trav][noparse][[/noparse]index]
...and...
trav
...same as...
word[noparse][[/noparse]@trav]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chip Gracey
Parallax, Inc.
I am just finishing up my Prop program to run my little SuperMill.· I have two variables, xpos and ypos, tht define the current coordinates of the X and Y tables.· These variables are updated each time either table moves and are always correct as long as I don't turn the Prop off.· If I turn the Prop off, then back on, they both go to 0,0.· With the Stamp, each time either is updated, I write the new value to EEPROM.
I have read the DAT pages of Chapter 4 several times but I do not see a way to write a DAT statement from with the program.· Is it possible to write a DAT statement "on the fly", so to speak.· I could always write a new DAT statement before I turn the Prop off, then read it when the Prop is turned back on, but it would be much nicer if I could update the DAT statement automaticallly via the program.
Thanks
Sid
OBJ
· term: "tv_terminal"·················
· kb: "keyboard"
· fp: "floatmath"
· i2c: "i2cObject"
Here is·my DAT block:
DAT
··· loc·· word· 0,0····· 'xpos, ypos
··· trav· word· "L",100,"I",200,"P",0,"L", 300
·········· word· "I", 400,· "R", 0,· "O",0,"L",600,"I",400,"Q"
Now, could you show me how to write new values of xpos or ypos to DAT whenever either changes.· Maybe one of these days I can do things like this for myself, but not just yet.
Thank you very much.
Sid
Basically, you'd call InitializeI2C somewhere in your initialization and call DoItAll(@loc,xpos,ypos) when you want to update the DAT. You can do an "if DoItAll(...)" if you want to check that it all went well. I'm assuming that words are most significant byte first on the Propellor. I haven't checked, but
I think that's how things are arranged.
PUB WriteWord(Addr,Value)··········· ' Write the word Value at Address.· True if successful
· i2cObject.init(i2cSDA, i2cSCL)·
··· if i2cObject.devicePresent(EEPROM_Addr) == true
····· term.str(string("EEPROM present"))
··· else
····· term.str(string("EEPROM not present"))
··· i2cObject.writeLocation(EEPROM_Addr,Addr,Value,16,8)
··· waitcnt(clkfreq / 100 + cnt)·· ' Wait 10ms
··· return i2cObject.readLocation(EEPROM_Addr,Addr,16,8) == Value
· return false
Then at the very beginning of the program I modified my PUB start to:
PUB start
· 'start the tv terminal
· term.start(12)
· WriteWord(Addr, value)
When I tried to load it I got an error "Expected an expression term" and it highlighted "Addr".· What did I do wrong?·
Sid·······
Sid
Every time you run this, it should show a larger value
2) EEPROM_Addr is the address of the EEPROM chip on the I2C bus and has nothing to do with Propellor addresses
DAT
test· word· 0
"test" turned purple, so I figured it ws a reserved word.· I changed it to test1 and it turned the normal color.· Then I wrote:
PUB start
' start the tv terminal
· term.start(12)
· term.dec(test1)
· waitcnt(clkfreq*2 + cnt)········· 'added this line
' initialize I2C
· i2cObject.init(i2cSDA, i2cSCL)
·· if NOT WriteWord(@test1,test1+1)
··· term.str(string("EEPROM Write Error"))
I loaded and ran.· "0" appears for 2 seconds, then the screen turned black briefly, then back to a blank blue screen - nothing at all displayed.
I have an idea - easier for me, harder for you.· I have attached pulsout_N_autorun which works fine.· Could you insert whatever so it will work?· Line 127 is the first instance of xpos changing value.· If you can do your thing here so I can see how you did it, then I can change all the other instances in the program.· If it compiles, please send it back to me as pulsout_P_autorun.
Thanks· lot
Sid
···
I doiwnloaded i2cDemoApp.· I had no idea what I was doing but I started changing things to see what would happen.· Eventually I got to the point where it would read the current position of xpos and ypos, write them to EEPROM and then read them back.· This is in keeping with my programming philosophy when I don't know what I'm doing - if Button A doesn't work, then push Button B.
Anyway, I incorporated the write/read sequence into my program as:
PRI EEPROM_Demo | eepromData, eepromLocation, EEPROM_array[noparse][[/noparse]10], ackbit
Then I wrote another method:
PRI EEPROM_read | eepromData, loc, EEPROM_array[noparse][[/noparse]10], ackbit
I saved everything into a new version - pulsout_P_autorun - which I have attached.· All the previous lines that said "term.dec(xpos", etc.. were deleted.· The revised program with the two added methods were great, EXCEPT - when I turn the Prop off and back on again, X and Y go to 0,0, instead of the current positions I was anticipating.· It's like it is not reading the EEPROM or I am not getting it there correctly in the first place.· Can you fix it so I can read the current position when I boot up again.· I have also attached the version of i2cObject I am using.· Apparently there are at least two versions of this object and I wanted to make sure you have the version I was using.
Thanks
Sid
down, modified I2C Demo program that just scans the I2C bus and does it's EEPROM thing if one is found.
1) Even though the I2C read / write routines accept a bit count, they really only read / write the 8 most significant bits.
They're taking the high order byte of your values (which is probably zero). You have to break it apart yourself. That's why
I wrote the "WriteByte" and "WriteWord" routines ... to take care of this. You might as well use them.
2) I've modified the i2cObject to properly handle a bit count other than 8 (see my previously posted archive). That will only
work for devices that understand a non-8 bit data size. It certainly isn't true for EEPROMs.
You have to use "@" when passing the EEPROM location to the read/write routines. So, "@xpos" means "address in EEPROM or RAM of xpos". In your program you just put "xpos". This writes the data at the location in EEPROM corresponding to the value of xpos ... in other words ... where you don't want it.
However, I agree with you that I am doing it wrong.· When I write:
term.dec(xpos)·· I think I'm really displaying the value that was generated when I told it to go left.
I changed that line to:
term.dec(eepromdata)
and all I got was 0, so obviously I am not writing properly to the EEPROM· I'll just wait until you can make it right.· I'm anxious to see how you do it.· I have an EEPROM that will only accept bytes, so with the Stamp I have to write:
shiftout.......v1.lowbyte, v1.highbyte,...........
Don't now if that approach will work with Prop.· Anyway, I'll wait for you to fix things, as you always do.
Sid
This writes the current value of xpos and ypos to the EEPROM so that they will be reloaded into RAM when the Propellor is restarted. These should not be written to EEPROM unless they have actually changed since there is a limit on the number of times any EEPROM can be written (approx 1,000,000).
Note that this may not work if you don't use my modified i2cObject (v1.3). If you want to display xpos and ypos, use "term.dec(xpos)". If you want to read the values stored in EEPROM do:
term.dec(xpos)· ' or (ypos)· wherever necessary, ran it to make sure everything was OK, then saved it as Rev Q.
I then added your two methods - copied and pasted - and tried to compile it.· I got an error "Expected a unique name" and it highlighted the xpos in the DATA list.· So....I· changed all references in the DATA list and in your two methods to xposit or yposit as required.· It then compiled OK.
I'll let you know in the morning how the program worked out.· It is about time for me to power down.
Sid
Well, here is what happened.· I added your two methods to my program, changing
WriteLocation to
i2cObject.writeLocation(%1010_0000, @xposit, xposit>> 8, 16, 8) ' write msb of xpos
··· i2cObject.writeLocation(%1010_0000, @xposit+1, xposit, 16, 8) ' write lsb of xpos
··· i2cObject.writeLocation(%1010_0000, @yposit, yposit >> 8, 16, 8) ' write msb of ypos
··· i2cObject.writeLocation(%1010_0000, @yposit+1, yposit, 16, 8) ' write lsb
To check the response, I put ReadLocation at the beginning of the program and put WriteLocation at the end of the L,R,I and O sequences.· The first time if ran it the screen said:
xpos = 19456· ypos = 18688
I then ran left, 100, and xpos changed to 0.· Then I realized that I wanted to store xpos, not xposit, so I changed the WriteLocation lines to:
i2cObject.writeLocation(%1010_0000, @xposit, xpos>> 8, 16, 8) ' write msb of xpos
··· i2cObject.writeLocation(%1010_0000, @xposit+1, xpos, 16, 8) ' write lsb of xpos
··· i2cObject.writeLocation(%1010_0000, @yposit, ypos >> 8, 16, 8) ' write msb of ypos
··· i2cObject.writeLocation(%1010_0000, @yposit+1, ypos, 16, 8) ' write lsb of ypos
When I loaded and ran xpos was still 0 and ypos still 18688.
I ran in, 100, and ypos changed to 18788.· Then I ran left, 1000.· Xpos was 768
and ypos was still 18788.· I ran right,100.· Xpos and ypos were unchanged.· I ran right, 1000.· xpos was 65280 and ypos was unchanged.· I turned the Prop off for a minute, then back on and the same values were displayed.
That is where I am at the moment.· I'm going to play around with it to see if I can get the proper display.· I feel that this has taken enough of your time, so if I can not get it working, I'll go back to my original program, and if I have to stop in the middle, I'll either just let the Prop run until the next morning, or, I could record the X and Y values, then plug them in at the start of the program when I'm ready to resume.
Sid
xpos var word
x var byte
y var byte
z var word
xpos = 1000
x = xpos>>8··· 'msb
y = xpos········ lsb
xpos·= x<<8 | lsb
debug dec ? x, cr
debug dec ? y, cr
debug dec ? xpos, cr
The debug screen said:
x = 3
y = 232
xpos = 1000
so that proves out your math.· Then I added 2 lines to WriteLocation:
PRI writePosition
··· xpos := 444···· 'added
··· ypos := 555··· 'added
··· i2cObject.Init(29, 28)· ' initialize the i2c routines with SCL
The idea being to force a display of xpos and ypos, regardless of what they really were.· I ran left, 100, and got 256 and 16543 instead of the 444 amd 555 I was expecting.· Then I loaded the program into EEPROM instead of RAM and got
256 and 43.
It doesn't make any difference whether I use v1.2 or v1.3 of ic2Object.
So I'll try something else.
Sid
yposit remained 0 but your ypos changed to 100.· Then I wrote in 100 again.
yposit remained 0 butyou ypos changed to 44.· This is weird.
Sid
PRI writePosition
··· xposit := xpos
··· yposit := ypos
··· i2cObject.Init(29, 28)· ' initialize the i2c routines with SCL pin 28 and SDA pin 29
··· i2cObject.writeLocation(%1010_0000, @xposit, xposit>>8, 16, 8) ' write msb of xpos
··· i2cObject.writeLocation(%1010_0000, @xposit+1, xposit, 16, 8) ' write lsb of xpos
··· i2cObject.writeLocation(%1010_0000, @yposit, yposit >>8, 16, 8) ' write msb of ypos
··· i2cObject.writeLocation(%1010_0000, @yposit+1, yposit, 16, 8) ' write lsb of ypos
··· i2cObject.stop ' stop using pins 28 and 29 and leave them as inputs
I esloaded and everything read 0.· Then I wrote In 255.· Your ypos said 255, yposit said 255 and my Y said 255.· Then I said in 1.· Your ypos said 0, yposit said 256, and my Y said 256.· It's like the program is not reading the msb of yposit.· I said left 100.· Your xpos stayed at 0, xposit said 100 and my X said 100.· I said left 155.· Your xpos remained 0, my X and xposit both said 255.· I then changed:
term.dec(msb << 8 | lsb)
to read:
term.dec(yposit)
Now your·ypos, my Y and yposit all respond accurately.· I turned the Prop off for a minute, then back on.· Your ypos said 59392, yposit said 59392, and as epected my Y said·0.
Then I changed:
term.dec(msb << 8 | lsb)
to read:
term.dec(xposit)
Now the xpos function responds just like the·ypos.· However, if I turn Prop off, then back on, your xpos says 1, xposit says 1, and as expected my X says 0.
I am becoming emotionally traumitized!
Sid