简体   繁体   English

PlatformIO ATMega324P util / delay.h不准确

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

I am using PlatformIO and CLion to program an ATMega324P Microcontroller. 我正在使用PlatformIO和CLion对ATMega324P微控制器进行编程。 The project is created with PlatformIO on a mac and opened in CLion. 该项目是在Mac上使用PlatformIO创建的,并在CLion中打开。 I can successfully build the program and run it on the ATMega324p. 我可以成功构建程序并在ATMega324p上运行它。 I run the following code successfully. 我成功运行以下代码。

main.cpp 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 Platformio.ini

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

Although this code run the delay seems noticeably inaccurate. 尽管运行此代码,但延迟明显不准确。 Do I have do anything to make sure the delay is working properly? 我是否有任何措施来确保延迟正常工作?

Your MCU is probably running off its internal RC oscillator. 您的MCU可能正在运行其内部RC振荡器。 This oscillator isn't particularly precise -- it's specified as 8 MHz, but individual parts may run anywhere from 7.3 to 8.1 MHz. 该振荡器不是特别精确-指定为8 MHz,但是各个部分的运行频率可能在7.3至8.1 MHz之间。

To get more accurate timing, you'll need to attach an external crystal and program the clock fuses accordingly. 为了获得更准确的时序,您需要连接一个外部晶振并相应地设置时钟熔丝。

The following settings fixed my issue. 以下设置解决了我的问题。

Platformio.ini 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