[英]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.