Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b556b02e03 |
No files matched your search
@@ -114,6 +114,8 @@ extern SPI_HandleTypeDef hspi1;
|
||||
void green_led();
|
||||
void red_led();
|
||||
void blink_yellow_led();
|
||||
void yellow_led_start();
|
||||
void yellow_led_stop();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static void SPINDLE_SetDutyCycle(SpindleHandle_t h, void* context, int backwards
|
||||
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, pulse);
|
||||
}
|
||||
|
||||
printf("duty=%f backwards=%d pulse=%lu\n", dutyCycle, backwards, (unsigned long)pulse);
|
||||
//printf("duty=%f backwards=%d pulse=%lu\n", dutyCycle, backwards, (unsigned long)pulse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,18 @@ L6474_Handle_t init_stepper(void* pIO, void* pGPO, void* pPWM){
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
static int stepper_check_status(L6474_Handle_t s){
|
||||
L6474_Status_t st;
|
||||
if(L6474_GetStatus(s, &st) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
if(st.UVLO || st.TH_SD || st.OCD || st.NOTPERF_CMD || st.WRONG_CMD){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reset_stepper(L6474_Handle_t s){
|
||||
|
||||
L6474_BaseParameter_t b;
|
||||
@@ -108,57 +120,51 @@ int reset_stepper(L6474_Handle_t s){
|
||||
result |= L6474_ResetStandBy(s);
|
||||
result |= L6474_Initialize(s, &b);
|
||||
result |= L6474_SetPowerOutputs(s, 0);
|
||||
yellow_led_stop();
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
#define REF_MAX_STEPS (mm_to_step(150))
|
||||
|
||||
int stepper_reference(L6474_Handle_t s, int flag){
|
||||
L6474_SetPowerOutputs(s, 1);
|
||||
if(L6474_SetPowerOutputs(s, 1) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
yellow_led_start();
|
||||
//flag: 0 keiner, 1 -t, 2 -e, 3 -s
|
||||
|
||||
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
|
||||
if(L6474_StepIncremental(s, mm_to_step(5)) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
if(stepper_check_status(s)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
L6474_StepIncremental(s, mm_to_step(5));
|
||||
|
||||
int button_pressed = 0;
|
||||
|
||||
while(!button_pressed){
|
||||
// zum Schalter fahren, mit Limit und Statuspruefung
|
||||
int steps = 0;
|
||||
while(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) != GPIO_PIN_RESET){
|
||||
if(L6474_StepIncremental(s, -1) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
|
||||
button_pressed=1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if((++steps % 100) == 0 && stepper_check_status(s)){
|
||||
return 1;
|
||||
}
|
||||
if(steps > REF_MAX_STEPS){
|
||||
return 1; // Schalter nie erreicht
|
||||
}
|
||||
|
||||
}
|
||||
if(flag == 3){
|
||||
L6474_SetAbsolutePosition(s, 0);
|
||||
|
||||
L6474_Status_t status;
|
||||
if(L6474_GetStatus(s, &status) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
int button_pressed = 0;
|
||||
|
||||
while(!button_pressed){
|
||||
L6474_StepIncremental(s, -1);
|
||||
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
|
||||
button_pressed=1;
|
||||
}
|
||||
|
||||
|
||||
if(stepper_check_status(s)){
|
||||
return 1;
|
||||
}
|
||||
L6474_SetAbsolutePosition(s, 0);
|
||||
|
||||
return 0;
|
||||
|
||||
if(L6474_SetAbsolutePosition(s, 0) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stepper_softstart(L6474_Handle_t s, unsigned int duration){
|
||||
@@ -167,8 +173,10 @@ void stepper_softstart(L6474_Handle_t s, unsigned int duration){
|
||||
|
||||
int stepper_pos(L6474_Handle_t s){
|
||||
int position = 0;
|
||||
L6474_GetAbsolutePosition(s, &position);
|
||||
printf("Stepper position: %d", position);
|
||||
if(L6474_GetAbsolutePosition(s, &position) != errcNONE){
|
||||
return 1;
|
||||
}
|
||||
printf("%d", (position/800));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -192,14 +200,21 @@ int stepper_move(L6474_Handle_t s, int pos){
|
||||
return 1;
|
||||
}
|
||||
|
||||
L6474_Status_t status;
|
||||
if(L6474_GetStatus(s, &status) != errcNONE){
|
||||
if(stepper_check_status(s)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_binary_8bit(unsigned int val) {
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
int bit = (val >> i) & 1;
|
||||
printf("%d", bit);
|
||||
if (i == 4) printf(" ");
|
||||
}
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
@@ -228,11 +243,19 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
}
|
||||
if ( argc < 2 )
|
||||
{
|
||||
printf("missing step value for step commandFAIL\r\n");
|
||||
printf("missing step value for step command\r\n");
|
||||
printf("FAIL\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
L6474_StepIncremental(h, atoi(argv[1]));
|
||||
if(L6474_StepIncremental(h, atoi(argv[1])) != errcNONE || stepper_check_status(h)){
|
||||
state = 0;
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
yellow_led_stop();
|
||||
printf("FAIL\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%d steps", (int)atoi(argv[1]));
|
||||
|
||||
@@ -241,11 +264,16 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
{
|
||||
if(reset_stepper(h)){
|
||||
state = 0;
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
yellow_led_stop();
|
||||
printf("FAIL\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
state = 1;
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
|
||||
printf("OK\r\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -259,6 +287,9 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
|
||||
if(stepper_reference(h, 0)){
|
||||
state = 0;
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
yellow_led_stop();
|
||||
printf("FAIL\r\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -277,11 +308,14 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
|
||||
if(stepper_pos(h)){
|
||||
state = 0;
|
||||
printf("FAIL\r\n");
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
yellow_led_stop();
|
||||
printf("\r\nFAIL\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("OK\r\n");
|
||||
printf("\r\nOK\r\n");
|
||||
return 0;
|
||||
}
|
||||
else if ( strcmp(argv[0], "move") == 0 )
|
||||
@@ -308,12 +342,60 @@ int StepperConsoleFunction( int argc, char** argv, void* ctx )
|
||||
|
||||
if(stepper_move(h, mm_to_step(target_mm))==1){
|
||||
state = 0;
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
|
||||
yellow_led_stop();
|
||||
printf("FAIL\r\n");
|
||||
return -1;
|
||||
}
|
||||
printf("OK\r\n");
|
||||
return 0;
|
||||
}
|
||||
else if (strcmp(argv[0], "status") == 0)
|
||||
{
|
||||
L6474x_State_t currentState;
|
||||
L6474_Status_t stepperStatus;
|
||||
int moving = 0;
|
||||
|
||||
// 1. get state of state machine
|
||||
if (L6474_GetState(h, ¤tState) != errcNONE)
|
||||
{
|
||||
printf("failed to get state\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 2.get driver-state
|
||||
if (L6474_GetStatus(h, &stepperStatus) != errcNONE)
|
||||
{
|
||||
printf("failed to get status\r\nFAIL");
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned int errorBits = ((stepperStatus.WRONG_CMD & 0x01) << 8) |
|
||||
((stepperStatus.UVLO & 0x01) << 7) |
|
||||
((stepperStatus.TH_WARN & 0x01) << 6) |
|
||||
((stepperStatus.TH_SD & 0x01) << 5) |
|
||||
((stepperStatus.ONGOING & 0x01) << 4) |
|
||||
((stepperStatus.OCD & 0x01) << 3) |
|
||||
((stepperStatus.NOTPERF_CMD & 0x01) << 2) |
|
||||
((stepperStatus.HIGHZ & 0x01) << 1) |
|
||||
((stepperStatus.DIR & 0x01) << 0);
|
||||
|
||||
|
||||
|
||||
// 3. check for moving motor aka async pending operation (should be always 0 with no async mode)
|
||||
L6474_IsMoving(h, &moving);
|
||||
|
||||
|
||||
printf("0x%X\r\n", (unsigned int)currentState); //print state in first line
|
||||
printf("0x%X\r\n", errorBits); //print error flags in second line
|
||||
printf("internal error bits in binary: ");
|
||||
print_binary_8bit(errorBits);
|
||||
printf("%d\r\n", moving); //print async pending op in third line
|
||||
printf("OK");
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("passed invalid sub command\r\n");
|
||||
|
||||
@@ -115,13 +115,33 @@ void green_led(){
|
||||
}
|
||||
}
|
||||
|
||||
static TaskHandle_t yellowLedTask = NULL;
|
||||
|
||||
void blink_yellow_led(){
|
||||
while(1){
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
while(1){
|
||||
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_SET);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
}
|
||||
|
||||
void yellow_led_start(void)
|
||||
{
|
||||
if (yellowLedTask == NULL) {
|
||||
xTaskCreate(blink_yellow_led, "blink_yellow_led", 1024, NULL, 1, &yellowLedTask);
|
||||
}
|
||||
}
|
||||
|
||||
void yellow_led_stop(void)
|
||||
{
|
||||
if (yellowLedTask != NULL) {
|
||||
vTaskDelete(yellowLedTask);
|
||||
yellowLedTask = NULL;
|
||||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_1, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void red_led(){
|
||||
@@ -141,19 +161,19 @@ static int CapabilityFunc( int argc, char** argv, void* ctx )
|
||||
(void)argv;
|
||||
(void)ctx;
|
||||
printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\r\nOK",
|
||||
0, // has spindle
|
||||
0, // has spindle status
|
||||
0, // has stepper
|
||||
1, // has spindle
|
||||
1, // has spindle status
|
||||
1, // has stepper
|
||||
0, // has stepper move relative
|
||||
0, // has stepper move speed
|
||||
0, // has stepper move async
|
||||
0, // has stepper status
|
||||
0, // has stepper refrun
|
||||
1, // has stepper status
|
||||
1, // has stepper refrun
|
||||
0, // has stepper refrun timeout
|
||||
0, // has stepper refrun skip
|
||||
0, // has stepper refrun stay enabled
|
||||
0, // has stepper reset
|
||||
0, // has stepper position
|
||||
1, // has stepper reset
|
||||
1, // has stepper position
|
||||
0, // has stepper config
|
||||
0, // has stepper config torque
|
||||
0, // has stepper config throvercurr
|
||||
|
||||
Reference in new issue
Block a user