![]() XPOR! ( data adr - ) \ OR data with XP array XP! ( data adr - ) \ Store data into XP array LADDER LOGIC RUNTIME BYTECODE ( adr - data ) \ read data from XP array The compilation of the X position can be optimized to say 4-bits as part of the opcode. *** TOTAL OF 87 BYTES *** Assuming byte codes also encode literal values directly |/|- 32 TEST INVERT AND Read input 003, INVERT then AND with stack |- 30 OR Read X position 30 memory and OR with stack | |- 4 TEST AND Read value of input Y000 and AND with stack | |- 13 TEST AND Read value of input 007 and AND with stack | |- 4 TEST AND Read value of input 006 and AND with stack | 30 XPOR! POP stack and OR with X position 30 memory |/|- 22 TEST INVERT AND Read input 002, INVERT then AND with stack |- 20 OR OR with X position memory - save on stack | |- 13 TEST AND Read value of input 005 (taken from X position memory) and AND with stack | |- 4 TEST AND Read value of input 004 (taken from X position memory) and AND with stack ![]() X005 5 13 XP! Mark X postion 13 with value of 005 X004 4 4 XP! Mark postion 4 with value of 004 | 20 XPOR! POP stack and OR with X position 20 memory | |- 13 TEST AND Read value of input 001 (taken from X position memory) and AND with stack | |- 4 TEST AND Read value of input 000 (taken from X position memory) and AND with stack Y000 0 58 XP! Mark X postion 58 with value of 000 X003 3 32 XP! Mark X postion 32 with value of 003 X002 2 22 XP! Mark X postion 22 with value of 002 X001 1 13 XP! Mark X postion 13 with value of 001 ![]() X000 0 4 XP! Mark X postion 4 with value of 000 X Y Signal - Read value and mark this position along the line as that value (offset Y label values) ( Output - STORE data from stack to output |/|- Input N/C - INVERT and AND with data stack |- Left junction - push TRUE onto data stack With a Forth itself or a simple engine written in assembler or Spin.Ī brief step-through is given below. The labels and symbols are compiled as byte tokens which are then interpreted by the runtime engine in Forth fashion either Symbols are extracted from the input stream and simple rules are applied working off the X position memory and a data stack. The parser can read the labels and assign them to a memory corresponding to it's X position on the line. The ladder diagram is an ASCII text file representing the ladder logic Of course the Prop could use it's font characters in place of the standard characters to improve the display if compiling on the Prop and yet the parser remains the same. Otherwise a compiler could be written in VB or whatever to generate the byte codes. It's after midnight and I had a very late night last night so I may have missed a few things but bear with me.įor a stand-alone system the compiler could be written in Spin itself and the ladder logic diagram could be stored as a text file either in EEPROM or SD card on the target. Where the symbol starts on a line is the index into the line array where labels and data are stored. The label for this was parsed on the preceding line and it remembers the value of the label from the position on the line. When the parser sees certain character sequences such as -|/|- it interprets this as a normally closed signal. By using very simple rules it should be possible to extract the symbols and generate interpreted byte codes to represent the operation. Imagine the diagram is coded in ASCII characters to represent the various functions and that this closely matches a normal ladder diagram. Here's an idea for a dirt simple Ladder Logic compiler. Ron Nollet mentioned it would be good to be able program in Ladder Logic, the language of PLCs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |