问题描述
我在 Arduino 环境中使用 11.0592MHz 的 ATMega328P.我认识到 delayMicroseconds() 函数的速度太快了大约 27%.原因是,wiring.c 中的代码假设时钟速度现在为 8MHz.
I am using the ATMega328P at 11.0592MHz with the Arduino environment. I recognized that the delayMicroseconds() function is about 27% too fast. The reason is, that the code in wiring.c assumes that the clock peed is now 8MHz.
现在我尝试修复它.我找到了不同的帖子,但我不确定最兼容 Arduino 的方式是什么.你能推荐什么?
Now I try to fix it. I found different posts but I am not sure what is the most Arduino compatible way. What can you recommend?
- 如果 F_CPU 为 11.0592MHz,将wiring.c 中的变量us"乘以1.27?简单,但只影响 delayMicroseconds 而不是 millis()、micros()、delay() 等.
- 将预缩放因子从 64 更改为 ???
其他想法或指南?
提前致谢.
菲利克斯
推荐答案
Arduino 的方式是为您的开发板制作一个具有新 F_CPU 速度的定制平台.核心库应该通过这个 F_CPU.
The Arduino way would be to make a custom PLATFORM for your board with that of the new F_CPU speed. The core libraries should carry this F_CPU through.
这很容易,通过使用您的差异制作 board.txt 文件.文件的位置(两者之间相同)在两个当前 IDE 之间不同.以 Arduino IDE 1.0.5 为例:
This is easy enough, by making a boards.txt file with your differences. Where the location of the file (same between the two) is different between the two current IDE's. In the case of Arduino IDE 1.0.5:
C:\Users\mflaga\Documents\Arduino\hardware\myArduino11MgHz\boards.txt
在 1.5.5 的情况下:
and in the case of 1.5.5:
C:\Users\mflaga\Documents\Arduino\hardware\myArduino11MgHz\avr\boards.txt
在您的情况下,草图目录会有所不同.
Where in your case the sketch directory would be different.
# See: http://code.google.com/p/arduino/wiki/Platforms
##############################################################
myArduino11MgHz.name=Arduino 11MgHz
myArduino11MgHz.vid.0=0x2341
myArduino11MgHz.pid.0=0x0043
myArduino11MgHz.vid.1=0x2341
myArduino11MgHz.pid.1=0x0001
myArduino11MgHz.upload.tool=avrdude
myArduino11MgHz.upload.protocol=arduino
myArduino11MgHz.upload.maximum_size=32256
myArduino11MgHz.upload.maximum_data_size=2048
myArduino11MgHz.upload.speed=115200
myArduino11MgHz.bootloader.tool=avrdude
myArduino11MgHz.bootloader.low_fuses=0xFF
myArduino11MgHz.bootloader.high_fuses=0xDE
myArduino11MgHz.bootloader.extended_fuses=0x05
myArduino11MgHz.bootloader.unlock_bits=0x3F
myArduino11MgHz.bootloader.lock_bits=0x0F
myArduino11MgHz.bootloader.file=optiboot/optiboot_atmega328.hex
myArduino11MgHz.build.mcu=atmega328p
myArduino11MgHz.build.f_cpu=11059200L
myArduino11MgHz.build.board=AVR_myArduino11MgHz
myArduino11MgHz.build.core=arduino:arduino
myArduino11MgHz.build.variant=arduino:standard
##############################################################
这是 board.txt 的第 3 方 GUI 编辑器.
Here is a 3rd party GUI Editor of the board.txt.
免责声明.以上确实可以编译并且应该可以正常工作.我还没有实际测试并加载到单元中的地方.
Disclaimer. The above does compile and should work fine. Where I have not actually tested and loaded into a unit.
也就是说,我希望引导加载程序的 F_CPU 不匹配.对此有三种可能的解决方案.
That said, I would expect the bootloader's F_CPU not to match. There are three possible solutions to this.
第一;optiboot 加载程序应该有一个对应的目标,其偏差如下:
First; the optiboot loader should have a corresponding target with the below deviation:
\arduino-1.5.5\hardware\arduino\avr\bootloaders\optiboot\Makefile
myArduino11MgHz: AVR_FREQ = 11059200L
第二;更改boards.txt上传速度以匹配=115200*(11059200/16000000)的变化.
Second; Change the boards.txt upload speed to match the change of =115200*(11059200/16000000).
myArduino11MgHz.upload.speed=79626
这是一个非典型的波特率,avrdude 或串口可能支持它.
This being a non typical baud rate, either avrdude or the serial port may support it.
第三;不要使用引导加载,通过 ISP 编程器上传.
Third; Don't use the bootload, by uploading via the ISP programmer.
我也计划用不同的 F_CPU 制作一块板,但实际上只制作了具有相同速度的定制板.对于您的情况,我很想知道上述方法是否真的有效.
I have likewise planned to make a board with a different F_CPU, but only actually made custom boards, with the same speed. I would be curious to know if the above actually works, in your case.
这篇关于Arduino 频率为 11.0592MHz.修改 Timer0, delayMicroseconds()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!