【问题标题】:Control multiple Servo using avr [closed]使用 avr 控制多个伺服 [关闭]
【发布时间】:2016-02-12 20:06:19
【问题描述】:

我想通过直接切换输出来尝试使用带有 timer1 的 avr 来控制大约 20 个伺服系统(用于机器人)。 这就是我到目前为止所能想到的。但是当我尝试添加最后两个舵机时,所有舵机都失败了。我假设这是一个时间问题。但我不知道如何纠正这一点。我在网上搜索,但没有找到任何具体的答案。

如果有人能指出他们谈论控制多个伺服系统的好消息来源,那将非常有帮助

int main(void)
{
    DDRB = 0xFF;
    DDRA = 0xFF;

    TCCR1A |= 1<<WGM11; 
    TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
    TIMSK |= 1 << OCIE1A;

    ICR1 = 19999;  // Clear on reaching this point. 
    uint16_t count = MIN_VAL;
    uint16_t count2 = 2000; 
    uint16_t c_rp = MIN_VAL;
    uint16_t c_rp2 = 1000; 
    uint16_t c_rp3 = MIN_VAL;



    sei();
    while(1)
    {
        // Control PORT B PINS 
        // TCNT1 counts upwards and on reaching count 
        // an then the pin goes low
        // SERVO 1
        if( (  PORTB & (1<<PIN) ) && TCNT1 >= count)
        {
            PORTB &= ~(1<<PIN);
            if (count < MAX_VAL)
                count  += INC_VAL; // CHANGING SERVO POSITION
            else
                count = MIN_VAL; 

        }

        // SERVO 2
        if( (  PORTB & (1<<PIN2) ) && TCNT1 >= count2)
        {
            PORTB &= ~(1<<PIN2); // CONSTANT SERVO POSITION

        }


        // Control PORT A PINS 
         // SERVO 3
        if( (  PORTA & (1<<RP) ) && TCNT1 >= c_rp)
        {
            PORTA &= ~(1<<RP);
            if (c_rp < MAX_VAL)
                c_rp  += INC_VAL;
            else
                c_rp = MIN_VAL; 

        }

          // SERVO 4
        if( (  PORTA & (1<<RP2) ) && TCNT1 >= c_rp2)
        {
            PORTA &= ~(1<<RP2);

        }

 }


ISR (TIMER1_COMPA_vect) // ISR called when TCNT1 equals ICR1
{
    PORTB |= (1<< PIN ) | (1<< PIN2) ;
    PORTA |= (1 << RP ) | (1 << RP2) | (1<< RP3);
}

【问题讨论】:

  • 从您发布的代码中并不清楚您想要实现什么,也不清楚什么没有按您期望的方式工作。

标签: c assembly embedded avr atmega


【解决方案1】:

通过这种无耻的自我推销,我至少可以得到 12 个。不过,它可能会为您指明正确的方向: https://github.com/pengumc/servocontroller/blob/ef4d7c69e96375feeab30072e7b7f7975616cc87/src/ServoControllerI2C.c

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多