2016年4月29日 星期五

義守大學電機系陳慶瀚 VHDL PPT

義守大學電機系 VHDL 

授課教師:陳慶瀚


組合邏輯與VHDL 基本語法

組合邏輯與VHDL 基本語法




2016年4月27日 星期三

28BYJ-48 步進馬達實驗 (一相激磁)

28BYJ-48 步進馬達實驗 (一相激磁)

步進馬達依照靜子線圈的相數多寡可分為單相、雙相、三相、四相和五相等。一般小型的步進馬達以四相式為準,這類的馬達在定字上有四組相對應的線圈,分別提供相差90度相位的電力。當馬達單相激磁時,這四組線圈可在各相的對應處停住轉子,當下一個脈衝來到時,轉子轉動一個角度,這種角度稱為步進角。步進角的計算公式如下:

        步進角=360度/ 寸動數

              = 360度 / (相數 X 轉子齒數)

寸動數:步進馬達每週所轉動的步數,就是相數和轉子齒數的乘積。










//程式
int Pin0 = 6;
int Pin1 = 7;
int Pin2 = 8;
int Pin3 = 9;
int _step = 0;
int count=0 ;
boolean dir = true;
// gre
void setup()
{
 pinMode(Pin0, OUTPUT);
 pinMode(Pin1, OUTPUT);
 pinMode(Pin2, OUTPUT);
 pinMode(Pin3, OUTPUT);
}
 void loop()
{
 switch(_step){
   case 0:
     digitalWrite(Pin0, HIGH);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
   case 1:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, HIGH);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
   case 2:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, HIGH);
     digitalWrite(Pin3, LOW);
   break;
   case 3:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, HIGH);
   break;
     default:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
 }

 count++;
 if (count>4096) {   // 28BYJ-48 5V DC  360 / (5.625 / 64) = 4096 step
  count=0;
  dir=!dir;
  delay(1000);
 }

 if(dir){
   _step++;
 }else{
   _step--;
 }

 if(_step>7){
   _step=0;
 }
 if(_step<0){
   _step=7;
 }
 delay(4);
}

28BYJ-48 步進馬達實驗 (二相激磁)

28BYJ-48 步進馬達實驗 (二相激磁)


留意 順序 1-3-2-4  對應 接腳 6, 8, 7, 9
// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 9);


5V Stepper Motors
You will need a stepper library, but there is one built into Arduino, so no installation should be needed.

These steppers normally have 4096 steps per revolution, but the built in stepper library works in
4 step sequence vs the 8 step sequence that it would expect, so we need to consider it as 2048, though you might find this is not completely accurate either and you may need to tweak code.

The code expects this pinout - you may modify as necessary:
IN1 --> 8
​IN2 --> 9
​IN3 --> 10
​IN4 --> 11
5-12V+ -->5V
​Gnd- --> Gnd





28BYJ-48 步進馬達實驗 (二相激磁)

/*-----( Import needed libraries )-----*/
#include <Stepper.h>

/*-----( Declare Constants, Pin Numbers )-----*/
//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
#define STEPS_PER_MOTOR_REVOLUTION 32

//---( Steps per OUTPUT SHAFT of gear reduction )---
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64  //2048


/*-----( Declare objects )-----*/
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4  and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 9);  // 1-3-2-4 for proper sequencing

/*-----( Declare Variables )-----*/
int  Steps2Take;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
// Nothing  (Stepper Library sets pins as outputs)
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION ;  // Rotate CW 1 turn
  small_stepper.setSpeed(250);
  small_stepper.step(Steps2Take);
  delay(1000);

  Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION;  // Rotate CCW 1 turn
  small_stepper.setSpeed(500);  // 700 a good max speed??
  small_stepper.step(Steps2Take);
  delay(2000);

}/* --(end main loop )-- */

/* ( THE END ) */

28BYJ-48 步進馬達實驗 (二相激磁)

// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 9);

留意 順序 1-3-2-4  對應 接腳 6, 8, 7, 9



5V Stepper Motors
You will need a stepper library, but there is one built into Arduino, so no installation should be needed.

These steppers normally have 4096 steps per revolution, but the built in stepper library works in
4 step sequence vs the 8 step sequence that it would expect, so we need to consider it as 2048, though you might find this is not completely accurate either and you may need to tweak code.

The code expects this pinout - you may modify as necessary:
IN1 --> 6
​IN2 --> 7
​IN3 --> 8
​IN4 --> 9

5-12V+ -->5V ----要連接
​Gnd- --> Gnd
----要連接


//========程式=============
//2 phase step motor control
/*-----( Import needed libraries )-----*/
#include <Stepper.h>

/*-----( Declare Constants, Pin Numbers )-----*/
//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
#define STEPS_PER_MOTOR_REVOLUTION 32

//---( Steps per OUTPUT SHAFT of gear reduction )---
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 128  //4096

/*-----( Declare objects )-----*/
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4  and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 6, 8, 7, 9);


/*-----( Declare Variables )-----*/
int  Steps2Take;

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
// Nothing  (Stepper Library sets pins as outputs)
}/*--(end setup )---*/

void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  small_stepper.setSpeed(1);   // SLOWLY Show the 4 step sequence
  Steps2Take  =  4;  // Rotate CW
  small_stepper.step(Steps2Take);
  delay(2000);

  Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CW 1/2 turn
  small_stepper.setSpeed(100);
  small_stepper.step(Steps2Take);
  delay(1000);

  Steps2Take  =  - STEPS_PER_OUTPUT_REVOLUTION / 2;  // Rotate CCW 1/2 turn
  small_stepper.setSpeed(700);  // 700 a good max speed??
  small_stepper.step(Steps2Take);
  delay(2000);

}/* --(end main loop )-- */

/* ( THE END ) */

  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...