We want to rotate the stepper motor(Radial stepper) using a while loop until and unless an event(event: touching limit switch) triggers it.
Problems: 1) As per code, the stepper motor has to keep on running until and unless it touches the limit switch (event). But the stepper motor stopped rotating without even touching the limit switch and the code got executed fully. Sometimes the stepper motor works as per the code.,some times it’s doesn’t. Note: As per electronic connections, all are working fine.
Connection : Stepper motor driver Pul+, Pul-, Dir +, Dir - connected to Nucleo Board F746ZG (PE_4,PE_5,PE_2,PF_8) respectively. Stepper motor driver Vdc+ and ground are connected to the source. Stepper motor Pul+, Pul-, Dir +, Dir - are connected to Stepper motor driver A+,A-,B+,B-.
Limit Switch: Normally open, on the trigger, gets closed. Limit switch ground connected to the board ground and another terminal connected to the board (PD_2).
Checked all the possibilities (changing all of them limit switch, board, stepper motor, stepper motor driver, getting enough power supply). Code is metioned below.
Thanks in advance
. . .
/**/
#include “mbed.h”
#include “math.h”
#include “FermeStepper.h”
#include “stepperMotor.h”
#include “FermeCantileverMotor.h”
#include “PinDetect.h” // Library for external interrupts
#include “Servo.h”
#include “string”
#include “rtos.h”
#include “DebounceIn.h” // Library for sampling in interrupts (mechanical contacts)
Serial pc(USBTX, USBRX);
sMotor Radial_Stepper(PE_4,PE_5,PE_2,PF_8);
DigitalIn Radial_Limit(PD_2); // Radial Stepper limit switch
DigitalOut Radial_Relay(PE_3); // Radial Stepper Motor Relay
int main()
{
int ch,radialsteps,speed;
float radial_delay = 1;
Radial_Limit.mode(PullUp);
while(1)
{
pc.printf("\n\1 radial reset \nChoice:");
pc.scanf("%d", &ch);
switch(ch)
{
case 1:
Radial_Relay = 1;
wait(radial_delay);
Radial_Limit.mode(PullUp);
while(Radial_Limit!=1) // Spin Stepper until hits limit switch
Radial_Stepper.step(1, 1, 350);
wait(1);
break;
}
}
}
. . .