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.
156 lines
4.8 KiB
156 lines
4.8 KiB
// #include "ozone_pwm_control.h"
|
|
// #define TIMINT_TIM 1800000
|
|
// #define INTERVAL_TIM 300000
|
|
|
|
// #define CLCK 48
|
|
|
|
// ozone_messages_t ozone_messages;
|
|
// extern timing_message_t timing_message;
|
|
|
|
// extern uint32_t g_duty[4]; // PWMd的占空比
|
|
// extern uint32_t g_frequency;
|
|
// extern ozone_message_t ozone_message;
|
|
|
|
// /**
|
|
// * @brief 定时周期
|
|
// * *
|
|
|
|
// * @brief 设置间歇工作的周期
|
|
// *
|
|
// * @param ozone_interval_period
|
|
// * @param ozone_interval_duty
|
|
// */
|
|
// void ozone_pwm_control_set_pwm2(uint32_t ozone_interval_period,uint32_t ozone_interval_duty){
|
|
|
|
// }
|
|
|
|
// /**
|
|
// * @brief 设置臭氧PWM工作时间的模式,一直工作,定时工作,间歇工作,不工作
|
|
// *
|
|
// * @param mode
|
|
// */
|
|
// void set_ozone_work_mode(OZONE_WOEK_MODE_T mode) {
|
|
// if (mode == HAS_BEEN_WORKING) {
|
|
// set_ozone_work_gears(ozone_messages.will_be_set_work_gears);
|
|
// } else if (mode == TIMING_WORK) {
|
|
// ozone_pwm_control_set_pwm_output_1(ozone_messages.ozone_timing_duty);
|
|
// } else if (mode == TIMING_INTERVAL_WORK) {
|
|
// ozone_pwm_control_set_pwm_output_2(ozone_messages.ozone_timing_duty,
|
|
// ozone_messages.ozone_interval_duty);
|
|
// } else if (mode == STOP_PWM_WORK) {
|
|
// ozone_pwm_control_stop_pwm();
|
|
// }
|
|
// ozone_messages.now_ozone_woek_mode = mode;
|
|
// }
|
|
|
|
// /**
|
|
// * @brief 设置臭氧PWM工作档位
|
|
// *
|
|
// * @param mode
|
|
// */
|
|
// void set_ozone_work_gears(OZONE_WOEK_GEARS_T gears) {
|
|
// if (gears == LOW_END) {
|
|
// ozone_pwm_control_set_pwm_duty(ozone_messages.ozone_pwm_frequency,
|
|
// ozone_messages.ozone_pwm_duty);
|
|
// } else if (gears == MIDDLE_GRADE) {
|
|
// ozone_pwm_control_set_pwm_duty(ozone_messages.ozone_pwm_frequency,
|
|
// ozone_messages.ozone_pwm_duty);
|
|
// } else if (gears == SLAP_UP) {
|
|
// ozone_pwm_control_set_pwm_duty(ozone_messages.ozone_pwm_frequency,
|
|
// ozone_messages.ozone_pwm_duty);
|
|
// }
|
|
// ozone_messages.now_ozone_woek_gears = gears;
|
|
// }
|
|
// //######################################################
|
|
// double calculate_top(double target_frequency) {
|
|
// int clck = 0;
|
|
// int target_frequency_hz = 0;
|
|
// int top = 0;
|
|
// clck = CLCK * 1000 * 1000;
|
|
// target_frequency_hz = (int)target_frequency * 1000;
|
|
// // printf("target_frequency_hz%d\n", target_frequency_hz);
|
|
// top = clck / target_frequency_hz;
|
|
// // printf("top%d\t\n", top);
|
|
// return top;
|
|
// }
|
|
// double calculate_MAT2(double top, double duty) {
|
|
// double percentage_duty = 0;
|
|
// double Mat2 = 0;
|
|
// percentage_duty = duty / 100;
|
|
// Mat2 = top * percentage_duty;
|
|
// return Mat2;
|
|
// }
|
|
|
|
// void ozone_pwm_control_set_pwm_duty(uint32_t set_frequency, uint32_t set_duty) {
|
|
// double top = 0;
|
|
// double Mat2 = 0;
|
|
// if (set_frequency > CLCK * 1000) {
|
|
// printf("out of range\n");
|
|
// return;
|
|
// }
|
|
// top = calculate_top(set_frequency); //根据需要的频率计算出TOP(自动重装载值)
|
|
// if (top == 0) {
|
|
// return;
|
|
// }
|
|
// Mat2 = calculate_MAT2(top, set_duty);
|
|
// // printf("top:\t%2.lf\n", top);
|
|
// // printf("MAT2:\t%2.lf\n", Mat2);
|
|
// // printf("MAT3:\t%2.lf\n", top);
|
|
// T16Nx_Disable(T16N0);
|
|
// t16n0_1_init();
|
|
// T16Nx_SetMAT2(T16N0, Mat2);
|
|
// T16Nx_SetMAT3(T16N0, top);
|
|
// T16Nx_SetTOP1(T16N0, top);
|
|
// }
|
|
// //######################################################
|
|
|
|
// /**
|
|
// * @brief 有定时,无间歇
|
|
// *
|
|
// * @param pwm_timing_duty
|
|
// */
|
|
// void ozone_pwm_control_set_pwm_output_1(uint32_t pwm_timing_duty) {}
|
|
|
|
// /**
|
|
// * @brief 有定时,有间歇
|
|
// *
|
|
// * @param pwm_duty
|
|
// * @param pwm_interval_duty
|
|
// */
|
|
// void ozone_pwm_control_set_pwm_output_2(uint32_t pwm_timing_duty,
|
|
// uint32_t pwm_interval_duty) {}
|
|
|
|
// /**
|
|
// * @brief 停止pwm输出
|
|
// *
|
|
// */
|
|
// void ozone_pwm_control_stop_pwm(void) { stop_ozone_work(); }
|
|
|
|
// /**
|
|
// * @brief 定时时间到了以后关机
|
|
// *
|
|
// */
|
|
// void try_shutdown(void) {
|
|
// if (port_haspassedms(ozone_message.count_down_begin_sys_time) >= TIMINT_TIM) {
|
|
// ozone_message.count_down_begin_sys_time = get_sys_ticket();
|
|
// if (ozone_message.timing_rank == 1) { //定时时间到
|
|
// set_timing_light_mode(CLOSE_ALL_LED);
|
|
// printf("time over\r\n");
|
|
// } else { //定时时间减30min,每减30min关闭一个led
|
|
// printf("time minus 30min\r\n");
|
|
// set_timing_light_mode(timing_message.now_timing_mode - 1);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// /**
|
|
// * @brief 关闭pwm输出
|
|
// *
|
|
// */
|
|
// void stop_ozone_work(void) {
|
|
// set_ozone_work_mode(STOP_PWM_WORK); //关闭PWM输出
|
|
// port_fan_set(false); //风扇结束工作
|
|
// close_all_light(); //关闭rgb,关闭led0~led3
|
|
// }
|
|
|
|
|