在DIY黑膠唱機的過程中国旷,準備用一個42步進電機帶動唱盤呐芥,需要恒定的每分鐘33.33轉的轉速志秃。
記錄一下折騰的過程漠魏。
用洞洞板制作的驅動電路:
step_driver_01.jpg
step_driver_board.jpg
驅動板接線圖:
wiring.png
先拿價格便宜很多的A4988做實驗:
A4988.png
A4988_01.png
按照接線圖在面包板上把線接好柬脸。
Ardunio代碼如下:
bool PULSE_STATE = true;
// A4988引腳連接Arduino引腳編號
const int dirPin = 2; // Direction
const int stepPin = 3; // Step
const int sleepPin = 4; // Sleep
const int resetPin = 5; // Reset
const int ms3Pin = 6; // Ms3
const int ms2Pin = 7; // Ms2
const int ms1Pin = 8; // Ms1
const int enPin = 9; // Enable
void setup() {
// 設置引腳模式
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(sleepPin,OUTPUT);
pinMode(resetPin,OUTPUT);
pinMode(ms3Pin,OUTPUT);
pinMode(ms2Pin,OUTPUT);
pinMode(ms1Pin,OUTPUT);
pinMode(enPin,OUTPUT);
// 初始化引腳狀態(tài)
digitalWrite(sleepPin, HIGH);
digitalWrite(resetPin, HIGH);
digitalWrite(enPin, LOW);
digitalWrite(ms1Pin, LOW);
digitalWrite(ms2Pin, LOW);
digitalWrite(ms3Pin, LOW);
// 初始化電機步進模式為全步進
//TMC2209 64細分
digitalWrite(ms1Pin, LOW);
digitalWrite(ms2Pin, HIGH);
//Clockwise 順時針旋轉
digitalWrite(dirPin, 1);
cli(); //stop interrupts for till we make the settings
/*1. First we reset the control register to amke sure we start with everything disabled.*/
TCCR1A = 0; // Reset entire TCCR1A to 0
TCCR1B = 0; // Reset entire TCCR1B to 0
TCNT1 = 0;
// turn on CTC mode
TCCR1B |= (1 << WGM12);
/*2. We set the prescalar to the desired value by changing the CS10 CS12 and CS12 bits. */
TCCR1B |= B00000001;
/*3. We enable compare match mode on register A*/
TIMSK1 |= (1 << OCIE1A);
OCR1A = 1125; //Finally we set compare register A to this value
sei(); //Enable back the interrupts
}
void loop() {
// put your main code here, to run repeatedly:
}
ISR(TIMER1_COMPA_vect){
PULSE_STATE = !PULSE_STATE;
digitalWrite(stepPin,PULSE_STATE);
}
代碼主要使用了TIMER1定時器痘绎。需要計算發(fā)送到電機的脈沖頻率。用的Arduino NANO 主頻是26MHz, 普通42步進電機的步距角是1.8度肖粮,轉一圈都要200個脈沖孤页,A4988芯片最大可使用的細分是16細分,如果用16細分涩馆,轉一圈都要20016=3200個脈沖行施。我的目標是每三分鐘轉100轉允坚,需要的脈沖頻率是1003200/(3*60)=1777.77Hz
A4988驅動芯片噪音比較大,步進電機運轉時震動比較大蛾号。試驗成功之后稠项,換上了高大上的TMC2209芯片,電機低速運轉時超級安靜鲜结,震動極小展运。TMC2209內部支持256細分,計算脈沖頻率的時候需要重新計算一下精刷。上面代碼中使用的是TMC2209芯片的版本拗胜。
用洞洞板制作的時候,用了一片LM7809穩(wěn)壓芯片給NANO主板供電怒允,但當使用24伏電壓時埂软,LM7809芯片發(fā)熱比較嚴重。后續(xù)準備換一個DCDC模塊纫事。