回覆 9# aazz

呢個係用L298嘅例子。 用查表法簡化 sin wave 的方案。

const int buttonPin1 = 4;// the number of the direction pushbutton pin
const int buttonPin2 = 5;// the number of the direction pushbutton pin
const int ledPin =  13;  // the number of the status LED pin (not the flash LED)
const int motorPin1 =9;  //pwm
const int motorPin2 =10; //pwm
const int motorPin3 =11; //pwm
int pwmSinA[] = {127,119,110,102,94,86,78,71,64,56,50,43,37,32,26,21,17,13,10,7,4,2,1,0,0,0,1,2,4,7,10,13,17,21,26,32,37,43,50,56,64,71,78,86,94,102,110,119,127,135,144,152,160,168,176,183,191,198,204,211,217,222,228,233,237,241,244,247,250,252,253,254,254,254,253,252,250,247,244,241,237,233,228,222,217,211,204,198,191,183,176,168,160,152,144,135}; // array of PWM duty values for 8-bit timer - sine function
int pwmSinB[] = {237,241,244,247,250,252,253,254,254,254,253,252,250,247,244,241,237,233,228,222,217,211,204,198,191,183,176,168,160,152,144,135,127,119,110,102,94,86,78,71,64,56,50,43,37,32,26,21,17,13,10,7,4,2,1,0,0,0,1,2,4,7,10,13,17,21,26,32,37,43,50,56,64,71,78,86,94,102,110,119,127,135,144,152,160,168,176,183,191,198,204,211,217,222,228,233}; // array of PWM duty values for 8-bit timer - sine function
int pwmSinC[] = {17,21,26,32,37,43,50,56,64,71,78,86,94,102,110,119,127,135,144,152,160,168,176,183,191,198,204,211,217,222,228,233,237,241,244,247,250,252,253,254,254,254,253,252,250,247,244,241,237,233,228,222,217,211,204,198,191,183,176,168,160,152,144,135,127,119,110,102,94,86,78,71,64,56,50,43,37,32,26,21,17,13,10,7,4,2,1,0,0,0,1,2,4,7,10,13}; // array of PWM duty values for 8-bit timer - sine function

const int motorDelay=300; //controls the RPM
int direction = 1; // direction 1=cw, 0=ccw
int currentStep=0;

///////////////////////////////////////////////////////////////////////////////////
void setup() {

  pinMode(buttonPin1, INPUT);
  digitalWrite(buttonPin1, HIGH);  //internal pull up resistor
  pinMode(buttonPin2, INPUT);
  digitalWrite(buttonPin2, HIGH);  //internal pull up resistor
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  //
  move();
  delay(100);
}//end setup()
//////////////////////////////////////////////////////////////////////////////////
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
if (digitalRead(buttonPin1) == LOW)
  {
   currentStep++;
   if (currentStep > 95) currentStep=0;
   move();
  }
if (digitalRead(buttonPin2) == LOW)
  {
   currentStep--;  
   if (currentStep < 0) currentStep=95;
   move();
  }
delay(motorDelay);
}//end loop()
///////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////////////
void move()
{
analogWrite(motorPin1, pwmSinA[currentStep]);
analogWrite(motorPin2, pwmSinB[currentStep]);
analogWrite(motorPin3, pwmSinC[currentStep]);
}//end move()
////////////////////////////////////////////////////////////////////////

TOP

回覆  aazz

呢個係用L298嘅例子。 用查表法簡化 sin wave 的方案。

const int buttonPin1 = 4;// the nu ...
uvvvvw 發表於 2018-4-21 23:35


thanks
試試

TOP

小第都有 L293D 板;
https://item.taobao.com/item.htm ... &id=35550173132
但返效果都是麻麻;
十分難起動;
而且293D 在運行時十分熱;
怕佢會燒

TOP

回覆  aazz
呢個係用L298嘅例子。 用查表法簡化 sin wave 的方案。
uvvvvw 發表於 2018-4-21 23:35

師兄,我係唔識控制[無刷電機]。
我想問吓點解要用sine wave去控制?點解有師兄話起動有困難?應該怎樣起動?另外,是否可以用vector control去分開控制[轉速]和[扭力]?
可否指教一吓? 謝謝!

TOP

本帖最後由 aazz 於 2018-4-22 12:46 編輯
師兄,我係唔識控制[無刷電機]。
我想問吓點解要用sine wave去控制?點解有師兄話起動有困難?應該怎樣起動? ...
marlin12 發表於 2018-4-22 12:36


