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
240 lines
7.5 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
|
|
// }
|
|
#include "ozone_pwm_control.h"
|
|
|
|
#define INTERVAL_TICK 30000
|
|
|
|
uint32_t s_hardware_frequency; //单位ms,保存现在的PWM频率
|
|
uint32_t s_hardware_duty; //单位ms,保存现在的PWM占空比
|
|
uint32_t s_large_period; //单位ms,保存现在的定时周期
|
|
uint32_t s_large_duty = 100; //单位ms,保存现在的定时占空比
|
|
|
|
uint32_t begin_ticket;
|
|
|
|
bool ozone_pwm_control_enable_falg = false;
|
|
void HOOK_pwm_module_set_pwm_duty(uint32_t frequency, uint32_t duty);
|
|
void HOOK_pwm_stop(void);
|
|
bool HOOK_pwm_is_enable(void);
|
|
|
|
void update_begin_ticket(void) {
|
|
begin_ticket = get_sys_ticket(); //更新大周期的开始时间(间歇时间的开始的时间)
|
|
}
|
|
|
|
void ozone_pwm_control_enable(void) { ozone_pwm_control_enable_falg = true; }
|
|
void ozone_pwm_control_disable(void) {
|
|
ozone_pwm_control_enable_falg = false;
|
|
}
|
|
bool ozone_pwm_control_is_enable(void) { return ozone_pwm_control_enable_falg; }
|
|
|
|
/**
|
|
* @brief 一直工作的时间定时的占空比为100,
|
|
* 间歇时间设置300000
|
|
* @param freq
|
|
* @param duty
|
|
*/
|
|
void ozone_pwm_control_module_set_pwm_output_1(uint32_t large_period, uint8_t large_duty) {
|
|
s_large_period = large_period;
|
|
s_large_duty = large_duty;
|
|
update_begin_ticket();
|
|
ozone_pwm_control_enable();
|
|
if (large_duty == 100) {
|
|
ozone_pwm_control_disable();
|
|
}
|
|
}
|
|
/**
|
|
* @brief 定时和PWM
|
|
*
|
|
* @param hardware_period pwm频率
|
|
* @param hardware_duty pwm占空比
|
|
* @param large_period 定时周期
|
|
* @param large_duty 定时占空比
|
|
*/
|
|
void ozone_pwm_control_module_set_pwm_output_2(uint32_t hardware_period, uint8_t hardware_duty, uint32_t large_period,
|
|
uint8_t large_duty) {
|
|
s_hardware_frequency = hardware_period;
|
|
s_hardware_duty = hardware_duty;
|
|
s_large_period = large_period;
|
|
s_large_duty = large_duty;
|
|
update_begin_ticket();
|
|
ozone_pwm_control_enable();
|
|
HOOK_pwm_module_set_pwm_duty(hardware_period, hardware_duty);
|
|
if (large_duty == 100) {
|
|
ozone_pwm_control_disable();
|
|
}
|
|
}
|
|
|
|
void ozone_pwm_control_module_stop_pwm(void) {}
|
|
|
|
void ozone_pwm_control_module_loop(void) {
|
|
static uint32_t hardware_frequency;
|
|
static uint32_t hardware_duty;
|
|
if (ozone_pwm_control_is_enable() == false) { //没有使能直接退出
|
|
HOOK_pwm_stop();
|
|
return;
|
|
}
|
|
if (port_haspassedms(begin_ticket) % s_large_period <= s_large_period * s_large_duty / 100) {
|
|
if (!HOOK_pwm_is_enable()) {
|
|
printf("set work\r\n");
|
|
HOOK_pwm_module_set_pwm_duty(hardware_frequency, hardware_duty);
|
|
}
|
|
} else {
|
|
if (HOOK_pwm_is_enable()) {
|
|
printf("set rest\r\n");
|
|
hardware_frequency = s_hardware_frequency; //将关闭之前的频率进行保存
|
|
hardware_duty = s_hardware_duty; //将关闭之前的占空比进行保存
|
|
HOOK_pwm_stop();
|
|
}
|
|
}
|
|
}
|