Quantcast
Channel: Motor drivers forum - Recent Threads
Viewing all articles
Browse latest Browse all 14309

MCT8315A: EEPROM WRITING ISSUE AND FG ISSUE

$
0
0
Part Number: MCT8315A

Tool/software:

Hello ,

I'm working on MCT8315A I need to program the EEPROM via I2C before putting it in a device , So i use a linux SBC to communicate with it.

But i have a issue that make impossible for me to put the parameters in the chip (Only using the evaluation board and connecting I2C to my custom board i can change values ).

Here the schematic to see if there is issue (Powered in 5V)



And my C code

int write_SHADOW_REGISTER_MCT8315A(int reg,int32_t data){

	char buf[10];	
	buf[0]=0x10; //No CRC 
	buf[1]=0x00;
	buf[2]=reg;
	buf[3]=data;
	buf[4]=data>>8;
	buf[5]=data>>16;
	buf[6]=data>>24;


	//printf("REG 0x%02x DATA : 0x%07x \n",reg,data); 

	//printf(" val %ld %d \n",write(file, buf, 7),errno);
	if (write(file, buf, 7) != 7) {
		printf("error writing at reg 0x%02x \n",reg);
		return -1;
	}
	return 0;
}

int write_SHADOW_TO_EEPROM_MCT8315A(){
	
	char buf[10];
	buf[0]=0x10; //No CRC
	buf[1]=0x00;
	buf[2]=0xE6; //SHADOW REGISTER
	buf[3]=0x00; //COMMAND
	buf[4]=0x00; //COMMAND
	buf[5]=0x50; //COMMAND
	buf[6]=0x8A; //COMMAND
 
    if (write(file, buf, 7) != 7) {
		printf("error sending I2C copy to EEPROM\n");
		return -1;
	}

	delay(1000); //WAIT FOR EEPROM WRITING
	return 0;
	
}

int copy_EEPROM_TO_SHADOW_REGISTER_MCT8315A(){
	
	//COPING EEPROM TO SHADOW REGISTER
	char buf[10];
	buf[0]=0x10; //No CRC
	buf[1]=0x00;
	buf[2]=0xE6; //SHADOW REGISTER
	buf[3]=0x00; //COMMAND
	buf[4]=0x00; //COMMAND
	buf[5]=0x00; //COMMAND
	buf[6]=0x40; //COMMAND

	if (write(file, buf, 7) != 7) {
		printf("error sending command copy EEPROM to shadow register\n");
		return -1;
	}

	delay(400);
	return 0;	
}

int read_REGISTER_MCT8315A(int reg, int32_t data) {
    char buf[10];

    // READ SHADOW REGISTER
    buf[0] = 0x90;
    buf[1] = 0x00;
    buf[2] = reg;
    

    if (write(file, buf, 3) != 3) {
        printf("error writing command read shadow register\n");
        return -1;
    }

    if (read(file, buf, 4) != 4) {
        printf("error reading from register\n");
        return -1;
    } else {
        int j = 24;
        char var_cast = 0;

        for (int i = 3; i >= 0; i--) {
            var_cast = (data >> j) & 0xFF;
            if (buf[i] != var_cast) {
                // Affiche uniquement en cas d'erreur
                printf("Error validating register 0x%02x:\n", reg);
                printf("Expected: 0x%08x\n", data);
                printf("Received: 0x%02x%02x%02x%02x\n", buf[3], buf[2], buf[1], buf[0]);
                return -1;
            }
            j -= 8;
        }
    }

    return 0;
}



			delay(1000);
			// Stop motor
			write_SHADOW_REGISTER_MCT8315A(0xE8 ,0x00008000);
			delay(1000);

			// Clear faults
			write_SHADOW_REGISTER_MCT8315A(0xE6,0x30000000);
			delay(100);

			// Effectuer les écritures
			int i = 0;  // Indice pour parcourir le tableau des valeurs
			for (int j = 0; j < num_registres; j++) {
				if (!is_commente(registres[j])) {  // Si ce n'est pas un registre commenté
					printf("registre [0x%X] data : 0x%08x\n",registres[j], values[i]);
					int fault = write_SHADOW_REGISTER_MCT8315A(registres[j], values[i++]);	
					if (fault != 0) {
						printf("Erreur lors de l'écriture dans le registre 0x%X\n", registres[j]);	
						status_error();
						pthread_create(&LED_Fade_thread_Handle, NULL, LED_Fade, NULL);
						return;
					}
				} else {
					//printf("Registre 0x%X ignoré (commenté).\n", registres[j]);
					i++;  
				}
			}

			printf("Écriture des registres terminée.\n");

			// EEPROM write command
			write_SHADOW_TO_EEPROM_MCT8315A();

            int retry = 10;
			while (retry--) {
				if (read_REGISTER_MCT8315A(0xE6, 0x00000000) == 0) {
					break; // EEPROM write done
				}
				delay(100); // wait 100ms before retry
			}
			if (retry < 0) {
				printf("Erreur : EEPROM write timeout\n");
				// gérer erreur
			}


			digitalWrite(PIN_CMD_RELAY,RELAY_DRIVER_BOARD_OFF);
			delay(2000);
			digitalWrite(PIN_CMD_RELAY,RELAY_DRIVER_BOARD_ON);
			delay(2000);

			copy_EEPROM_TO_SHADOW_REGISTER_MCT8315A();

			// Stop motor
			write_SHADOW_REGISTER_MCT8315A(0xE8 ,0x00008000);
			delay(1000);

			// Clear faults
			write_SHADOW_REGISTER_MCT8315A(0xE6,0x30000000);
			delay(100);
			i=0;
			// Effectuer les lectures depuis les registres
			for (int j = 0; j < num_registres; j++) {
				if (!is_commente(registres[j])) {
					int fault=read_REGISTER_MCT8315A(registres[j], values[i++]);
					printf("%d \n",i);
					if (fault != 0) {
						status_error();
						pthread_create(&LED_Fade_thread_Handle, NULL, LED_Fade, NULL);
						return;
					}
				} else {
					//printf("Registre 0x%X ignoré (commenté).\n", registres[j]);
					i++;
				}
			}