人兄
英文小第不太懂的;
我試左找左幾個月;
找左很多 youtube片;
好像多數要用 MCU 板 或程式ROM控制;
多數是方波;
先可以又快有有力;
但小第找到的線路同 用 Arduino 去控制;
都只能起動慢;
轉速不高又沒什麼力度;
所以問問這處的人兄;

TOP

小第都有 L293D 板;

但返效果都是麻麻;
十分難起動;
而且293D 在運行時十分熱;
怕佢會燒 ...
aazz 發表於 2018-4-22 08:58

你用嘅module可能是低電流嘅。又冇散熱。可能唔夠力。

TOP

師兄,我係唔識控制[無刷電機]。
我想問吓點解要用sine wave去控制?點解有師兄話起動有困難?應該怎樣起動? ...
marlin12 發表於 2018-4-22 12:36

用 sine wave 控制,摩打轉得柔順D。唔會跳下跳下。
呢個係唔用 sine wave 控制嘅基礎版。可以先玩下呢個。

const int buttonPin1 = 4;// the number of the direction pushbutton pin
const int buttonPin2 = 5;// the number of the direction pushbutton pin
const int ledPin =  13;  // the number of the status LED pin (not the flash LED)
const int motorAPin1 =3;
const int motorAPin2 =5;
const int motorAPin3 =6;
const int motorBPin1 =9;
const int motorBPin2 =10;
const int motorBPin3 =11;
//const int motorPins[]={3,5,6};

const int motorPinSteps[3][6]={
{1,1,1,0,0,0},
{1,0,0,0,1,1},
{0,0,1,1,1,0}};

const int motorDelay=500; // together with pot controls the RPM
boolean direct = true; // direction true=forward, false=backward
int increment;
int currentStepA=0;

///////////////////////////////////////////////////////////////////////////////////
void setup() {

  pinMode(buttonPin1, INPUT);
  digitalWrite(buttonPin1, HIGH);  //internal pull up resistor
  pinMode(buttonPin2, INPUT);
  digitalWrite(buttonPin2, HIGH);  //internal pull up resistor
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(motorAPin1, OUTPUT);
  pinMode(motorAPin2, OUTPUT);
  pinMode(motorAPin3, OUTPUT);
  pinMode(motorBPin1, OUTPUT);
  pinMode(motorBPin2, OUTPUT);
  pinMode(motorBPin3, OUTPUT);
  //
  move();
  delayMicroseconds(motorDelay);
}//end setup()
//////////////////////////////////////////////////////////////////////////////////
//
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
currentStepA++;
if (currentStepA > 5) currentStepA=0;
move();
delay( motorDelay);
}//end loop()
///////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//
////////////////////////////////////////////////////////////////////////
void move()
{
digitalWrite(motorAPin1,motorPinSteps[0][currentStepA]);
digitalWrite(motorAPin2,motorPinSteps[1][currentStepA]);
digitalWrite(motorAPin3,motorPinSteps[2][currentStepA]);  
digitalWrite(motorBPin1,motorPinSteps[0][currentStepA]);
digitalWrite(motorBPin2,motorPinSteps[1][currentStepA]);
digitalWrite(motorBPin3,motorPinSteps[2][currentStepA]);  
}//end move()
////////////////////////////////////////////////////////////////////////



若用 Arduino 控制 ESC (electronic speed controller) ,起動先至比較複雜。
否則同控制步進馬達差唔多。只要起步速度不太快,一般沒問題。

TOP

人兄
英文小第不太懂的;
我試左找左幾個月;
找左很多 youtube片;
好像多數要用 MCU 板 或程式ROM控制;
多 ...
aazz 發表於 2018-4-22 12:44

想快要考慮加速度。就是先慢後快。
一開始速度太快,會轉唔郁嘅。

TOP

想快要考慮加速度。就是先慢後快。
一開始速度太快,會轉唔郁嘅。
uvvvvw 發表於 2018-4-22 14:01


但硬碟 MOTOR 的電路;
好像一開始就是快的;
而且按停可以再轉得反;
不過力度是差一些

TOP

你用嘅module可能是低電流嘅。又冇散熱。可能唔夠力。
uvvvvw 發表於 2018-4-22 13:50


人兄
小第就是用上面淘寶的連結;
那塊擴展板;

TOP