Skip to content

Commit

Permalink
Stepper supports microstepping via JSON and theoretically UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonbrown2 committed Jun 19, 2016
1 parent 59087ac commit 5d1469b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
19 changes: 19 additions & 0 deletions src/command_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ void ICACHE_FLASH_ATTR json_process_command(char *json_input)
{
break;
}
case 'U':
{
os_printf("U\n");
struct stepper_command_packet parsed_motor_command;
parsed_motor_command.port = 0;
parsed_motor_command.opcode = json_opcode;
parsed_motor_command.motor_id = 0;
parsed_motor_command.queue = (*(json_input + tokens[place+4].start) == '1') ? 0x01 : 0x00;
parsed_motor_command.step_num = 0;
unsigned short ustep_setting = *(json_input + tokens[place+5].start) - 48;
parsed_motor_command.step_rate = ntohs(ustep_setting);
motor_process_command(&parsed_motor_command, dummy_ip);
place += 6;
break;
}
case 'B':
//servo bounds
{
Expand Down Expand Up @@ -246,6 +261,10 @@ void issue_command(char motor_id)
//ntohl(command.step_num), ntohs(command.step_rate));
opcode_goto(ntohl(command[motor_id].step_num), ntohs(command[motor_id].step_rate), motor_id);
}
else if(command[motor_id].opcode == 'U')
{
change_motor_setting(MICROSTEPPING, ntohs(command[motor_id].step_rate));
}
else
{
os_printf("Opcode not found!\n");
Expand Down
19 changes: 13 additions & 6 deletions src/stepper_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
#define GPIO_STEP_ENABLE 5
#define GPIO_STEP_DIR 13
#define GPIO_USTEP_A 0
#define GPIO_USTEP_B 14
#define GPIO_USTEP_C 12
#define GPIO_IO_A 14
#define GPIO_IO_B 12

#define GPIO_USTEP_A_MASK 0x0001
#define GPIO_STEP_MASK 0x0010
#define GPIO_STEP_ENABLE_MASK 0x0020
#define GPIO_USTEP_C_MASK 0x1000
#define GPIO_IO_B_MASK 0x1000
#define GPIO_STEP_DIR_MASK 0x2000
#define GPIO_USTEP_B_MASK 0x4000
#define GPIO_USTEP_ALL_MASK 0x5001
#define GPIO_IO_A_MASK 0x4000
#define GPIO_NOSTEP_MASK 0x7021
#define GPIO_NODIR_MASK 0x5031
#define GPIO_ALL_MASK 0x7031
Expand Down Expand Up @@ -55,7 +54,7 @@ void init_motor_gpio()

GPIO_REG_WRITE(GPIO_ENABLE_W1TS_ADDRESS, GPIO_ALL_MASK);
GPIO_REG_WRITE(GPIO_ENABLE_W1TC_ADDRESS, ~GPIO_ALL_MASK);
GPIO_MASK_WRITE(GPIO_USTEP_ALL_MASK);
GPIO_MASK_WRITE(GPIO_USTEP_A_MASK);
}

void step_driver ( void )
Expand Down Expand Up @@ -157,6 +156,14 @@ void ICACHE_FLASH_ATTR change_motor_setting(config_setting input, int data)
case MAX_SERVO_BOUND:
break;
case MICROSTEPPING:
if(data > 0)
{
GPIO_MASK_WRITE(GPIO_REG_READ(GPIO_OUT_ADDRESS) | GPIO_USTEP_A_MASK);
}
else
{
GPIO_MASK_WRITE(GPIO_REG_READ(GPIO_OUT_ADDRESS) & (~GPIO_USTEP_A_MASK));
}
break;
}
}
Expand Down

0 comments on commit 5d1469b

Please sign in to comment.