Here the result in my terminal

registre [0x80] data : 0x6f044300
registre [0x82] data : 0x0ea89187
registre [0x84] data : 0x1a250aa4
registre [0x86] data : 0x000a0200
registre [0x88] data : 0x01a624b0
registre [0x8A] data : 0x4cc40101
registre [0x8C] data : 0x000ce944
registre [0x8E] data : 0x00401405
registre [0x90] data : 0x06a44c80
registre [0x96] data : 0x36db6da6
registre [0x98] data : 0x36db6d80
registre [0x9A] data : 0x054ba106
registre [0x9C] data : 0x52880000
registre [0x92] data : 0x78fc5035
registre [0x94] data : 0x7447a009
registre [0xAC] data : 0x14440200
registre [0xAE] data : 0x14c00000
registre [0xA4] data : 0x2d720640
registre [0xA6] data : 0x080c0800
registre [0xA8] data : 0x7fff4000Écriture des registres terminée.
Error validating register 0xe6:
Expected: 0x00000000
Received: 0x8a500000

So basically I2C works in write and read (i can read shadow register and write to it ) but the callback of 0xE6 is never at 0 so the EEPROM is never written


Also i have a other issue with FG pin.

When the motor is locked or unplugged at the intervall of LCK_RETRY i can see a signal of FG pin (the chip try to restart the motor).

But in my device that use this chip (unpossible to modify firmare) it detects it as a working motor and leads to issue.

How can i fix it with the MCT8315A still  be able to restart a motor if locked

Here my profile :

{"signature": "oneui-register-data","data": [
    [
      {"idx": 0,"id": "isd_config","value": "0x6F044300"
      },
      {"idx": 1,"id": "motor_startup1","value": "0x0EA89187"
      },
      {"idx": 2,"id": "motor_startup2","value": "0x1A250AA4"
      },
      {"idx": 3,"id": "closed_loop1","value": "0x000A0200"
      },
      {"idx": 4,"id": "closed_loop2","value": "0x01A624B0"
      },
      {"idx": 5,"id": "closed_loop3","value": "0x4CC40101"
      },
      {"idx": 6,"id": "closed_loop4","value": "0x000CE944"
      },
      {"idx": 7,"id": "const_speed","value": "0x00401405"
      },
      {"idx": 8,"id": "const_pwr","value": "0x06A44C80"
      },
      {"idx": 9,"id": "150_deg_two_ph_profile","value": "0x36DB6DA6"
      },
      {"idx": 10,"id": "150_deg_three_ph_profile","value": "0x36DB6D80"
      },
      {"idx": 11,"id": "trap_config1","value": "0x054BA106"
      },
      {"idx": 12,"id": "trap_config2","value": "0x52880000"
      }
    ],
    [
      {"idx": 0,"id": "fault_config1","value": "0x78FC5035"
      },
      {"idx": 1,"id": "fault_config2","value": "0x7447A009"
      }
    ],
    [
      {"idx": 0,"id": "gd_config1","value": "0x14440200"
      },
      {"idx": 1,"id": "gd_config2","value": "0x14C00000"
      }
    ],
    [
      {"idx": 0,"id": "pin_config1","value": "0x2D720640"
      },
      {"idx": 1,"id": "pin_config2","value": "0x080C0800"
      },
      {"idx": 2,"id": "device_config","value": "0x7FFF4000"
      },
      {"idx": 3,"id": "peri_config","value": "0x00000000"
      }
    ],
    [
      {"idx": 0,"id": "ana_trim3","value": "0x4A004800"
      },
      {"idx": 1,"id": "ana_trim4","value": "0x00000000"
      },
      {"idx": 2,"id": "ana_trim5","value": "0x00000016"
      },
      {"idx": 3,"id": "ana_trim6","value": "0x00000000"
      },
      {"idx": 4,"id": "ana_trim7","value": "0x00000000"
      },
      {"idx": 5,"id": "ana_trim8","value": "0x00005085"
      },
      {"idx": 6,"id": "ana_trim9","value": "0x0091F81F"
      },
      {"idx": 7,"id": "ana_trim10","value": "0x536AF038"
      }
    ],
    [
      {"idx": 0,"id": "algo_reserved1","value": "0x00000000"
      },
      {"idx": 1,"id": "algo_reserved2","value": "0x00000000"
      },
      {"idx": 2,"id": "algo_reserved3","value": "0x00000000"
      }
    ],
    [
      {"idx": 0,"id": "gate_driver_fault_status","value": "0x00000000"
      },
      {"idx": 1,"id": "controller_fault_status","value": "0x00000000"
      }
    ],
    [
      {"idx": 0,"id": "sys_status1","value": "0x0031EC90"
      },
      {"idx": 1,"id": "sys_status2","value": "0x20010674"
      },
      {"idx": 2,"id": "sys_status3","value": "0x003B004A"
      }
    ],
    [
      {"idx": 0,"id": "device_ctrl","value": "0x00000000"
      }
    ],
    [
      {"idx": 0,"id": "algo_ctrl1","value": "0x8A500000"
      }
    ]
  ]
}


Thanks for the answer

Viewing all articles
Browse latest Browse all 14309

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>