My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

servo_private.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * servo_private.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
  24. * Copyright (c) 2009 Michael Margolis. All right reserved.
  25. *
  26. * This library is free software; you can redistribute it and/or
  27. * modify it under the terms of the GNU Lesser General Public
  28. * License as published by the Free Software Foundation; either
  29. * version 2.1 of the License, or (at your option) any later version.
  30. *
  31. * This library is distributed in the hope that it will be useful,
  32. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  34. * Lesser General Public License for more details.
  35. *
  36. * You should have received a copy of the GNU Lesser General Public
  37. * License along with this library; if not, write to the Free Software
  38. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  39. */
  40. #ifndef SERVO_PRIVATE_H
  41. #define SERVO_PRIVATE_H
  42. #include <stdint.h>
  43. // Architecture specific include
  44. #ifdef __AVR__
  45. #include "HAL_AVR/ServoTimers.h"
  46. #elif defined(ARDUINO_ARCH_SAM)
  47. #include "HAL_DUE/ServoTimers.h"
  48. #else
  49. #error "This library only supports boards with an AVR or SAM3X processor."
  50. #endif
  51. // Macros
  52. #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
  53. #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
  54. #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
  55. #define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds
  56. #define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer
  57. #define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
  58. #define INVALID_SERVO 255 // flag indicating an invalid servo index
  59. //
  60. #define usToTicks(_us) (( clockCyclesPerMicrosecond()* _us) / PRESCALER) // converts microseconds to tick (PRESCALER depends on architecture)
  61. #define ticksToUs(_ticks) (( (unsigned)_ticks * PRESCALER)/ clockCyclesPerMicrosecond() ) // converts from ticks back to microseconds
  62. //#define NBR_TIMERS ((MAX_SERVOS) / (SERVOS_PER_TIMER))
  63. // convenience macros
  64. #define SERVO_INDEX_TO_TIMER(_servo_nbr) ((timer16_Sequence_t)(_servo_nbr / (SERVOS_PER_TIMER))) // returns the timer controlling this servo
  65. #define SERVO_INDEX_TO_CHANNEL(_servo_nbr) (_servo_nbr % (SERVOS_PER_TIMER)) // returns the index of the servo on this timer
  66. #define SERVO_INDEX(_timer,_channel) ((_timer*(SERVOS_PER_TIMER)) + _channel) // macro to access servo index by timer and channel
  67. #define SERVO(_timer,_channel) (servo_info[SERVO_INDEX(_timer,_channel)]) // macro to access servo class by timer and channel
  68. // Types
  69. typedef struct {
  70. uint8_t nbr : 6 ; // a pin number from 0 to 63
  71. uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false
  72. } ServoPin_t;
  73. typedef struct {
  74. ServoPin_t Pin;
  75. unsigned int ticks;
  76. } ServoInfo_t;
  77. // Global variables
  78. extern uint8_t ServoCount;
  79. extern ServoInfo_t servo_info[MAX_SERVOS];
  80. // Public functions
  81. extern void initISR(timer16_Sequence_t timer);
  82. extern void finISR(timer16_Sequence_t timer);
  83. #endif // SERVO_PRIVATE_H