瀏覽代碼

Nikon IR support for time lapse photos (#16539)

gjdodd 4 年之前
父節點
當前提交
7481563bd9
共有 2 個檔案被更改,包括 53 行新增6 行删除
  1. 15
    1
      Marlin/Configuration_adv.h
  2. 38
    5
      Marlin/src/gcode/feature/camera/M240.cpp

+ 15
- 1
Marlin/Configuration_adv.h 查看文件

@@ -368,7 +368,7 @@
368 368
  * FAST_PWM_FAN_FREQUENCY [undefined by default]
369 369
  *   Set this to your desired frequency.
370 370
  *   If left undefined this defaults to F = F_CPU/(2*255*1)
371
- *   ie F = 31.4 Khz on 16 MHz microcontrollers or F = 39.2 KHz on 20 MHz microcontrollers
371
+ *   i.e., F = 31.4kHz on 16MHz microcontrollers or F = 39.2kHz on 20MHz microcontrollers.
372 372
  *   These defaults are the same as with the old FAST_PWM_FAN implementation - no migration is required
373 373
  *   NOTE: Setting very low frequencies (< 10 Hz) may result in unexpected timer behavior.
374 374
  *
@@ -2444,6 +2444,20 @@
2444 2444
 
2445 2445
   // Duration to hold the switch or keep CHDK_PIN high
2446 2446
   //#define PHOTO_SWITCH_MS   50 // (ms) (M240 D)
2447
+
2448
+  /**
2449
+   * PHOTO_PULSES_US may need adjustment depending on board and camera model.
2450
+   * Pin must be running at 48.4kHz.
2451
+   * Be sure to use a PHOTOGRAPH_PIN which can rise and fall quick enough.
2452
+   * (e.g., MKS SBase temp sensor pin was too slow, so used P1.23 on J8.)
2453
+   *
2454
+   *  Example pulse data for Nikon: https://bit.ly/2FKD0Aq
2455
+   *                     IR Wiring: https://git.io/JvJf7
2456
+   */
2457
+  //#define PHOTO_PULSES_US { 2000, 27850, 400, 1580, 400, 3580, 400 }  // (µs) Durations for each 48.4kHz oscillation
2458
+  #ifdef PHOTO_PULSES_US
2459
+    #define PHOTO_PULSE_DELAY_US 13 // (µs) Approximate duration of each HIGH and LOW pulse in the oscillation
2460
+  #endif
2447 2461
 #endif
2448 2462
 
2449 2463
 /**

+ 38
- 5
Marlin/src/gcode/feature/camera/M240.cpp 查看文件

@@ -62,11 +62,44 @@
62 62
 #endif
63 63
 
64 64
 #if PIN_EXISTS(PHOTOGRAPH)
65
-  constexpr uint8_t NUM_PULSES = 16;
66
-  constexpr float PULSE_LENGTH = 0.01524;
67
-  inline void set_photo_pin(const uint8_t state) { WRITE(PHOTOGRAPH_PIN, state); _delay_ms(PULSE_LENGTH); }
68
-  inline void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }
69
-  inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }
65
+
66
+  FORCE_INLINE void set_photo_pin(const uint8_t state) {
67
+    constexpr uint32_t pulse_length = (
68
+      #ifdef PHOTO_PULSES_US
69
+        PHOTO_PULSE_DELAY_US
70
+      #else
71
+        15                    // 15.24 from _delay_ms(0.01524)
72
+      #endif
73
+    );
74
+    WRITE(PHOTOGRAPH_PIN, state);
75
+    delayMicroseconds(pulse_length);
76
+  }
77
+
78
+  FORCE_INLINE void tweak_photo_pin() { set_photo_pin(HIGH); set_photo_pin(LOW); }
79
+
80
+  #ifdef PHOTO_PULSES_US
81
+
82
+    inline void pulse_photo_pin(const uint32_t duration, const uint8_t state) {
83
+      if (state) {
84
+        for (const uint32_t stop = micros() + duration; micros() < stop;)
85
+          tweak_photo_pin();
86
+      }
87
+      else
88
+        delayMicroseconds(duration);
89
+    }
90
+
91
+    inline void spin_photo_pin() {
92
+      static constexpr uint32_t sequence[] = PHOTO_PULSES_US;
93
+      for (uint8_t i = 0; i < COUNT(sequence); i++)
94
+        pulse_photo_pin(sequence[i], !(i & 1));
95
+    }
96
+
97
+  #else
98
+
99
+    constexpr uint8_t NUM_PULSES = 16;
100
+    inline void spin_photo_pin() { for (uint8_t i = NUM_PULSES; i--;) tweak_photo_pin(); }
101
+
102
+  #endif
70 103
 #endif
71 104
 
72 105
 /**

Loading…
取消
儲存