dimmer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*********************************************************************
  2. *
  3. * 8 channels AC dimmer library for Fraise pic18f device
  4. *
  5. *********************************************************************
  6. * Author Date Comment
  7. *********************************************************************
  8. * Antoine Rousseau apr 2016 Original.
  9. ********************************************************************/
  10. /*
  11. # This program is free software; you can redistribute it and/or
  12. # modify it under the terms of the GNU General Public License
  13. # as published by the Free Software Foundation; either version 2
  14. # of the License, or (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23. # MA 02110-1301, USA.
  24. */
  25. #ifndef _DIMMER__H_
  26. #define _DIMMER__H_
  27. /** @file */
  28. /** @defgroup dimmer Dimmer module
  29. * 8 channels AC dimmer
  30. * Example :
  31. *
  32. * main.c
  33. * \include dimmer/examples/example1/main.c
  34. * config.h
  35. * \include dimmer/examples/example1/config.h
  36. * @{
  37. */
  38. #include <fruit.h>
  39. /** \name Settings to put in config.h
  40. You must define the pin used to trig the interrupt (sensing the AC zero-crossing):
  41. ~~~~
  42. #define DIMMER_INTPIN K9 (replace K9 by the pin used by your dimmer)
  43. ~~~~
  44. The following parameters can be overloaded:
  45. */
  46. //@{
  47. #ifndef DIMMER_INTPIN
  48. #error you must define DIMMER_INTPIN before calling dimmer.h
  49. #endif
  50. #ifndef DIMMER_INTEDGE
  51. /** @brief Edge of the interrupt (0:falling edge ; 1:rising edge) ; default: 1(rising edge). */
  52. #define DIMMER_INTEDGE 1
  53. #endif
  54. #ifndef DIMMER_TIMER
  55. /** @brief Timer to be used by the dimmer module (only 1, 3 or 5 ; default: 5). */
  56. #define DIMMER_TIMER 5
  57. #endif
  58. #ifndef DIMMER_K0
  59. #define DIMMER_K0 KZ2 /**< @brief output pin for channel 0.*/
  60. #endif
  61. #ifndef DIMMER_K1
  62. #define DIMMER_K1 KZ2 /**< @brief output pin for channel 1.*/
  63. #endif
  64. #ifndef DIMMER_K2
  65. #define DIMMER_K2 KZ2 /**< @brief output pin for channel 2.*/
  66. #endif
  67. #ifndef DIMMER_K3
  68. #define DIMMER_K3 KZ2 /**< @brief output pin for channel 3.*/
  69. #endif
  70. #ifndef DIMMER_K4
  71. #define DIMMER_K4 KZ2 /**< @brief output pin for channel 4.*/
  72. #endif
  73. #ifndef DIMMER_K5
  74. #define DIMMER_K5 KZ2 /**< @brief output pin for channel 5.*/
  75. #endif
  76. #ifndef DIMMER_K6
  77. #define DIMMER_K6 KZ2 /**< @brief output pin for channel 6.*/
  78. #endif
  79. #ifndef DIMMER_K7
  80. #define DIMMER_K7 KZ2 /**< @brief output pin for channel 7.*/
  81. #endif
  82. #ifndef DIMMER_TMIN
  83. #define DIMMER_TMIN 9000UL
  84. #endif
  85. #ifndef DIMMER_INTPRI
  86. #define DIMMER_INTPRI 1
  87. #endif
  88. //@}
  89. /** \name Initialization
  90. */
  91. //@{
  92. /** @brief Init the module in **setup()** */
  93. void dimmerInit(void);
  94. //@}
  95. /** \name Main loop functions
  96. */
  97. //@{
  98. void dimmerService(void); ///< @brief Module service routine, to be called by the main **loop()**.
  99. //@}
  100. /** \name Utilities
  101. */
  102. //@{
  103. /** @brief Set the value of a dimmer channel.
  104. @param num Dimmer channel (0 to 7)
  105. @param val New 16 bit value for this channel, between 0 and 65535
  106. */
  107. void dimmerSet(unsigned char num,unsigned int val);
  108. //@}
  109. /** \name Interrupt routine
  110. */
  111. //@{
  112. void dimmerHighInterrupt(void); ///< @brief Module high interrupt routine, must be called by the **highInterrupts()** user defined function.
  113. //@}
  114. //@{
  115. void dimmerLowInterrupt(void); ///< @brief Module low interrupt routine, must be called by the **lowInterrupts()** user defined function.
  116. //@}
  117. /** \name Receive function
  118. */
  119. //@{
  120. /** @brief Module receive function, to be called by the **fraiseReceive()** user defined function.
  121. *
  122. The first byte of the message represents the channel (0-7), the 2 next bytes are the 16 bit new position value.
  123. If the first byte is 8 then the next char sets the AC frequency : 0=50Hz, 1=60Hz
  124. */
  125. void dimmerReceive();
  126. //@}
  127. void dimmerPrintDebug();
  128. /** @}
  129. */
  130. #endif // DIMMER