| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| mpfj 
 
 
 Joined: 09 Sep 2003
 Posts: 95
 Location: UK
 
 
			        
 
 | 
			
				| Another table read bug |  
				|  Posted: Fri Feb 20, 2004 6:45 am |   |  
				| 
 |  
				| Compiler version : 3v185 PIC type : 18F8720
 
 I have a structure defined as follows ...
 
 
  	  | Code: |  	  | typedef struct {
 int8 byte_count;
 int1 multiple;
 int1 broadcast;
 } modbus_function_struct;
 
 const modbus_function_struct modbus_function[MODBUS_NUM_FUNCTIONS] = {
 {8, false, false},   // read coil status (digout readback)
 {8, false, false},   // read input status
 {8, false, false},   // read holding register (output register readback)
 {8, false, false},   // read input register
 {8, false, true},   // force single coil
 {8, false, true},   // preset single register
 {4, false, false},   // read exception status
 {8, false, false},   // loopback diagnostic test
 {0, false, false},
 {0, false, false},
 {0, false, false},
 {0, false, false},
 {0, false, false},
 {0, false, false},
 {7, true, true},   // force multiple coils
 {7, true, true}      // preset multiple registers
 };
 
 | 
 
 The "const" function generated is as follows ...
 
 
  	  | Code: |  	  | 0E84:  MOVFF  FF2,0E
 0E88:  BCF    FF2.7
 0E8A:  CLRF   FF7
 0E8C:  ADDLW  A2
 0E8E:  MOVWF  FF6
 0E90:  MOVLW  0E
 0E92:  ADDWFC FF7,F
 0E94:  MOVLW  00
 0E96:  MOVWF  FF8
 0E98:  TBLRD*+
 0E9A:  MOVF   FF5,W    <------ here the result is placed in the WREG
 0E9C:  BTFSC  0E.7
 0E9E:  BSF    FF2.7
 0EA0:  RETURN 0
 0EA2:  DATA 08,00
 0EA4:  DATA 08,00
 0EA6:  DATA 08,00
 0EA8:  DATA 08,00
 0EAA:  DATA 08,02
 0EAC:  DATA 08,02
 0EAE:  DATA 04,00
 0EB0:  DATA 08,00
 0EB2:  DATA 00,00
 0EB4:  DATA 00,00
 0EB6:  DATA 00,00
 0EB8:  DATA 00,00
 0EBA:  DATA 00,00
 0EBC:  DATA 00,00
 0EBE:  DATA 07,03
 0EC0:  DATA 07,03
 
 | 
 
 Note that the result of the table read is placed in the WREG.
 
 Now, when I request "byte_count", the compiler produces the following ...
 
 
  	  | Code: |  	  | ....................          // set message size
 ....................          message_size = modbus_function[modbus.func].byte_count;
 AF0E:  BCF    FD8.0
 AF10:  RLCF   x21,W
 AF12:  MOVLB  C
 AF14:  CLRF   x0D
 AF16:  MOVWF  x0C
 AF18:  MOVLB  0
 AF1A:  MOVFF  C0D,03
 AF1E:  MOVLB  C
 AF20:  MOVF   x0C,W
 AF22:  MOVLB  0
 AF24:  CALL   0E84
 AF28:  MOVWF  01
 AF2A:  MOVFF  01,C0B
 
 | 
 
 Note that after the CALL 0E84 instruction, the WREG is accessed, thus using the correct value.
 
 *BUT* when I access one of the int1 values, e.g. "multiple", the following code is generated ...
 
 
  	  | Code: |  	  | ....................          // are we expecting any additional bytes ??
 ....................          if (modbus_function[modbus.func].multiple) {
 AF2E:  BCF    FD8.0
 AF30:  MOVLB  A
 AF32:  RLCF   x21,W
 AF34:  MOVLB  C
 AF36:  CLRF   x0D
 AF38:  MOVWF  x0C
 AF3A:  MOVLW  01
 AF3C:  ADDWF  x0C,W
 AF3E:  MOVWF  01
 AF40:  MOVLW  00
 AF42:  ADDWFC x0D,W
 AF44:  MOVWF  03
 AF46:  MOVF   01,W
 AF48:  MOVLB  0
 AF4A:  CALL   0E84
 AF4E:  CLRF   08
 AF50:  BTFSC  00.0
 AF52:  INCF   08,F
 AF54:  BTFSS  01.0
 AF56:  GOTO   AF84
 
 | 
 
 As you might notice, after the CALL 0E84 instruction, absolutely *no* access to the WREG is made !!!!
   
 Am I missing something, or should I report this to CCS ?
 
 Mark
 |  |  
		|  |  
		| mpfj 
 
 
 Joined: 09 Sep 2003
 Posts: 95
 Location: UK
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Fri Feb 27, 2004 3:34 am |   |  
				| 
 |  
				| This has been fixed in 3v186 ... 
 ... actually it hasn't !!  They claim it has been, but the bug is still there !!
 
 Oops ...
 |  |  
		|  |  
		| Neutone 
 
 
 Joined: 08 Sep 2003
 Posts: 839
 Location: Houston
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Fri Feb 27, 2004 8:30 am |   |  
				| 
 |  
				| I posted some code that does table reads not very long ago. It is also part of a MODBUS routine. It works fine. I suspect your problem is due in part to the syntax you are using. When recieving packets in MODBUS protocol there is a requirement that the bytes within the packet are not followed by a pause greater than 1.5 byte times between bytes. Simply counting bytes as the are recieved will not detect this and is more dificult to impliment. If you look at my other post you will see a working example of this. |  |  
		|  |  
		| mpfj 
 
 
 Joined: 09 Sep 2003
 Posts: 95
 Location: UK
 
 
			        
 
 | 
			
				|  |  
				|  Posted: Fri Feb 27, 2004 8:42 am |   |  
				| 
 |  
				| My modbus code works fine  And in most cases table reads work fine. 
 It is only when you have an array of structures (which contain int1 variables) that things go wrong.
 
 Try compiling the following program and inspect the code generated for the last instruction ...
 
 
  	  | Code: |  	  | #include <18F8720.h> 
 typedef struct {
 int8 byte_count;
 int1 multiple;
 int1 broadcast;
 } a_struct;
 
 const a_struct a_function[16] = {
 {8, false, false},   // read coil status (digout readback)
 {8, false, false},   // read input status
 };
 
 void main() {
 int8 i;
 int1 j;
 int8 k;
 
 // init index
 k = 0;
 
 // here we read the int8 value
 i = a_function[k].byte_count;
 
 // here we read one of the int1 values
 j = a_function[k].multiple;
 }
 
 | 
 Notice how the table lookup routine returns its value in the WREG, but it's not used in the code.
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |