Subversion Repositories HomeAutomation

Rev

Rev 1425 | Rev 1977 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #ifndef ACT_HWPWM
  2. #define ACT_HWPWM
  3.  
  4. /*-----------------------------------------------------------------------------
  5.  * Includes
  6.  *---------------------------------------------------------------------------*/
  7. /* system files */
  8. #include <avr/io.h>
  9. #include <avr/interrupt.h>
  10. #include <stdio.h>
  11. /* lib files */
  12. #include <config.h>
  13. #include <bios.h>
  14. #include <drivers/can/stdcan.h>
  15. #include <drivers/timer/timer.h>
  16. #include <drivers/mcu/gpio.h>
  17.  
  18. //to use PCINT lib. uncomment the line below
  19. //#include <drivers/mcu/pcint.h>
  20.  
  21. void act_hwPWM_Init(void);
  22. void act_hwPWM_Process(void);
  23. void act_hwPWM_HandleMessage(StdCan_Msg_t *rxMsg);
  24. void act_hwPWM_List(uint8_t ModuleSequenceNumber);
  25.  
  26. #if act_hwPWM_CH1_COM>0 || act_hwPWM_CH2_COM>0
  27. #if act_hwPWM_CH1_CS != act_hwPWM_CH2_CS
  28. #error Cannot have different Clock Prescaler Select values, act_hwPWM_CH1_CS != act_hwPWM_CH2_CS
  29. #endif
  30. #if act_hwPWM_CH1_WGM != act_hwPWM_CH2_WGM
  31. #error Cannot have different Waveform Generation Mode values, act_hwPWM_CH1_WGM != act_hwPWM_CH2_WGM
  32. #endif
  33. #endif
  34.  
  35. #if act_hwPWM_CH3_COM>0 || act_hwPWM_CH4_COM>0
  36. #if act_hwPWM_CH3_CS != act_hwPWM_CH4_CS
  37. #error Cannot have different Clock Prescaler Select values, act_hwPWM_CH3_CS != act_hwPWM_CH4_CS
  38. #endif
  39. #if act_hwPWM_CH3_WGM != act_hwPWM_CH4_WGM
  40. #error Cannot have different Waveform Generation Mode values, act_hwPWM_CH3_WGM != act_hwPWM_CH4_WGM
  41. #endif
  42. #endif
  43.  
  44. #if act_hwPWM_CH1_WGM==0
  45. #define act_hwPWM_CH1_TOP 0xffffUL
  46. #define act_hwPWM_CH2_TOP 0xffffUL
  47. #endif
  48. #if act_hwPWM_CH1_WGM==1 || act_hwPWM_CH1_WGM==5
  49. #define act_hwPWM_CH1_TOP 0x00ffUL
  50. #define act_hwPWM_CH2_TOP 0x00ffUL
  51. #endif
  52. #if act_hwPWM_CH1_WGM==2 || act_hwPWM_CH1_WGM==6
  53. #define act_hwPWM_CH1_TOP 0x01ffUL
  54. #define act_hwPWM_CH2_TOP 0x01ffUL
  55. #endif
  56. #if act_hwPWM_CH1_WGM==3 || act_hwPWM_CH1_WGM==7
  57. #define act_hwPWM_CH1_TOP 0x03ffUL
  58. #define act_hwPWM_CH2_TOP 0x03ffUL
  59. #endif
  60. #define act_hwPWM_CH1_FACT (256UL*act_hwPWM_CH1_TOP)/10000UL
  61. #define act_hwPWM_CH2_FACT (256UL*act_hwPWM_CH2_TOP)/10000UL
  62.  
  63. #if act_hwPWM_CH1_WGM==4 || act_hwPWM_CH1_WGM>7
  64. #error Not supported Waveform Generation Mode on CH1 and CH2
  65. #endif
  66.  
  67.  
  68. #if act_hwPWM_CH3_WGM==0 || act_hwPWM_CH3_WGM==1 || act_hwPWM_CH3_WGM==3
  69. #define act_hwPWM_CH3_TOP 0xff
  70. #define act_hwPWM_CH4_TOP 0xff
  71. #endif
  72. #define act_hwPWM_CH3_FACT (256UL*act_hwPWM_CH3_TOP)/10000UL
  73. #define act_hwPWM_CH4_FACT (256UL*act_hwPWM_CH4_TOP)/10000UL
  74.  
  75. #if act_hwPWM_CH3_WGM==2 || act_hwPWM_CH3_WGM>3
  76. #error Not supported Waveform Generation Mode on CH3 and CH4
  77. #endif
  78.  
  79. #define OCR_1   OCR1B
  80. #define OCR_2   OCR1A
  81. #define OCR_3   OCR0A
  82. #define OCR_4   OCR0B
  83.  
  84. #define ACT_HWPWM_MAX_DIM               10000UL
  85. #define ACT_HWPWM_MIN_DIM               0
  86.  
  87. #define ACT_HWPWM_DEMO_STATE_NOT_RUNNING    0
  88. #define ACT_HWPWM_DEMO_STATE_DECREASE       1
  89. #define ACT_HWPWM_DEMO_STATE_INCREASE       2
  90. #define ACT_HWPWM_DEMO_STATE_GOBACK     3
  91.  
  92. #ifdef act_hwPWM_USEEEPROM
  93.     struct act_hwPWM_Data{
  94.         ///TODO: Define EEPROM variables needed by the module
  95.         uint16_t ch1;
  96.         uint16_t ch2;
  97.         uint16_t ch3;
  98.         uint16_t ch4;
  99.     }; 
  100. #endif
  101.  
  102. #endif // ACT_HWPWM
  103.