Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@12:9f8c7f4da5f6, 2021-03-24 (annotated)
- Committer:
- wuliqunyy
- Date:
- Wed Mar 24 14:17:25 2021 +0000
- Revision:
- 12:9f8c7f4da5f6
- Parent:
- 11:b86aea372744
- Child:
- 13:1faffc2dc651
doe2 version
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:fe3c7dde9771 | 4 | |
wuliqunyy | 0:fe3c7dde9771 | 5 | |
wuliqunyy | 0:fe3c7dde9771 | 6 | /* Main function */ |
wuliqunyy | 0:fe3c7dde9771 | 7 | int main() { |
wuliqunyy | 6:019ab407ac3c | 8 | |
wuliqunyy | 6:019ab407ac3c | 9 | /*init funcitons*/ |
wuliqunyy | 5:daab0e0e67e2 | 10 | i2c_mbed_fpga i2c; |
wuliqunyy | 6:019ab407ac3c | 11 | main_init(); /*reset the FPGA!*/ |
wuliqunyy | 3:557d5725b1bb | 12 | |
wuliqunyy | 6:019ab407ac3c | 13 | /*control codes*/ |
wuliqunyy | 9:76a0b9f29a2d | 14 | wait_ms(2000); /* keep FPGA in reset for 5s, to let motor stop*/ |
wuliqunyy | 9:76a0b9f29a2d | 15 | enbale_fpga(); /* enable FPGA */ |
wuliqunyy | 12:9f8c7f4da5f6 | 16 | wait_ms(3); |
wuliqunyy | 6:019ab407ac3c | 17 | led4 = i2c.i2c_window_open(); /*send password 0xd0d0*/ |
wuliqunyy | 12:9f8c7f4da5f6 | 18 | wait_ms(1); |
wuliqunyy | 12:9f8c7f4da5f6 | 19 | led4 = i2c.i2c_window_open(); /*send password 0xd0d0*/ |
wuliqunyy | 12:9f8c7f4da5f6 | 20 | wait_ms(1); |
wuliqunyy | 11:b86aea372744 | 21 | i2c.i2c_clear_spd_ctrl(); |
wuliqunyy | 12:9f8c7f4da5f6 | 22 | wait_ms(1); |
wuliqunyy | 12:9f8c7f4da5f6 | 23 | // i2c.i2c_set_50k_pwm(1); |
wuliqunyy | 12:9f8c7f4da5f6 | 24 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 25 | i2c.i2c_set_position_pulse_width(3,3); /*unsigned int mantisaa_2b, unsigned int exponent_3b*/ |
wuliqunyy | 12:9f8c7f4da5f6 | 26 | wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 27 | // i2c.i2c_set_position_duty(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 28 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 29 | // i2c.i2c_set_position_anti_cog(0); |
wuliqunyy | 12:9f8c7f4da5f6 | 30 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 31 | // i2c.i2c_set_start_up_duty(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 32 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 33 | i2c.i2c_set_start_up_pulse_width(3,5); /*(unsigned int mantisaa_3b, unsigned int exponent_3b*/ |
wuliqunyy | 12:9f8c7f4da5f6 | 34 | wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 35 | // i2c.i2c_set_start_up_num_comm(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 36 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 37 | // i2c.i2c_set_curve_type(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 38 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 39 | // i2c.i2c_set_loop_mode(0); |
wuliqunyy | 12:9f8c7f4da5f6 | 40 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 41 | // //led4 = i2c.i2c_set_soft_start_up(1, 1, 0, 1, 1); |
wuliqunyy | 12:9f8c7f4da5f6 | 42 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 43 | // i2c.i2c_clear_spd_ctrl(); |
wuliqunyy | 12:9f8c7f4da5f6 | 44 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 45 | // i2c.i2c_set_loop_mode(0); |
wuliqunyy | 12:9f8c7f4da5f6 | 46 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 47 | // i2c.i2c_set_curve_type(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 48 | // wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 49 | // i2c.i2c_set_dc_ini(2); |
wuliqunyy | 12:9f8c7f4da5f6 | 50 | // wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 51 | // i2c.i2c_set_dc_sr(2); |
wuliqunyy | 12:9f8c7f4da5f6 | 52 | wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 53 | i2c.i2c_set_rough_gain(0); |
wuliqunyy | 12:9f8c7f4da5f6 | 54 | wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 55 | i2c.i2c_set_open_loop_duty(0x8000); |
wuliqunyy | 12:9f8c7f4da5f6 | 56 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 57 | // i2c.i2c_set_comm_i_thres(15,1); |
wuliqunyy | 12:9f8c7f4da5f6 | 58 | wait_ms(3); |
wuliqunyy | 12:9f8c7f4da5f6 | 59 | i2c.i2c_set_comm_di_thres(0,1); |
wuliqunyy | 12:9f8c7f4da5f6 | 60 | // wait_ms(10); |
wuliqunyy | 12:9f8c7f4da5f6 | 61 | // led4 = i2c.i2c_motor_start(); /*send password 0xcafe*/ |
wuliqunyy | 6:019ab407ac3c | 62 | |
wuliqunyy | 6:019ab407ac3c | 63 | /*enter infinite loop, motor should be running*/ |
wuliqunyy | 5:daab0e0e67e2 | 64 | while (1) {} |
wuliqunyy | 0:fe3c7dde9771 | 65 | |
wuliqunyy | 0:fe3c7dde9771 | 66 | } |