Robofun 機器人論壇
標題:
[馬達問題MG-995][atmega32控制問題]我是新手!幫解
[打印本頁]
作者:
nosniw_2003
時間:
2009-6-16 22:26
標題:
[馬達問題MG-995][atmega32控制問題]我是新手!幫解
我是一個新手,請教各位大大幫忙我
請問各位專家!!
1) 為什麼我的SERVO MG-995只可以轉60度而不可轉180度?
2) 我打算用atmega32控制8個 SERVO, 下面的是我的CODE, 但是不知道為什麼 channel 0,1 沒有轉而只停在140度, 其他channel 就沒問題停在90度.
code:
// up to 8 servos on portB sequentially controlled
// mega32
// 8 MHz
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
// initial pulse times in us for servo 0, 1, 2...(last value is a synchro gap)
unsigned int servo[9] = {1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 6000};
volatile unsigned char servo_num = 0;
ISR(TIMER1_COMPA_vect)
{
PORTD = (1<<servo_num);
OCR1A = servo[servo_num];
servo_num++;
servo_num %= 9; // if servo_num = 9 then servo_num = 0;
}
int main (void)
{
DDRD = 255; // portb output
TCCR1B |= (1<<WGM12) | (1<<CS11); // pwm mode 4, prescale 8
TIMSK |= (1<<OCIE1A); // enable T1_compareA interrupt
sei();
for(;;) // test
{
servo[0] = 1000; // servos 0 and 1 left
servo[1] = 1000;
_delay_ms(5000);
servo[0] = 1500; // servos 0 and 1 center
servo[1] = 1500;
_delay_ms(5000);
servo[0] = 2000; // servos 0 and 1 right
servo[1] = 2000;
_delay_ms(5000);
}
}//main
感謝啦!
歡迎光臨 Robofun 機器人論壇 (https://robofun.net/forum/)
Powered by Discuz! X3.2