Lab 6 code.
Dependencies: mbed
Fork of WaG by
Diff: stepper.cpp
- Revision:
- 20:d23bcd97f2c5
- Parent:
- 18:0e281922212c
- Child:
- 21:88f9f280931b
--- a/stepper.cpp Fri Mar 02 22:20:43 2018 +0000 +++ b/stepper.cpp Tue Mar 06 17:25:48 2018 +0000 @@ -18,16 +18,19 @@ #include "stepper.h" DigitalOut stp_ncs(STP_DRV8806_NCS); +DigitalIn jog_ccw(D4); +DigitalIn jog_cw(D5); + +int stp_cur_pos; +int stp_sensor_pos[NUM_SENSORS + 1]; extern spi_cfg drv8806 { SPI_DRV8806_ID, STP_DRV8806_NCS, - 0, - 1000000, - 8, + DRV8806_SPI_MODE, + DRV8806_SPI_FREQ, + DRV8806_SPI_NO_BITS, }; -int stp_cur_pos; -int stp_sensor_pos[NUM_SENSORS + 1] /* * void stp_init(); @@ -41,7 +44,7 @@ * Returns: void */ void stp_init() { - stp_cur_pos = STP_POS_UNKN + stp_cur_pos = STP_POS_UNKN; for (int i = 1; i <= NUM_SENSORS; i++) { stp_sensor_pos[i] = STP_POS_UNKN; } @@ -60,5 +63,18 @@ * Returns: void */ void stp_step(int direction) { + jog_cw.mode(PullUp); + jog_ccw.mode(PullUp); + + //static int cur_pos = stp_cur_pos; + static int turn[4] = {0x03, 0x06, 0x0c, 0x09}; + if (direction == STP_CW) { + for (int i = 0; i < 4; i++) + spi_send(drv8806, turn[i]); + } + else if (direction == STP_CCW) { + for (int i = 3; i >= 0; i--) + spi_send(drv8806, turn[i]); + } } \ No newline at end of file