Ben Willems / Mbed 2 deprecated MLX90418_I2C_master_bwi

Dependencies:   mbed

main.cpp

Committer:
wuliqunyy
Date:
2021-05-12
Revision:
15:83bbc18cccbc
Parent:
14:062850afdf38
Child:
16:a0bfe33f8a4a

File content as of revision 15:83bbc18cccbc:

#include "mbed.h"
#include "main_init.h"
#include "i2c_mbed_fpga.h"


/* Main function */
int main() {
    
    /*init funcitons*/
    i2c_mbed_fpga i2c;
    main_init();  /*reset the FPGA!*/ 
    
    /*control codes*/
      wait_ms(2000);   /* keep FPGA in reset for 5s, to let motor stop*/
      enbale_fpga();   /* enable FPGA */ 
      wait_ms(45);      
      i2c.i2c_config_mode_entry();  /*send password 0xd0d0*/
      wait_ms(1);
      i2c.i2c_clear_spd_ctrl();
      wait_ms(1);
      i2c.i2c_set_comm_i_thres(0x0fff,1);  //note, 0fff is -1 signed
      wait_ms(1);
      i2c.i2c_set_comm_di_thres(0,1);
      wait_ms(1);
      i2c.i2c_set_fall_time_blank(4);
      wait_ms(1);
      i2c.i2c_set_50k_pwm(1);    
      wait_ms(1);        
      i2c.i2c_set_position_pulse_width(2,2); /*unsigned int mantisaa_2b, unsigned int exponent_3b*/
      wait_ms(1);
//    i2c.i2c_set_position_duty(3);
//    wait_ms(10);
//    i2c.i2c_set_position_anti_cog(0);
//    wait_ms(10);
//    i2c.i2c_set_start_up_duty(3);
//    wait_ms(10);
      i2c.i2c_set_start_up_pulse_width(3,5); /*(unsigned int mantisaa_3b, unsigned int exponent_3b*/
      wait_ms(1);
//    i2c.i2c_set_start_up_num_comm(3);
//    wait_ms(10);
//    //led4 = i2c.i2c_set_soft_start_up(1, 1, 0, 1, 1);
//    wait_ms(10);
//    i2c.i2c_clear_spd_ctrl();
      wait_ms(1);
      i2c.i2c_set_loop_mode(0);
      wait_ms(1);
      i2c.i2c_set_curve_type(3);
      wait_ms(1);
      i2c.i2c_set_dc_ini(2);
      wait_ms(1);
      i2c.i2c_set_dc_sr(0);
      wait_ms(1);
      i2c.i2c_set_rough_gain(0);
      wait_ms(1);
      i2c.i2c_set_ehp_reg_gain(0);
      wait_ms(1);
      i2c.i2c_skip_app_copy();
      wait_ms(1);
      led4 = i2c.i2c_soft_reset();  /*send password 0xcafe*/
      wait_ms(40);
      i2c.i2c_set_open_loop_duty(0xffff);
    
    /*enter infinite loop, motor should be running*/
    while (1) {}

}