servo.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*********************************************************************
  2. *
  3. * Servo library for Fraise pic18f device
  4. * Uses TIMER5 !
  5. *
  6. *********************************************************************
  7. * Author Date Comment
  8. *********************************************************************
  9. * Antoine Rousseau jan 2013 Original.
  10. ********************************************************************/
  11. /*
  12. # This program is free software; you can redistribute it and/or
  13. # modify it under the terms of the GNU General Public License
  14. # as published by the Free Software Foundation; either version 2
  15. # of the License, or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. # You should have received a copy of the GNU General Public License
  22. # along with this program; if not, write to the Free Software
  23. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  24. # MA 02110-1301, USA.
  25. */
  26. #ifndef _Servo__H_
  27. #define _Servo__H_
  28. /** @file */
  29. /** @defgroup servo Servo module
  30. * Automates the use of maximum 8 RC servomotors.
  31. Servo module uses timer 5.
  32. * Example :
  33. * \include servo/examples/example1/main.c
  34. * @{
  35. */
  36. #include <fruit.h>
  37. /** \name Initialization
  38. */
  39. //@{
  40. /** @brief Init the module in **setup()** */
  41. void servoInit(void);
  42. /** @brief Select a pin for a servo channel.
  43. @param num Servomotor channel (0 to 7)
  44. @param conn Symbol of the pin (example : K1 for connector 1)
  45. */
  46. #define servoSelect(num,conn) do { \
  47. digitalClear(conn);\
  48. pinModeDigitalOut(conn);\
  49. CALL_FUN3(SERVO_SELECT_,num,KPORT(conn),KBIT(conn));\
  50. } while(0)
  51. //@}
  52. /** \name Main loop functions
  53. */
  54. //@{
  55. void servoService(void); ///< @brief Module service routine, to be called by the main **loop()**.
  56. //@}
  57. /** \name Utilities
  58. */
  59. //@{
  60. /** @brief Set position of a servomotor.
  61. @param num Servomotor channel (0 to 7)
  62. @param val New position of this servo, in 8/FOSC steps ; e.g for Versa1, FOSC=64MHz, so servo steps are 1/8 us : 8000 corresponds to 1 ms position.
  63. */
  64. void servoSet(unsigned char num,unsigned int val);
  65. //@}
  66. /** \name Interrupt routine
  67. */
  68. //@{
  69. void servoHighInterrupt(void); ///< @brief Module interrupt routine, must be called by the **highInterrupts()** user defined function.
  70. //@}
  71. /** \name Receive function
  72. */
  73. //@{
  74. /** @brief Module receive function, to be called by the **fraiseReceive()** user defined function.
  75. *
  76. The first byte of the message represents the channel (0-7), the 2 next bytes are the 16 bit new position value.
  77. If the first byte equals to 254, then the message is for reading a channel position ; the next byte then is the actual channel, and the module sends to the master the current position of this channel.
  78. */
  79. void servoReceive();
  80. //@}
  81. void servoSetPort(unsigned char num,unsigned char *port,unsigned char mask);
  82. #define SERVO_SELECT_(num,connport,connbit) servoSetPort(num,&LAT##connport,1<<connbit)
  83. /** @}
  84. */
  85. #endif //