|
各位先進好:
最近手癢摸到 硬碟機想驅動它轉動,本來想網路上找邏輯電路,一時沒找到,於是想用 MCU 來驅動,於是找來 STM8S03 和 ULN2003 驅動,網路上有 ARDUINO 版本的,看他的驅動程式和驅動影片發現很順,我的卻是力量不足,轉速不足... 想要請問先進們,如何增加它的力量和降低ULN2003的溫度,因為溫度升到攝氏60度以上....
線路:
驅動:目前驅動為 6步: STEP1 STEP2 STEP3 STEP4 STEP5 STEP6
原先設計驅動3步驅動: STEP1 STPE3 STEP5
麵包板測試(3歐姆限流)
現況1歐姆限流)
網路的程式:
- The code is very simple, here is mine, I am not sure if I used this exact code in the video, you might need to tinker with it.
- int phase1 = 2;
- int phase2 = 3;
- int phase3 = 4;
- int led = 12;
- unsigned long stepLength = 40000;
- int minStepLength = 1400;
- int steps = 5;
- void setup() {
- pinMode(led, OUTPUT);
- pinMode(phase1, OUTPUT);
- pinMode(phase2, OUTPUT);
- pinMode(phase3, OUTPUT);
- digitalWrite(led, LOW);
- }
- void loop() {
- switchStep(1);
- switchStep(2);
- switchStep(3);
-
- if(stepLength > minStepLength)
- {
- stepLength = stepLength - steps;
- } else {
- // set the minimum pulse length
- stepLength=minStepLength;
- }
-
- if (stepLength < 39950) {
- digitalWrite(led, HIGH); // second gear
- steps = 300;
- }
-
- if (stepLength < 20000) {
- digitalWrite(led, LOW); // third gear
- steps = 50;
- }
- if (stepLength < 3000) {
- digitalWrite(led, HIGH); // fourth gear
- steps = 2;
- }
- }
- void switchStep(int stage)
- {
- switch(stage)
- {
- case 1:
- digitalWrite(phase1, HIGH);
- digitalWrite(phase2, LOW);
- digitalWrite(phase3, LOW);
- myDelay(stepLength);
- break;
-
- case 2:
- digitalWrite(phase1, LOW);
- digitalWrite(phase2, HIGH);
- digitalWrite(phase3, LOW);
- myDelay(stepLength);
- break;
-
- default:
- digitalWrite(phase1, LOW);
- digitalWrite(phase2, LOW);
- digitalWrite(phase3, HIGH);
- myDelay(stepLength);
- break;
- }
- }
複製代碼
我目前的程式:
- #include "stm8s.h"
- #include "stm8s_tim4.h"
- #include "global_defined.h"
- #include "stm8s_gpio.h"
- #include "stm8s_conf.h"
- #define coilPORT GPIOC
- #define inputPORT GPIOB
- #define speed_set GPIO_PIN_LNIB //read low 4bits data
- #define coil1 GPIO_PIN_1 //motor coil 1
- #define coil2 GPIO_PIN_2 //motor coil 2
- #define coil3 GPIO_PIN_7 //motor coil 3
- #define led_indicator GPIO_PIN_3 //LED indicator
- #define free_ext_run GPIO_PIN_7 //free_ext_run
- #define enable_pin GPIO_PIN_4
- #define DIR_pin GPIO_PIN_5
- #define CLK_pin GPIO_PIN_6
- u8 speed_delay_time;
- u8 speed_basic_data=23;
- u8 speed_parameter[]={0,10,20,30,40,50,60,70,80,90,100,110,120,130,140,150};
- u8 time_count_100us_flag;
- u8 free_run_flag;
- u8 free_run_set;//check sw free run is set
- void GPIOinit(void)//basic i/o setting
- {
- GPIO_Init(coilPORT,GPIO_PIN_ALL,GPIO_MODE_OUT_PP_HIGH_FAST);//coil port
- GPIO_Init(inputPORT,GPIO_PIN_ALL,GPIO_MODE_IN_PU_NO_IT);//all input port
- }
- void step_delay(u16 delay_100us)//motor coil step time delay if 7200rpm motor 1rotate 8.33ms 2.777ms per step
- {
- while(delay_100us)
- {
- if(time_count_100us_flag==1)
- {
- delay_100us -= 1;
- time_count_100us_flag=0;//timer flag reset
- }
- }
- }
- void switch_step(u8 stage)
- {
- switch(stage)
- {
- case 1:
- GPIO_WriteHigh(coilPORT,coil1);
- GPIO_WriteLow(coilPORT,coil2);
- GPIO_WriteLow(coilPORT,coil3);
- step_delay(30);//coil power on period
- GPIO_WriteLow(coilPORT,coil1);//turn off coil current
- break;
- case 2:
- GPIO_WriteLow(coilPORT,coil1);
- GPIO_WriteHigh(coilPORT,coil2);
- GPIO_WriteLow(coilPORT,coil3);
- step_delay(30);//coil power on period
- GPIO_WriteLow(coilPORT,coil2);//turn off coil current
- break;
- case 3:
- GPIO_WriteLow(coilPORT,coil1);
- GPIO_WriteLow(coilPORT,coil2);
- GPIO_WriteHigh(coilPORT,coil3);
- step_delay(30);//coil power on period
- GPIO_WriteLow(coilPORT,coil3);//turn off coil current
- break;
-
- case 11:
- GPIO_WriteHigh(coilPORT,coil1);
- GPIO_WriteLow(coilPORT,coil2);
- GPIO_WriteLow(coilPORT,coil3);
- step_delay(15);//coil power on period
- GPIO_WriteLow(coilPORT,coil1);//turn off coil current
- break;
- case 12:
- GPIO_WriteLow(coilPORT,coil1);
- GPIO_WriteHigh(coilPORT,coil2);
- GPIO_WriteLow(coilPORT,coil3);
- step_delay(15);//coil power on period
- GPIO_WriteLow(coilPORT,coil2);//turn off coil current
- break;
- case 13:
- GPIO_WriteLow(coilPORT,coil1);
- GPIO_WriteLow(coilPORT,coil2);
- GPIO_WriteHigh(coilPORT,coil3);
- step_delay(15);//coil power on period
- GPIO_WriteLow(coilPORT,coil3);//turn off coil current
- break;
-
-
-
- case 21:
- GPIO_WriteHigh(coilPORT,coil1);
- GPIO_WriteHigh(coilPORT,coil2);
- GPIO_WriteLow(coilPORT,coil3);
- step_delay(15);//coil power on period
- GPIO_WriteLow(coilPORT,coil1);//turn off coil current
- break;
- case 22:
- GPIO_WriteLow(coilPORT,coil1);
- GPIO_WriteHigh(coilPORT,coil2);
- GPIO_WriteHigh(coilPORT,coil3);
- step_delay(15);//coil power on period
- GPIO_WriteLow(coilPORT,coil2);//turn off coil current
- break;
- case 23:
- GPIO_WriteHigh(coilPORT,coil1);
- GPIO_WriteLow(coilPORT,coil2);
- GPIO_WriteHigh(coilPORT,coil3);
- step_delay(15);//coil power on period
- GPIO_WriteLow(coilPORT,coil3);//turn off coil current
- break;
-
-
- }
- }
複製代碼
|
-
|