繁体   English   中英

PlatformIO ATMega324P util / delay.h不准确

[英]PlatformIO ATMega324P util/delay.h not accurate

我正在使用PlatformIO和CLion对ATMega324P微控制器进行编程。 该项目是在Mac上使用PlatformIO创建的,并在CLion中打开。 我可以成功构建程序并在ATMega324p上运行它。 我成功运行以下代码。

main.cpp中

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    DDRB |= 1 << PINB0; 

    while (true)
    {
        PORTB ^= 1 << PINB0; 
        _delay_ms(100);
    }
}

Platformio.ini

[env:mightycore324]
platform = atmelavr
board = mightycore324
framework = arduino
upload_protocol = usbtiny
board_f_cpu = 16000000L

尽管运行此代码,但延迟明显不准确。 我是否有任何措施来确保延迟正常工作?

您的MCU可能正在运行其内部RC振荡器。 该振荡器不是特别精确-指定为8 MHz,但是各个部分的运行频率可能在7.3至8.1 MHz之间。

为了获得更准确的时序,您需要连接一个外部晶振并相应地设置时钟熔丝。

以下设置解决了我的问题。

Platformio.ini

[env:mightycore324]
platform = atmelavr
board = mightycore324
framework = arduino
upload_protocol = usbtiny
board_f_cpu = 800000L

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM