Skip to content
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

Default DELAY_NS to round up. #21546

Merged
merged 20 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ec50d3d
Laser percent power
thinkyhead Dec 9, 2020
98799b5
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Dec 14, 2020
74367bc
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Dec 29, 2020
4a2dab7
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Jan 25, 2021
aa713a1
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Feb 1, 2021
2cc4d48
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Feb 2, 2021
8db0a77
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Mar 3, 2021
9dbc82f
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Mar 5, 2021
329e211
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Mar 12, 2021
80c48b0
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Mar 16, 2021
a9a8bf5
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Mar 24, 2021
245ffde
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Mar 31, 2021
825d057
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bugfix-2.0.x
descipher Apr 5, 2021
7608915
Default DELAY_NS to round up.
descipher Apr 5, 2021
f3c3b24
Keep PWM255 default ...
descipher Apr 5, 2021
1a61fb5
AVR is the intent for round up.
descipher Apr 5, 2021
b365600
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/21546
thinkyhead Apr 5, 2021
7fb3d27
is integer "ceil" good enough?
thinkyhead Apr 5, 2021
88dd2ff
update comments
thinkyhead Apr 5, 2021
ddddddc
align
thinkyhead Apr 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions Marlin/src/HAL/shared/Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,37 @@ void calibrate_delay_loop();

#endif

// Delay in nanoseconds
#define DELAY_NS(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL) / 1000UL)

/**************************************************************
* Delay in nanoseconds. Requires the F_CPU macro.
* These macros follow avr-libc delay conventions.
*
* For AVR there are three possible operation modes, due to its
* slower clock speeds and thus coarser delay resolution. For
* example, when F_CPU = 16000000 the resolution is 62.5ns.
*
* Round up (default)
* Round up the delay according to the CPU clock resolution.
* e.g., 100 will give a delay of 2 cycles (125ns).
*
* Round down (DELAY_NS_ROUND_DOWN)
* Round down the delay according to the CPU clock resolution.
* e.g., 100 will be rounded down to 1 cycle (62.5ns).
*
* Nearest (DELAY_NS_ROUND_CLOSEST)
* Round the delay to the nearest number of clock cycles.
* e.g., 165 will be rounded up to 3 cycles (187.5ns) because
* it's closer to the requested delay than 2 cycle (125ns).
*/

#ifndef __AVR__
#undef DELAY_NS_ROUND_DOWN
#undef DELAY_NS_ROUND_CLOSEST
#endif

#if ENABLED(DELAY_NS_ROUND_DOWN)
#define DELAY_NS(x) DELAY_CYCLES((x) * ((F_CPU) / 1000000UL) / 1000UL) // floor
#elif ENABLED(DELAY_NS_ROUND_CLOSEST)
#define DELAY_NS(x) DELAY_CYCLES(((x) * ((F_CPU) / 1000000UL) + 500) / 1000UL) // round
#else
#define DELAY_NS(x) DELAY_CYCLES(((x) * ((F_CPU) / 1000000UL) + 999) / 1000UL) // "ceil"
#endif
2 changes: 1 addition & 1 deletion Marlin/src/lcd/dogm/ultralcd_st7920_u8glib_rrd_AVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#elif F_CPU == 16000000
#define CPU_ST7920_DELAY_1 DELAY_NS(125)
#define CPU_ST7920_DELAY_2 DELAY_NS(0)
#define CPU_ST7920_DELAY_3 DELAY_NS(125)
#define CPU_ST7920_DELAY_3 DELAY_NS(188)
#else
#error "No valid condition for delays in 'ultralcd_st7920_u8glib_rrd_AVR.h'"
#endif
Expand Down