//This program controls a 12VDC 5A motor speed and direction using a potentiometer
//11-27-12
//Note: 'Enable' is the ON/OFF/PWM output pin on the Arduino
//The 'Cytron MD10C' is accepting the Arduino Output signals and regulating the motorcurrent
//Power to the MD10C is supplied by the Newark ECM100 power supply @ 12VDC.
//Thus, this code requires the Arduino, MD10C, ECM100, and brushed DC motor.
//http://ruggedcircuits.com/html/rugged_motor_driver.html
#include <Stepper.h>
#define Enable 3 // Assign the 'Enable' (PWM) signal to Pin 3
#define Direction 12 // Assign the 'Direction' signal to Pin 12
intpotVal; //potentiometer position value is stored here as # from 0- 1024
void setup() //further define what each I/O pin is being used for in this section
{
Serial.begin(9600); //begin the serial monitor for debugging convenience
pinMode(A0, INPUT); //The potentiometer for speed/direction control assigned to Pin A0
pinMode(Enable, OUTPUT);
digitalWrite(Enable, LOW); //Enable (PWM) pin assigned as an output and set as LOW (forward)
pinMode(Direction, OUTPUT);
digitalWrite(Direction, LOW); //Direction pin assigned as an output and set as LOW
analogWrite(Enable, 0); // Set the motor as OFF just incase
}
void loop()
{
potVal=(analogRead(A0))/2-256; //Read Pot, map value 0-1024 onto range (-255)to(255),for PWM
Welding Turntable http://www.svenhoek.com/Welding_Turntable.html
9 / 13 2013. 10. 11. 17:44
out
Serial.println(potVal); //display current pot value on the Serial Monitor for debugging convenience
if(potVal>=50){
digitalWrite(Direction, LOW); // Set Motor 1 forward direction
analogWrite(Enable, potVal-40); // Motor 1 ON at PotVal speed
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
else if(potVal<=-50){
digitalWrite(Direction, HIGH); // Set Motor 1 reverse direction
analogWrite(Enable, potVal*(-1)-41); // Motor 1 ON at PotVal speed. Math keeps PWM value positive
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
else{
digitalWrite(Direction, LOW); // Set Motor 1 forward direction
analogWrite(Enable, 0); // Motor 1 ON at PotVal speed
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
}
sketch_oct20a:10: error: expected constructor, destructor, or type conversion before ';' token
sketch_oct20a.cpp: In function 'void loop()':
sketch_oct20a:23: error: 'potVal' was not declared in this scope
sketch_oct20a:24: error: 'Welding' was not declared in this scope
sketch_oct20a:24: error: expected `;' before 'Turntable'
Szanaszétt van szakadva a forrás, legalábbis ami itt látszik.
A potval deklarációnál kimaradt egy szóköz az int után, a többi hiba mintha a kommentekből adódna.
Szanaszétt van szakadva a forrás, legalábbis ami itt látszik.
A potval deklarációnál kimaradt egy szóköz az int után, a többi hiba mintha a kommentekből adódna.
köszönöm valoban!
Most hogy sikerült be forditani és tesztelni is valamitöl nem ugy cselekszik ahogy kelene a Step/dir kimeneten nincs csak fix jel step kitöltés és a freki is fix !
A0 A 10K poti változásra sem történik semi ........
Részletenként élesítsd.
A potval az alprogramban vagy globálisan definiált? Globálisnak kell lennie, különben ha kilépsz az alprogramból: megszűnik a változó!
Robert írta:Részletenként élesítsd.
A potval az alprogramban vagy globálisan definiált? Globálisnak kell lennie, különben ha kilépsz az alprogramból: megszűnik a változó!
Robert írta:Az egyes részprogramok mennek külön-külön?
Nen én irtam talátam de az adot célra kelene de nem indul az hogy hogyan müködik a folyamata az sejtelmem nincs!
step/ dir vezérelt teljes hid a meghajtás amin egy potencia méterel kelene ez a funkciot megoldanom cw<------stop-------->ccw közép álás stop jobra.... balra pwm kitölés szabályzás!
Hát, akkor kénytelen vagy részekre bontva tesztelni. Előtted a hardware.
Off: CopyPaste hátránya: nem működik általában:(
Teszteld:
1, StepDir megy? Egy sima do/loopban modellezd.
2, StepDir delay-t késleltesd a potméter ADC eredményével - poti is megy.
3, PWM az minek? Hogy jön a StepDir-hez?
Robert írta:Hát, akkor kénytelen vagy részekre bontva tesztelni. Előtted a hardware.
Off: CopyPaste hátránya: nem működik általában:(
Teszteld:
1, StepDir megy? Egy sima do/loopban modellezd.
2, StepDir delay-t késleltesd a potméter ADC eredményével - poti is megy.
3, PWM az minek? Hogy jön a StepDir-hez?
//This program controls a 12VDC 5A motor speed and direction using a potentiometer
//11-27-12
//Note: 'Enable' is the ON/OFF/PWM output pin on the Arduino
//The 'Cytron MD10C' is accepting the Arduino Output signals and regulating the motor current
//Power to the MD10C is supplied by the Newark ECM100 power supply @ 12VDC.
//Thus, this code requires the Arduino, MD10C, ECM100, and brushed DC motor.
//http://ruggedcircuits.com/html/rugged_motor_driver.html
#include <Stepper.h>
#define Enable 3 // Assign the 'Enable' (PWM) signal to Pin 3
#define Direction 12 // Assign the 'Direction' signal to Pin 12
int potVal; //potentiometer position value is stored here as # from 0- 1024
void setup() //further define what each I/O pin is being used for in this section
{
Serial.begin(9600); //begin the serial monitor for debugging convenience
pinMode(A0, INPUT); //The potentiometer for speed/direction control assigned to Pin A0
pinMode(Enable, OUTPUT);
digitalWrite(Enable, LOW); //Enable (PWM) pin assigned as an output and set as LOW (forward)
pinMode(Direction, OUTPUT);
digitalWrite(Direction, LOW); //Direction pin assigned as an output and set as LOW
analogWrite(Enable, 0); // Set the motor as OFF just incase
}
void loop()
{
potVal=(analogRead(A0))/2-256; //Read Pot, map value 0-1024 onto range (-255)to(255), for PWM out
Serial.println(potVal); //display current pot value on the Serial Monitor for debugging convenience
if(potVal>=50){
digitalWrite(Direction, LOW); // Set Motor 1 forward direction
analogWrite(Enable, potVal-40); // Motor 1 ON at PotVal speed
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
else if(potVal<=-50){
digitalWrite(Direction, HIGH); // Set Motor 1 reverse direction
analogWrite(Enable, potVal*(-1)-41); // Motor 1 ON at PotVal speed. Math keeps PWM value positive
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
else{
digitalWrite(Direction, LOW); // Set Motor 1 forward direction
analogWrite(Enable, 0); // Motor 1 ON at PotVal speed
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
}
//This program controls a 12VDC 5A motor speed and direction using a potentiometer
//11-27-12
//Note: 'Enable' is the ON/OFF/PWM output pin on the Arduino
//The 'Cytron MD10C' is accepting the Arduino Output signals and regulating the motor current
//Power to the MD10C is supplied by the Newark ECM100 power supply @ 12VDC.
//Thus, this code requires the Arduino, MD10C, ECM100, and brushed DC motor.
//http://ruggedcircuits.com/html/rugged_motor_driver.html
#include <Stepper.h>
#define Enable 3 // Assign the 'Enable' (PWM) signal to Pin 3
#define Direction 12 // Assign the 'Direction' signal to Pin 12
int potVal; //potentiometer position value is stored here as # from 0- 1024
void setup() //further define what each I/O pin is being used for in this section
{
Serial.begin(9600); //begin the serial monitor for debugging convenience
pinMode(A0, INPUT); //The potentiometer for speed/direction control assigned to Pin A0
pinMode(Enable, OUTPUT);
digitalWrite(Enable, LOW); //Enable (PWM) pin assigned as an output and set as LOW (forward)
pinMode(Direction, OUTPUT);
digitalWrite(Direction, LOW); //Direction pin assigned as an output and set as LOW
analogWrite(Enable, 0); // Set the motor as OFF just incase
}
void loop()
{
potVal=(analogRead(A0))/2-256; //Read Pot, map value 0-1024 onto range (-255)to(255), for PWM out
Serial.println(potVal); //display current pot value on the Serial Monitor for debugging convenience
if(potVal>=50){
digitalWrite(Direction, LOW); // Set Motor 1 forward direction
analogWrite(Enable, potVal-40); // Motor 1 ON at PotVal speed
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
else if(potVal<=-50){
digitalWrite(Direction, HIGH); // Set Motor 1 reverse direction
analogWrite(Enable, potVal*(-1)-41); // Motor 1 ON at PotVal speed. Math keeps PWM value positive
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
else{
digitalWrite(Direction, LOW); // Set Motor 1 forward direction
analogWrite(Enable, 0); // Motor 1 ON at PotVal speed
delay(50); //Continue at that speed for 50/1000 sec. before restarting loop
}
}
Most már hibátlan a kód, lefordul és működik is. Nem tudom, hogy mi volt a hiba.
Még egy kérdésem lenne: a pwm frekvencia per pilanat 500 Hz. Ezt milyen érték változtatásával tudom a programban beállíitani?
Admin: Off: kérlek használj átolvasást vagy helyesírásellenőrzőt! Javítottam.
PWM belüla timert használja a chipben. Arduino esetén csak a kód mélyebb szétszedésével állítható (nem javasolt, főleg mert ekkor a keretrendszer általi korlátokból kinyúlsz és nem tudod mit ránt még magával). Nem olyan kicsi az az 500 Hz!