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.

240 lines
7.5 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. // #include "ozone_pwm_control.h"
  2. // #define TIMINT_TIM 1800000
  3. // #define INTERVAL_TIM 300000
  4. // #define CLCK 48
  5. // ozone_messages_t ozone_messages;
  6. // extern timing_message_t timing_message;
  7. // extern uint32_t g_duty[4]; // PWMd��ռ�ձ�
  8. // extern uint32_t g_frequency;
  9. // extern ozone_message_t ozone_message;
  10. // /**
  11. // * @brief ��ʱ����
  12. // * *
  13. // * @brief ���ü�Ъ����������
  14. // *
  15. // * @param ozone_interval_period
  16. // * @param ozone_interval_duty
  17. // */
  18. // void ozone_pwm_control_set_pwm2(uint32_t ozone_interval_period,uint32_t ozone_interval_duty){
  19. // }
  20. // /**
  21. // * @brief ���ó���PWM����ʱ����ģʽ��һֱ��������ʱ��������Ъ������������
  22. // *
  23. // * @param mode
  24. // */
  25. // void set_ozone_work_mode(OZONE_WOEK_MODE_T mode) {
  26. // if (mode == HAS_BEEN_WORKING) {
  27. // set_ozone_work_gears(ozone_messages.will_be_set_work_gears);
  28. // } else if (mode == TIMING_WORK) {
  29. // ozone_pwm_control_set_pwm_output_1(ozone_messages.ozone_timing_duty);
  30. // } else if (mode == TIMING_INTERVAL_WORK) {
  31. // ozone_pwm_control_set_pwm_output_2(ozone_messages.ozone_timing_duty,
  32. // ozone_messages.ozone_interval_duty);
  33. // } else if (mode == STOP_PWM_WORK) {
  34. // ozone_pwm_control_stop_pwm();
  35. // }
  36. // ozone_messages.now_ozone_woek_mode = mode;
  37. // }
  38. // /**
  39. // * @brief ���ó���PWM������λ
  40. // *
  41. // * @param mode
  42. // */
  43. // void set_ozone_work_gears(OZONE_WOEK_GEARS_T gears) {
  44. // if (gears == LOW_END) {
  45. // ozone_pwm_control_set_pwm_duty(ozone_messages.ozone_pwm_frequency,
  46. // ozone_messages.ozone_pwm_duty);
  47. // } else if (gears == MIDDLE_GRADE) {
  48. // ozone_pwm_control_set_pwm_duty(ozone_messages.ozone_pwm_frequency,
  49. // ozone_messages.ozone_pwm_duty);
  50. // } else if (gears == SLAP_UP) {
  51. // ozone_pwm_control_set_pwm_duty(ozone_messages.ozone_pwm_frequency,
  52. // ozone_messages.ozone_pwm_duty);
  53. // }
  54. // ozone_messages.now_ozone_woek_gears = gears;
  55. // }
  56. // //######################################################
  57. // double calculate_top(double target_frequency) {
  58. // int clck = 0;
  59. // int target_frequency_hz = 0;
  60. // int top = 0;
  61. // clck = CLCK * 1000 * 1000;
  62. // target_frequency_hz = (int)target_frequency * 1000;
  63. // // printf("target_frequency_hz%d\n", target_frequency_hz);
  64. // top = clck / target_frequency_hz;
  65. // // printf("top%d\t\n", top);
  66. // return top;
  67. // }
  68. // double calculate_MAT2(double top, double duty) {
  69. // double percentage_duty = 0;
  70. // double Mat2 = 0;
  71. // percentage_duty = duty / 100;
  72. // Mat2 = top * percentage_duty;
  73. // return Mat2;
  74. // }
  75. // void ozone_pwm_control_set_pwm_duty(uint32_t set_frequency, uint32_t set_duty) {
  76. // double top = 0;
  77. // double Mat2 = 0;
  78. // if (set_frequency > CLCK * 1000) {
  79. // printf("out of range\n");
  80. // return;
  81. // }
  82. // top = calculate_top(set_frequency); //������Ҫ��Ƶ�ʼ�����TOP���Զ���װ��ֵ��
  83. // if (top == 0) {
  84. // return;
  85. // }
  86. // Mat2 = calculate_MAT2(top, set_duty);
  87. // // printf("top:\t%2.lf\n", top);
  88. // // printf("MAT2:\t%2.lf\n", Mat2);
  89. // // printf("MAT3:\t%2.lf\n", top);
  90. // T16Nx_Disable(T16N0);
  91. // t16n0_1_init();
  92. // T16Nx_SetMAT2(T16N0, Mat2);
  93. // T16Nx_SetMAT3(T16N0, top);
  94. // T16Nx_SetTOP1(T16N0, top);
  95. // }
  96. // //######################################################
  97. // /**
  98. // * @brief �ж�ʱ���޼�Ъ
  99. // *
  100. // * @param pwm_timing_duty
  101. // */
  102. // void ozone_pwm_control_set_pwm_output_1(uint32_t pwm_timing_duty) {}
  103. // /**
  104. // * @brief �ж�ʱ���м�Ъ
  105. // *
  106. // * @param pwm_duty
  107. // * @param pwm_interval_duty
  108. // */
  109. // void ozone_pwm_control_set_pwm_output_2(uint32_t pwm_timing_duty,
  110. // uint32_t pwm_interval_duty) {}
  111. // /**
  112. // * @brief ֹͣpwm����
  113. // *
  114. // */
  115. // void ozone_pwm_control_stop_pwm(void) { stop_ozone_work(); }
  116. // /**
  117. // * @brief ��ʱʱ�䵽���Ժ��ػ�
  118. // *
  119. // */
  120. // void try_shutdown(void) {
  121. // if (port_haspassedms(ozone_message.count_down_begin_sys_time) >= TIMINT_TIM) {
  122. // ozone_message.count_down_begin_sys_time = get_sys_ticket();
  123. // if (ozone_message.timing_rank == 1) { //��ʱʱ�䵽
  124. // set_timing_light_mode(CLOSE_ALL_LED);
  125. // printf("time over\r\n");
  126. // } else { //��ʱʱ����30min,ÿ��30min�ر�һ��led
  127. // printf("time minus 30min\r\n");
  128. // set_timing_light_mode(timing_message.now_timing_mode - 1);
  129. // }
  130. // }
  131. // }
  132. // /**
  133. // * @brief �ر�pwm����
  134. // *
  135. // */
  136. // void stop_ozone_work(void) {
  137. // set_ozone_work_mode(STOP_PWM_WORK); //�ر�PWM����
  138. // port_fan_set(false); //���Ƚ�������
  139. // close_all_light(); //�ر�rgb���ر�led0~led3
  140. // }
  141. #include "ozone_pwm_control.h"
  142. #define INTERVAL_TICK 30000
  143. uint32_t s_hardware_frequency; //��λms���������ڵ�PWMƵ��
  144. uint32_t s_hardware_duty; //��λms���������ڵ�PWMռ�ձ�
  145. uint32_t s_large_period; //��λms���������ڵĶ�ʱ����
  146. uint32_t s_large_duty = 100; //��λms���������ڵĶ�ʱռ�ձ�
  147. uint32_t begin_ticket;
  148. bool ozone_pwm_control_enable_falg = false;
  149. void HOOK_pwm_module_set_pwm_duty(uint32_t frequency, uint32_t duty);
  150. void HOOK_pwm_stop(void);
  151. bool HOOK_pwm_is_enable(void);
  152. void update_begin_ticket(void) {
  153. begin_ticket = get_sys_ticket(); //���´����ڵĿ�ʼʱ�䣨��Ъʱ���Ŀ�ʼ��ʱ�䣩
  154. }
  155. void ozone_pwm_control_enable(void) { ozone_pwm_control_enable_falg = true; }
  156. void ozone_pwm_control_disable(void) {
  157. ozone_pwm_control_enable_falg = false;
  158. }
  159. bool ozone_pwm_control_is_enable(void) { return ozone_pwm_control_enable_falg; }
  160. /**
  161. * @brief һֱʱʱռձΪ100
  162. * Ъʱ300000
  163. * @param freq
  164. * @param duty
  165. */
  166. void ozone_pwm_control_module_set_pwm_output_1(uint32_t large_period, uint8_t large_duty) {
  167. s_large_period = large_period;
  168. s_large_duty = large_duty;
  169. update_begin_ticket();
  170. ozone_pwm_control_enable();
  171. if (large_duty == 100) {
  172. ozone_pwm_control_disable();
  173. }
  174. }
  175. /**
  176. * @brief ʱPWM
  177. *
  178. * @param hardware_period pwmƵ
  179. * @param hardware_duty pwmռձ
  180. * @param large_period ʱ
  181. * @param large_duty ʱռձ
  182. */
  183. void ozone_pwm_control_module_set_pwm_output_2(uint32_t hardware_period, uint8_t hardware_duty, uint32_t large_period,
  184. uint8_t large_duty) {
  185. s_hardware_frequency = hardware_period;
  186. s_hardware_duty = hardware_duty;
  187. s_large_period = large_period;
  188. s_large_duty = large_duty;
  189. update_begin_ticket();
  190. ozone_pwm_control_enable();
  191. HOOK_pwm_module_set_pwm_duty(hardware_period, hardware_duty);
  192. if (large_duty == 100) {
  193. ozone_pwm_control_disable();
  194. }
  195. }
  196. void ozone_pwm_control_module_stop_pwm(void) {}
  197. void ozone_pwm_control_module_loop(void) {
  198. static uint32_t hardware_frequency;
  199. static uint32_t hardware_duty;
  200. if (ozone_pwm_control_is_enable() == false) { //û��ʹ��ֱ���˳�
  201. HOOK_pwm_stop();
  202. return;
  203. }
  204. if (port_haspassedms(begin_ticket) % s_large_period <= s_large_period * s_large_duty / 100) {
  205. if (!HOOK_pwm_is_enable()) {
  206. printf("set work\r\n");
  207. HOOK_pwm_module_set_pwm_duty(hardware_frequency, hardware_duty);
  208. }
  209. } else {
  210. if (HOOK_pwm_is_enable()) {
  211. printf("set rest\r\n");
  212. hardware_frequency = s_hardware_frequency; //���ر�֮ǰ��Ƶ�ʽ��б���
  213. hardware_duty = s_hardware_duty; //���ر�֮ǰ��ռ�ձȽ��б���
  214. HOOK_pwm_stop();
  215. }
  216. }
  217. }