Need help saving variables to EEPROM so they come back after resetting Prop
brianm734
Posts: 29
Hello,
I have a little program I put together from a couple of OBEX objects I found. It reads a rotary quadrature encoder and presents the binary count on some pins. When I press a button, the count value is saved to EEPROM so the Prop can be reset or power cycled and the value will come back. This code works fine.
QuadDecodeWithMemory.spin
But now I need three encoders- So I tried using Jeff Martin's wonderful "Quadrature Encoder" object at: http://obex.parallax.com/objects/24/
Now I can read as many encoders as I need to, but this object does not seem to let me give it a starting position value, and it re-zeros the position values every time it starts up. I don't know enough about PASM to be able to modify the code.
Any help would be appreciated.
I have a little program I put together from a couple of OBEX objects I found. It reads a rotary quadrature encoder and presents the binary count on some pins. When I press a button, the count value is saved to EEPROM so the Prop can be reset or power cycled and the value will come back. This code works fine.
QuadDecodeWithMemory.spin
But now I need three encoders- So I tried using Jeff Martin's wonderful "Quadrature Encoder" object at: http://obex.parallax.com/objects/24/
Now I can read as many encoders as I need to, but this object does not seem to let me give it a starting position value, and it re-zeros the position values every time it starts up. I don't know enough about PASM to be able to modify the code.
Any help would be appreciated.
Comments
That was the first thing I tried, because it looked like it was filling those long variables with zeros, but it did not work. It looks like the code down in the PASM area sets the values to zero again.
Have you considered storing the absolute position as a variable in your code and adding the delta (relative position value since last time read) to that ? Unless I misunderstand what you are trying to do this should accomplish the same thing modifying the code would do.
That's a good idea. I will try that. Thanks.
From what you described and what was said in this thread, I thought for sure I had accidentally cleared it in two places. I just reviewed the code and it turns out I clear the Spin memory (Main RAM) and then clear the internal memory (Cog RAM) buffer to "match." The Update routine (PASM) is designed to maintain an internal buffer where every absolute value is kept (for speed reasons) and then, once every sample, the buffer's contents are written out to main RAM.
So the problem you were having was because, 1) the Spin buffer is being cleared, 2) the PASM buffer is being cleared as a separate operation, and 3) the Spin buffer's values are never read into the Cog RAM buffer.
The solution just suggested (keeping absolute separate and adding deltas will certainly work, but if you want to fix it the original way you were trying:
1) Either comment out or remove the line in Start that looks like this:
2) Then change the assembly code near the start of Update from this:
to this:
I haven't had a chance to test this code, but I think it will work.
Here's the version I just hacked together...
Quadrature Encoder (not cleared).spin