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

Nikon IR support for time lapse photos #16539

Merged
merged 4 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
* FAST_PWM_FAN_FREQUENCY [undefined by default]
* Set this to your desired frequency.
* If left undefined this defaults to F = F_CPU/(2*255*1)
* ie F = 31.4 Khz on 16 MHz microcontrollers or F = 39.2 KHz on 20 MHz microcontrollers
* i.e., F = 31.4kHz on 16MHz microcontrollers or F = 39.2kHz on 20MHz microcontrollers.
* These defaults are the same as with the old FAST_PWM_FAN implementation - no migration is required
* NOTE: Setting very low frequencies (< 10 Hz) may result in unexpected timer behavior.
*
Expand Down Expand Up @@ -2444,6 +2444,20 @@

// Duration to hold the switch or keep CHDK_PIN high
//#define PHOTO_SWITCH_MS 50 // (ms) (M240 D)

/**
* PHOTO_PULSES_US may need adjustment depending on board and camera model.
* Pin must be running at 48.4kHz.
* Be sure to use a PHOTOGRAPH_PIN which can rise and fall quick enough.
* (e.g., MKS SBase temp sensor pin was too slow, so used P1.23 on J8.)
*
* Example pulse data for Nikon: https://bit.ly/2FKD0Aq
* IR Wiring: https://git.io/JvJf7
*/
//#define PHOTO_PULSES_US { 2000, 27850, 400, 1580, 400, 3580, 400 } // (µs) Durations for each 48.4kHz oscillation
#ifdef PHOTO_PULSES_US
#define PHOTO_PULSE_DELAY_US 13 // (µs) Approximate duration of each HIGH and LOW pulse in the oscillation
#endif
#endif

/**
Expand Down
43 changes: 38 additions & 5 deletions Marlin/src/gcode/feature/camera/M240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,44 @@
#endif

#if PIN_EXISTS(PHOTOGRAPH)
constexpr uint8_t NUM_PULSES = 16;
constexpr float PULSE_LENGTH = 0.01524;
inline void set_photo_pin(const uint8_t state) { WRITE(PHOTOGRAPH_PIN, state); _delay_ms(PULSE_LENGTH); }
inline void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }
inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }

FORCE_INLINE void set_photo_pin(const uint8_t state) {
constexpr uint32_t pulse_length = (
#ifdef PHOTO_PULSES_US
PHOTO_PULSE_DELAY_US
#else
15 // 15.24 from _delay_ms(0.01524)
#endif
);
WRITE(PHOTOGRAPH_PIN, state);
delayMicroseconds(pulse_length);
}

FORCE_INLINE void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }

#ifdef PHOTO_PULSES_US

inline void pulse_photo_pin(const uint32_t duration, const uint8_t state) {
if (state) {
for (const uint32_t stop = micros() + duration; micros() < stop;)
tweak_photo_pin();
}
else
delayMicroseconds(duration);
}

inline void spin_photo_pin() {
static constexpr uint32_t sequence[] = PHOTO_PULSES_US;
for (uint8_t i = 0; i < COUNT(sequence); i++)
pulse_photo_pin(sequence[i], !(i & 1));
}

#else

constexpr uint8_t NUM_PULSES = 16;
inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }

#endif
#endif

/**
Expand Down