CH57x_pwm.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef __CH57x_PWM_H__
  2. #define __CH57x_PWM_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "CH579SFR.h"
  7. #include "core_cm0.h"
  8. /**
  9. * @brief channel of PWM define
  10. */
  11. #define CH_PWM4 0x01 // PWM4 通道
  12. #define CH_PWM5 0x02 // PWM5 通道
  13. #define CH_PWM6 0x04 // PWM6 通道
  14. #define CH_PWM7 0x08 // PWM7 通道
  15. #define CH_PWM8 0x10 // PWM8 通道
  16. #define CH_PWM9 0x20 // PWM9 通道
  17. #define CH_PWM10 0x40 // PWM10 通道
  18. #define CH_PWM11 0x80 // PWM11 通道
  19. /**
  20. * @brief channel of PWM define
  21. */
  22. typedef enum
  23. {
  24. High_Level = 0, // 默认低电平,高电平有效
  25. Low_Level, // 默认高电平,低电平有效
  26. }PWMX_PolarTypeDef;
  27. /**
  28. * @brief Configuration PWM4_11 Cycle size
  29. */
  30. typedef enum
  31. {
  32. PWMX_Cycle_256 = 0, // 256 个PWMX周期
  33. PWMX_Cycle_255, // 255 个PWMX周期
  34. PWMX_Cycle_128, // 128 个PWMX周期
  35. PWMX_Cycle_127, // 127 个PWMX周期
  36. PWMX_Cycle_64, // 64 个PWMX周期
  37. PWMX_Cycle_63, // 63 个PWMX周期
  38. PWMX_Cycle_32, // 32 个PWMX周期
  39. PWMX_Cycle_31, // 31 个PWMX周期
  40. }PWMX_CycleTypeDef;
  41. #define PWMX_CLKCfg( d ) (R8_PWM_CLOCK_DIV=d) /* PWM4-PWM11 通道基准时钟配置,= d*Tsys */
  42. void PWMX_CycleCfg( PWMX_CycleTypeDef cyc ); /* PWM4-PWM11 通道输出波形周期配置 */
  43. #define PWM4_ActDataWidth( d ) (R8_PWM4_DATA = d) /* PWM4 有效数据脉宽 */
  44. #define PWM5_ActDataWidth( d ) (R8_PWM5_DATA = d) /* PWM5 有效数据脉宽 */
  45. #define PWM6_ActDataWidth( d ) (R8_PWM6_DATA = d) /* PWM6 有效数据脉宽 */
  46. #define PWM7_ActDataWidth( d ) (R8_PWM7_DATA = d) /* PWM7 有效数据脉宽 */
  47. #define PWM8_ActDataWidth( d ) (R8_PWM8_DATA = d) /* PWM8 有效数据脉宽 */
  48. #define PWM9_ActDataWidth( d ) (R8_PWM9_DATA = d) /* PWM9 有效数据脉宽 */
  49. #define PWM10_ActDataWidth( d ) (R8_PWM10_DATA = d) /* PWM10 有效数据脉宽 */
  50. #define PWM11_ActDataWidth( d ) (R8_PWM11_DATA = d) /* PWM11 有效数据脉宽 */
  51. // 占空比 = 数据有效脉宽/波形周期
  52. void PWMX_ACTOUT( UINT8 ch, UINT8 da, PWMX_PolarTypeDef pr, UINT8 s); /* PWM4-PWM11通道输出波形配置 */
  53. void PWMX_AlterOutCfg( UINT8 ch, UINT8 s); /* PWM 交替输出模式配置 */
  54. #ifdef __cplusplus
  55. }
  56. #endif
  57. #endif // __CH57x_PWM_H__