Good way to do table indexing?
ManAtWork
Posts: 2,176
in Propeller 2
I need a state machine to handle the auto-calibration of multiple ADC pins. I plan to use a table where the pin modes (ain/gio/vio switching), source/destination indexes for calculations, duration and next state and possibly some skip masks to influence behaviour of the code are stored for each of the states.
As I don't have much experience coding in P2 assembler I wonder what could be the best way to handle indexing of the pins and table data. As I have to iterate both through the table entries and through the pin numbers I need some sort of double indirection for some operations.
I've seen there are the ALTS/D/R instructions for that purpose. I think I could place the table in hub RAM and do a burst transfer (SETQ+RDLONG) to read the table entries to variables in cog RAM whenever the state changes. Then, once per sampling period I coult iterate through the pin numbers. Unfortunatelly, due to hardware constraints the pins don't have consecutive numbers so I have to use a second table. This would result in almost every instruction in my loop having at least one preceding ALTS/D instruction. But the only alternative I see would be a hardcoded unrolled loop with almost identical code repeated 10 states * 6 pins = 60 times.
In spite of the name of the LUT RAM I think it's not suited very well for my purpose. I don't know if the RDLUT command supports indexing (PTRA[]...) as RDLONG/WORD/BYTE does. And the $200 address works for code execution only and not for data access if I read the docs correctly.
Has anybody already done something similar and could give me some advice?
As I don't have much experience coding in P2 assembler I wonder what could be the best way to handle indexing of the pins and table data. As I have to iterate both through the table entries and through the pin numbers I need some sort of double indirection for some operations.
I've seen there are the ALTS/D/R instructions for that purpose. I think I could place the table in hub RAM and do a burst transfer (SETQ+RDLONG) to read the table entries to variables in cog RAM whenever the state changes. Then, once per sampling period I coult iterate through the pin numbers. Unfortunatelly, due to hardware constraints the pins don't have consecutive numbers so I have to use a second table. This would result in almost every instruction in my loop having at least one preceding ALTS/D instruction. But the only alternative I see would be a hardcoded unrolled loop with almost identical code repeated 10 states * 6 pins = 60 times.
In spite of the name of the LUT RAM I think it's not suited very well for my purpose. I don't know if the RDLUT command supports indexing (PTRA[]...) as RDLONG/WORD/BYTE does. And the $200 address works for code execution only and not for data access if I read the docs correctly.
Has anybody already done something similar and could give me some advice?
Comments
BTW, doing both ALTS and ALTD on one instruction doesn't work, does it. The first ALTS would modify the source of the ALTD instead of the following instruction intended for the actual data transfer.
However, two consecutive ALT instructions could also be useful the way they work now. It could be used for adding three instead of two values (index1 + index2 + base address) for two dimensional arrays.
Hmm, does that mean that means "c *= (a+b)&$1ff"? That sounds quite useful.