-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong inline asm constraint in delayMicroseconds #12
Labels
bug
Something isn't working
Comments
What's the reason for the slightly different delayMicroseconds implementation in ArduinoShrink and picoCore? ArduinoShrink: Lines 25 to 41 in a95c1c4
picoCore: __attribute((always_inline))
static inline void delayMicroseconds(uint16_t us)
{
// if us is a compile-time constant result is accurate to 1 cycle
if (__builtin_constant_p(us)) {
_delay_us(us);
return;
}
// when us is not known at compile time, delay is accurate to +/- 2us
// plus an overhead of 3 CPU cycles
const float fMHz = (F_CPU/1000000.0);
// subtract two for rounding before dividing by 4
us -= 2;
delay4us:
// delay 4us per loop, less 4 cycles for overhead
_delay_us(4.0 - (4.0 / fMHz));
asm volatile ("sbiw %[us], 4" : [us]"+d"(us));
asm goto( "brpl %l[delay4us]" :::: delay4us);
} |
picoCore is designed to work at lower frequencies, such as 4.8Mhz or even
1.2Mhz. ArduinoShink is designed for the common frequencies of 8 and
16Mhz. If you try to build ArduinoShink with F_CPU set to 1Mhz it will
fail.
…On Wed, Jan 4, 2023, 13:47 Hans ***@***.***> wrote:
What's the reason for the slightly different delayMicroseconds
implementation in ArduinoShrink and picoCore?
ArduinoShrink:
https://github.com/nerdralph/ArduinoShrink/blob/a95c1c40721834e714f6bfe88fe0a280a7940052/src/as_wiring.c#L25-L41
picoCore:
__attribute((always_inline))
static inline void delayMicroseconds(uint16_t us)
{
// if us is a compile-time constant result is accurate to 1 cycle
if (__builtin_constant_p(us)) {
_delay_us(us);
return;
}
// when us is not known at compile time, delay is accurate to +/- 2us
// plus an overhead of 3 CPU cycles
const float fMHz = (F_CPU/1000000.0);
// subtract two for rounding before dividing by 4
us -= 2;
delay4us:
// delay 4us per loop, less 4 cycles for overhead
_delay_us(4.0 - (4.0 / fMHz));
asm volatile ("sbiw %[us], 4" : [us]"+d"(us));
asm goto( "brpl %l[delay4us]" :::: delay4us);
}
—
Reply to this email directly, view it on GitHub
<#12 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABKNZ6TJ6BVL62MV6EEQN5LWQWZRVANCNFSM6AAAAAATP6TSQA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug first discovered in MicroCore, which uses the same code.
MCUdude/MicroCore#136
The text was updated successfully, but these errors were encountered: