Hi
I' m a beginner and its my very first project so i might have many mistakes.
My project is producing an oscillator for welding. I want to control system with 3 potantiometer.
pot in A0 connection, controls delay time between oscillations
My questions are;
I can' t control speed. What can i add to control speed with A2 connection?
When it changes rotation, it stops and moves back suddenly. Probably it causes over heating of driver.
So may i stop and force again slowly? To do this how may i modify codes?
For this operation i use nema 23 with tb6560 and powering 24V 6,5A supply. Driver is heating too much. TB6560 switces are in this position;
S1 0 S2 0 S3 0 S4 0 S5 0 S6 0
To reduce overheating, maybe i have to adjust it in better set up?
Code below;
// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(A0, INPUT);
pinMode(A2, INPUT);
pinMode(A4, INPUT);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}
void loop() {
int range = analogRead (A4);
int speed= analogRead (A2);
int wait= analogRead (A0);
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
for(int x = 0; x < range; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
{ delay(wait);
{ digitalWrite(dirPin,LOW); //Changes the rotations direction
for(int x = 0; x < range; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
{ delay(wait);
}
int range = analogRead (A4);
int speed= analogRead (A2);
int wait= analogRead (A0);
You should begin debugging your code yourself by Serial.print() the return values, so you can see what is being returned.
How do you have those pins wired to the pots?
Paul
A0 A2 and A4 has 10k potantiometer wires. I will add a 2x16 led for next step but ofc as you said for checking whats going on in program, i will add serial print.
Sorry for double, first was on wrong topic but i couldt move.
@markT
I will check it tomarrow. About that, in arduino can we use more than one library in same program?
azir:
Hi
I' m a beginner and its my very first project so i might have many mistakes.
My project is producing an oscillator for welding. I want to control system with 3 potantiometer.
pot in A0 connection, controls delay time between oscillations
My questions are;
I can' t control speed. What can i add to control speed with A2 connection?
void loop() {
int range = analogRead (A4);
int speed= analogRead (A2);
int wait= analogRead (A0);
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
for(int x = 0; x < range; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(wait);
digitalWrite(dirPin,LOW); //Changes the rotations direction
for(int x = 0; x < range; x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(wait);
}
Looks like you should use the value 'speed' in the second 'delayMicroseconds(500);" in each loop. Right now you delay 500 microseconds twice in each iteration. That's 1 millisecond of delay so a little slower than 1000 steps per second. To get 1000 to 5096 microseconds delay between steps (1000 to 200 steps per second) you could use this:
for(int x = 0; x < range; x++)
{
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500 + (4 * speed));
}