Fork

Dependencies:   mbed libscpi

Committer:
wuliqunyy
Date:
Mon Jun 07 12:42:37 2021 +0000
Revision:
22:fd929620e873
Parent:
21:928fbeda074f
Child:
23:0237430bf3ec
back up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wuliqunyy 0:fe3c7dde9771 1 #include "mbed.h"
wuliqunyy 5:daab0e0e67e2 2 #include "main_init.h"
wuliqunyy 6:019ab407ac3c 3 #include "i2c_mbed_fpga.h"
wuliqunyy 16:a0bfe33f8a4a 4 #include "uart_mbed.h"
wuliqunyy 0:fe3c7dde9771 5
wuliqunyy 16:a0bfe33f8a4a 6 #define RAM_END_ADDR 0x4B
wuliqunyy 16:a0bfe33f8a4a 7
wuliqunyy 19:55189aea8f38 8 //#define CLIM_LEVEL 47 //1.5A
wuliqunyy 19:55189aea8f38 9 //#define CLIM_LEVEL 57 //1.8A
wuliqunyy 19:55189aea8f38 10 //#define CLIM_LEVEL 67 //2.1A
wuliqunyy 19:55189aea8f38 11 //#define CLIM_LEVEL 76 //2.4A
wuliqunyy 19:55189aea8f38 12 #define CLIM_LEVEL 86 //2.7A
wuliqunyy 19:55189aea8f38 13 //#define CLIM_LEVEL 95 //3.0A Runda fan setting
wuliqunyy 19:55189aea8f38 14 //#define CLIM_LEVEL 105 //3.3A
wuliqunyy 16:a0bfe33f8a4a 15 // I_LIM (A) = 4A * CLIM_LEVEL/127
wuliqunyy 0:fe3c7dde9771 16
wuliqunyy 0:fe3c7dde9771 17 /* Main function */
wuliqunyy 0:fe3c7dde9771 18 int main() {
wuliqunyy 16:a0bfe33f8a4a 19 char i2cBuffer[3];
wuliqunyy 16:a0bfe33f8a4a 20 char i2cTestPassFlag = 0;
wuliqunyy 22:fd929620e873 21 char i2cRamDumpFlag = 0;
wuliqunyy 22:fd929620e873 22 char i2cTestPulseDebugFlag = 1;
wuliqunyy 6:019ab407ac3c 23
wuliqunyy 6:019ab407ac3c 24 /*init funcitons*/
wuliqunyy 5:daab0e0e67e2 25 i2c_mbed_fpga i2c;
wuliqunyy 6:019ab407ac3c 26 main_init(); /*reset the FPGA!*/
wuliqunyy 3:557d5725b1bb 27
wuliqunyy 6:019ab407ac3c 28 /*control codes*/
wuliqunyy 14:062850afdf38 29 wait_ms(2000); /* keep FPGA in reset for 5s, to let motor stop*/
wuliqunyy 14:062850afdf38 30 enbale_fpga(); /* enable FPGA */
wuliqunyy 20:26e934452728 31 wait_ms(38);
wuliqunyy 20:26e934452728 32 //*(i2cBuffer+0) = (char)(I2C_STATE)& 0xff;
wuliqunyy 20:26e934452728 33 //i2c.i2c_word_read(i2cBuffer);
wuliqunyy 20:26e934452728 34 //uart_print(i2cBuffer);
wuliqunyy 20:26e934452728 35 //wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 36 i2c.i2c_config_mode_entry();
wuliqunyy 14:062850afdf38 37 wait_ms(1);
wuliqunyy 14:062850afdf38 38 i2c.i2c_clear_spd_ctrl();
wuliqunyy 14:062850afdf38 39 wait_ms(1);
wuliqunyy 15:83bbc18cccbc 40 i2c.i2c_set_comm_i_thres(0x0fff,1); //note, 0fff is -1 signed
wuliqunyy 14:062850afdf38 41 wait_ms(1);
wuliqunyy 14:062850afdf38 42 i2c.i2c_set_comm_di_thres(0,1);
wuliqunyy 14:062850afdf38 43 wait_ms(1);
wuliqunyy 14:062850afdf38 44 i2c.i2c_set_fall_time_blank(4);
wuliqunyy 14:062850afdf38 45 wait_ms(1);
wuliqunyy 13:1faffc2dc651 46 i2c.i2c_set_50k_pwm(1);
wuliqunyy 14:062850afdf38 47 wait_ms(1);
wuliqunyy 22:fd929620e873 48 //i2c.i2c_set_position_pulse_width(3,5); /* Runda unsigned int mantisaa_2b, unsigned int exponent_3b*/
wuliqunyy 22:fd929620e873 49 i2c.i2c_set_position_pulse_width(2,4); /* VGA unsigned int mantisaa_2b, unsigned int exponent_3b */
wuliqunyy 14:062850afdf38 50 wait_ms(1);
wuliqunyy 20:26e934452728 51 i2c.i2c_set_position_flat(3,7);
wuliqunyy 20:26e934452728 52 wait_ms(1);
wuliqunyy 12:9f8c7f4da5f6 53 // i2c.i2c_set_position_duty(3);
wuliqunyy 12:9f8c7f4da5f6 54 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 55 // i2c.i2c_set_position_anti_cog(0);
wuliqunyy 12:9f8c7f4da5f6 56 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 57 // i2c.i2c_set_start_up_duty(3);
wuliqunyy 12:9f8c7f4da5f6 58 // wait_ms(10);
wuliqunyy 22:fd929620e873 59 //i2c.i2c_set_start_up_pulse_width(5,6); /*Runda(unsigned int mantisaa_3b, unsigned int exponent_3b*/
wuliqunyy 22:fd929620e873 60 i2c.i2c_set_start_up_pulse_width(3,5); /* VGA (unsigned int mantisaa_3b, unsigned int exponent_3b*/
wuliqunyy 14:062850afdf38 61 wait_ms(1);
wuliqunyy 22:fd929620e873 62 //i2c.i2c_set_start_up_flat(5,6); /*Runda(unsigned int mantisaa_3b, unsigned int exponent_3b*/
wuliqunyy 22:fd929620e873 63 i2c.i2c_set_start_up_flat(3,6); /*VGA (unsigned int mantisaa_3b, unsigned int exponent_3b*/
wuliqunyy 20:26e934452728 64 wait_ms(1);
wuliqunyy 19:55189aea8f38 65 i2c.i2c_set_start_up_num_comm(1);
wuliqunyy 12:9f8c7f4da5f6 66 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 67 // //led4 = i2c.i2c_set_soft_start_up(1, 1, 0, 1, 1);
wuliqunyy 12:9f8c7f4da5f6 68 // wait_ms(10);
wuliqunyy 12:9f8c7f4da5f6 69 // i2c.i2c_clear_spd_ctrl();
wuliqunyy 14:062850afdf38 70 wait_ms(1);
wuliqunyy 14:062850afdf38 71 i2c.i2c_set_loop_mode(0);
wuliqunyy 14:062850afdf38 72 wait_ms(1);
wuliqunyy 14:062850afdf38 73 i2c.i2c_set_curve_type(3);
wuliqunyy 14:062850afdf38 74 wait_ms(1);
wuliqunyy 14:062850afdf38 75 i2c.i2c_set_dc_ini(2);
wuliqunyy 14:062850afdf38 76 wait_ms(1);
wuliqunyy 14:062850afdf38 77 i2c.i2c_set_dc_sr(0);
wuliqunyy 14:062850afdf38 78 wait_ms(1);
wuliqunyy 19:55189aea8f38 79 i2c.i2c_force_rough_reg(0);
wuliqunyy 19:55189aea8f38 80 wait_ms(1);
wuliqunyy 12:9f8c7f4da5f6 81 i2c.i2c_set_rough_gain(0);
wuliqunyy 14:062850afdf38 82 wait_ms(1);
wuliqunyy 14:062850afdf38 83 i2c.i2c_set_ehp_reg_gain(0);
wuliqunyy 14:062850afdf38 84 wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 85 i2c.i2c_set_clim_start_up(CLIM_LEVEL);
wuliqunyy 16:a0bfe33f8a4a 86 wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 87 i2c.i2c_set_clim_brake(CLIM_LEVEL);
wuliqunyy 16:a0bfe33f8a4a 88 wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 89 i2c.i2c_set_clim_run_time(CLIM_LEVEL);
wuliqunyy 16:a0bfe33f8a4a 90 wait_ms(1);
wuliqunyy 15:83bbc18cccbc 91 i2c.i2c_skip_app_copy();
wuliqunyy 15:83bbc18cccbc 92 wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 93
wuliqunyy 16:a0bfe33f8a4a 94 if(i2cRamDumpFlag == 1){
wuliqunyy 16:a0bfe33f8a4a 95 /*dump calibration data start*/
wuliqunyy 16:a0bfe33f8a4a 96 i2c.i2c_mlx_mode_entry();
wuliqunyy 16:a0bfe33f8a4a 97 wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 98 *(i2cBuffer+0) = (char)(I2C_STATUS)& 0xff;
wuliqunyy 16:a0bfe33f8a4a 99 i2c.i2c_word_read(i2cBuffer);
wuliqunyy 16:a0bfe33f8a4a 100 uart_print(i2cBuffer);
wuliqunyy 16:a0bfe33f8a4a 101
wuliqunyy 21:928fbeda074f 102 if( i2cBuffer[2] == 0x0C ){
wuliqunyy 16:a0bfe33f8a4a 103 uart_I2C_test_pass();
wuliqunyy 16:a0bfe33f8a4a 104 i2cTestPassFlag = 1;
wuliqunyy 16:a0bfe33f8a4a 105 led4 = 0;
wuliqunyy 16:a0bfe33f8a4a 106 }
wuliqunyy 16:a0bfe33f8a4a 107 else {
wuliqunyy 16:a0bfe33f8a4a 108 uart_I2C_test_fail();
wuliqunyy 16:a0bfe33f8a4a 109 i2cTestPassFlag = 0;
wuliqunyy 16:a0bfe33f8a4a 110 led4 = 1;
wuliqunyy 16:a0bfe33f8a4a 111 }
wuliqunyy 16:a0bfe33f8a4a 112
wuliqunyy 16:a0bfe33f8a4a 113 if(i2cTestPassFlag == 1){
wuliqunyy 16:a0bfe33f8a4a 114 char i;
wuliqunyy 16:a0bfe33f8a4a 115 for(i=0;i<=RAM_END_ADDR;i++) {
wuliqunyy 16:a0bfe33f8a4a 116 *(i2cBuffer+0) = i;
wuliqunyy 16:a0bfe33f8a4a 117 i2c.i2c_word_read(i2cBuffer);
wuliqunyy 16:a0bfe33f8a4a 118 uart_print(i2cBuffer);
wuliqunyy 16:a0bfe33f8a4a 119 wait_ms(300);
wuliqunyy 16:a0bfe33f8a4a 120 }
wuliqunyy 16:a0bfe33f8a4a 121 uart_ram_dump_finish();
wuliqunyy 16:a0bfe33f8a4a 122 }
wuliqunyy 16:a0bfe33f8a4a 123 }
wuliqunyy 16:a0bfe33f8a4a 124
wuliqunyy 16:a0bfe33f8a4a 125
wuliqunyy 16:a0bfe33f8a4a 126 wait_ms(1);
wuliqunyy 22:fd929620e873 127
wuliqunyy 22:fd929620e873 128 if(i2cTestPulseDebugFlag == 1) {
wuliqunyy 22:fd929620e873 129 i2c.i2c_mlx_mode_entry();
wuliqunyy 22:fd929620e873 130 wait_ms(1);
wuliqunyy 22:fd929620e873 131 i2c.i2c_enable_pules_debug_mode(i2cTestPulseDebugFlag);
wuliqunyy 22:fd929620e873 132 }
wuliqunyy 22:fd929620e873 133
wuliqunyy 22:fd929620e873 134 wait_ms(1);
wuliqunyy 16:a0bfe33f8a4a 135 i2c.i2c_soft_reset();
wuliqunyy 15:83bbc18cccbc 136 wait_ms(40);
wuliqunyy 20:26e934452728 137 i2c.i2c_set_open_loop_duty(0xffff); /*100%*/
wuliqunyy 20:26e934452728 138 //i2c.i2c_set_open_loop_duty(0xf850); /*97%*/
wuliqunyy 6:019ab407ac3c 139
wuliqunyy 6:019ab407ac3c 140 /*enter infinite loop, motor should be running*/
wuliqunyy 5:daab0e0e67e2 141 while (1) {}
wuliqunyy 0:fe3c7dde9771 142
wuliqunyy 0:fe3c7dde9771 143 }