律师2313A ||使用 RC 接收器 (Graupner 400) 进行直流电机控制的 PWM 信号

问题描述 投票:0回答:1

我正在 Microchip Studio 中编写程序,使用 RC 无线电接收器控制 DC 6V 引擎(graupner 400 max 4,0A)。 我正在使用 Attiny 2313A 和 F_CPU 16 MHz。

RC 接收器通过 PD2 引脚向 MCU 发送 PWM 信号。

MCU 必须向 PIN 发送 PWM 信号 PB3 + PB2 发动机左转 PB4 + PC5 引擎右转

为了控制电机,我想生成频率为 1 kHz 的 PWM 信号。

下面是我的程序和编译过程中的错误。非常感谢!

#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 16000000L
#define A PB3
#define D PB2
#define B PB4
#define C PD5

//Fast PWM
void PWM_100p_PRZOD()
{
    TCCR0A = (1<<COM0A1) | (1 << WGM02) | (1 << WGM01) | (1 << WGM00);
    TCCR1A = (1<<COM1A1) | (1 << WGM12) | (1 << WGM10);
    OCR0A= 255;
    OCR1A= 65535;
}

void PWM_0p_TYL()
{
    TCCR0B = (1<<COM0B1) | (1 << WGM02) | (1 << WGM01) | (1 << WGM00) | (1 << CS01);
    TCCR1B = (1<<COM1B1) | (1 << WGM12) | (1 << WGM10);
    OCR0B= 0;
    OCR1B= 0;
}
int main(void)
{
    DDRB |= (1 << DDB2) | (1 << DDB3) | (1 << DDB4);
    DDRD |= (1 << DDD5);
    PORTB &= ~((1 << A) | (1 << D) | (1 << B));
    PORTD &= ~(1 << C);
    DDRD &= ~(1 << PD2);
    PORTD &= ~(1 << PD2);
    
    while(1)
    {
        PWM_100p_PRZOD();
        _delay_ms(100);
    }
    return 0;
}
        }
        _delay_ms(100);
    }
    return 0;
}

错误

'ADMUX' undeclared (first use in this function)
'REFS0' undeclared (first use in this function)
'ADCSRA' undeclared (first use in this function)
'ADEN' undeclared (first use in this function)
'ADPS2' undeclared (first use in this function)
'ADPS1' undeclared (first use in this function)
'ADPS0' undeclared (first use in this function)
'ADMUX' undeclared (first use in this function)
'ADCSRA' undeclared (first use in this function)
'ADSC' undeclared (first use in this function)
'ADC' undeclared (first use in this function)
#error "Attempt to include more than one <avr/ioXXX.h> file."
#warning "F_CPU not defined for <util/delay.h>" [-Wcpp]
recipe for target 'main

avr pwm attiny motorengine
1个回答
0
投票

您的项目属性可能设置不正确。选择 Project > Properties 并检查 Device 设置。 编程器是一个单独的应用程序,只能从 IDE 启动,其设置可以与正在编译的项目完全不同。因此,在寻找编译错误原因时提及它是完全无关紧要的。

© www.soinside.com 2019 - 2024. All rights reserved.