Arduino + H-híd és DC motor

Processing/Wiring (illetve C) nyelvű programozási fogások, tippek. (AVR-Duino, Arduino, EthDuino, Diecimila, Severino, Nano, LilyPad)
Avatar
dpsslaser
Bitmanipulátor
Hozzászólások: 145
Csatlakozott: 2012. július 21. szombat, 6:00

Arduino + H-híd és DC motor

Hozzászólás Szerző: dpsslaser »

sziasztok !

Nem akartam ez miat uj topicot nyitni kis segitség kelene nem fordul le a kod!

kod:

Kód: Egész kijelölése

//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
}
}




hiba hivatkozás "arduino 1.0.1":

Kód: Egész kijelölése


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'


Avatar
irak
Biztosítékgyilkos
Hozzászólások: 73
Csatlakozott: 2005. november 2. szerda, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: irak »

Szevasz!

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.
Avatar
dpsslaser
Bitmanipulátor
Hozzászólások: 145
Csatlakozott: 2012. július 21. szombat, 6:00

Re: Arduino + szervómotor

Hozzászólás Szerző: dpsslaser »

irak írta:Szevasz!

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 ........

Kód: Egész kijelölése

 
int potVal; // hiányozhart valami érték?????
Avatar
irak
Biztosítékgyilkos
Hozzászólások: 73
Csatlakozott: 2005. november 2. szerda, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: irak »

Feltételezem hogy main-ból hívod a setup, majd a loop függvényt.

Sorosporton lesed az infókat?
Vagy ha nem, írj bele valami fixet a potval-ba, az analodRead-ot kikommentezve.
Hátha a ADC nincs meg...
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10213
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: Robert »

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ó!
Avatar
irak
Biztosítékgyilkos
Hozzászólások: 73
Csatlakozott: 2005. november 2. szerda, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: irak »

Függvényen kívül van, úgyhogy elvileg elérhető mindenhol (másnem extern-el).
Avatar
dpsslaser
Bitmanipulátor
Hozzászólások: 145
Csatlakozott: 2012. július 21. szombat, 6:00

Re: Arduino + szervómotor

Hozzászólás Szerző: dpsslaser »

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ó!
hogyan?
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10213
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: Robert »

Az egyes részprogramok mennek külön-külön?
Avatar
dpsslaser
Bitmanipulátor
Hozzászólások: 145
Csatlakozott: 2012. július 21. szombat, 6:00

Re: Arduino + szervómotor

Hozzászólás Szerző: dpsslaser »

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!
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10213
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: Robert »

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?
Avatar
dpsslaser
Bitmanipulátor
Hozzászólások: 145
Csatlakozott: 2012. július 21. szombat, 6:00

Re: Arduino + szervómotor

Hozzászólás Szerző: dpsslaser »

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?
H-bridge, DC motor vezérlés

dir>>>>> irány váltás: cw ccw
step>>>>>pwm

http://www.svenhoek.com/Welding_Turntable.html
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10213
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: Robert »

Arduino-0022-vel fordítsd le.

A cikkben említett H-Hídhoz tartozik a program.

Kód: Egész kijelölése

//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
 }
 }
Avatar
dpsslaser
Bitmanipulátor
Hozzászólások: 145
Csatlakozott: 2012. július 21. szombat, 6:00

Re: Arduino + szervómotor

Hozzászólás Szerző: dpsslaser »

Robert írta:Arduino-0022-vel fordítsd le.

A cikkben említett H-Hídhoz tartozik a program.

Kód: Egész kijelölése

//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.
Avatar
irak
Biztosítékgyilkos
Hozzászólások: 73
Csatlakozott: 2005. november 2. szerda, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: irak »

PWM-nél a freki fix ugyebár, az nem a te programodba van beállítva.
(max ha lenne vmi beállító függvénye, de nincs)

http://arduino.cc/en/Tutorial/PWM
http://arduino.cc/en/Reference/AnalogWrite
Avatar
Robert
Elektronbűvölő
Hozzászólások: 10213
Csatlakozott: 2005. december 9. péntek, 7:00

Re: Arduino + szervómotor

Hozzászólás Szerző: Robert »

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!
Válasz küldése