Với Loại opto Tốc độ Cao Có thể dùng Dòng TLP2345 Với xung ra 5V hoặc 24V Tùy Mục đích Sử Dụng
Các Bạn Cài đặt vào chế độ Phát Xung +Chiều
Đến Chương trình Phát xung Arduino như sau:
#define PWM1 PE13
#define PWM2 PE14
#define output PE13
long int chophepchay=0;
long int timess=0;
long int cnt_xung=0;
void taoxungsv(int timengat){
if(chophepchay){
if(micros() > timess) {digitalWrite(output,!digitalRead(output));
timess = micros()+timengat;}
else if(micros()<100)timess=0;
} else {digitalWrite(output,0); }
}
void stop_motor(void)
{
analogWriteFrequency(0); // Set PMW period to 500 Hz
analogWrite(PWM1,0); // Start PWM on A1, at 1000 Hz with 50% duty cycle
analogWriteFrequency(0); // Set PMW period to 2000 Hz instead of 1000
analogWrite(PWM2, 0); // Start PWM on A2, at 2000 Hz with 25% duty cycle
}
void setup() {
// put your setup code here, to run once:
pinMode(PWM1, OUTPUT);
pinMode(output, OUTPUT);
pinMode(PWM2, OUTPUT);chophepchay=1;
}
void loop() {
// put your main code here, to run repeatedly:
// Assuming Ax pins have PWM capabilities and use a different Timer.
if(chophepchay==1)
{
analogWriteFrequency(300000); // Set PMW period to 500 Hz
analogWrite(PWM1,50); // Start PWM on A1, at 1000 Hz with 50% duty cycle
analogWriteFrequency(300000); // Set PMW period to 2000 Hz instead of 1000
analogWrite(PWM2, 50); // Start PWM on A2, at 2000 Hz with 25% duty cycle
}
else
{
// stop_motor();
}
//taoxungsv(10);
//
//if(++cnt_xung>20000000) { chophepchay=1;}
}
Chương trình Tạo Xung taoxungsv(10); Để Gọi tần số chạy Hàm Này thay đổi tần số Servo .
Bạn muốn chính xác gọi hàm
analogWriteFrequency(300000); // Tần số xuất 300khz
analogWrite(PWM1,50); // Độ rộng Xung 50
Cảm ơn các bạn đã ghé thăm shop