Better handling of DELAY_NS and DELAY_US (#10716)

Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
Scott Lahteine
2018-05-12 08:34:04 -05:00
committed by GitHub
parent f5aaa2d6c0
commit a1062eec5b
21 changed files with 273 additions and 268 deletions

View File

@ -60,19 +60,16 @@
#include "../module/planner.h"
#include "../module/stepper.h"
#include "../Marlin.h"
#include "../HAL/Delay.h"
static uint8_t LEDs[8] = { 0 };
#ifdef CPU_32_BIT
// Approximate a 1µs delay on 32-bit ARM
void SIG_DELAY() {
int16_t delay_cycles = CYCLES_PER_MICROSECOND - 10;
while (delay_cycles >= 10) { DELAY_NOPS(6); delay_cycles -= 10; }
if (delay_cycles > 0) DELAY_NOPS(delay_cycles);
}
#define SIG_DELAY() DELAY_US(1)
#else
// Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
#define SIG_DELAY() DELAY_3_NOP
#define SIG_DELAY() DELAY_NS(188)
#endif
void Max7219_PutByte(uint8_t data) {

View File

@ -12,6 +12,7 @@
#include "../../Marlin.h"
#include "../../module/stepper.h"
#include "../../HAL/Delay.h"
dac084s085::dac084s085() { }
@ -27,11 +28,11 @@ void dac084s085::begin() {
spiBegin();
//init onboard DAC
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC0_SYNC, LOW);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC0_SYNC, HIGH);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC0_SYNC, LOW);
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
@ -39,11 +40,11 @@ void dac084s085::begin() {
#if EXTRUDERS > 1
//init Piggy DAC
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC1_SYNC, LOW);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC1_SYNC, HIGH);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC1_SYNC, LOW);
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
@ -66,20 +67,20 @@ void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
if (channel > 3) { // DAC Piggy E1,E2,E3
WRITE(DAC1_SYNC, LOW);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC1_SYNC, HIGH);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC1_SYNC, LOW);
}
else { // DAC onboard X,Y,Z,E0
WRITE(DAC0_SYNC, LOW);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC0_SYNC, HIGH);
delayMicroseconds(2U);
DELAY_US(2);
WRITE(DAC0_SYNC, LOW);
}
delayMicroseconds(2U);
DELAY_US(2);
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
}