Browse Source

update

master
zhaohe 3 years ago
parent
commit
0b02f66e58
  1. 160
      APP/adc.c
  2. 14
      APP/adc.h
  3. 82
      APP/current_through_mos_capturer.c
  4. 3
      APP/light.c
  5. 42
      APP/light.h
  6. 144
      APP/main.c
  7. 6
      APP/main.h
  8. 2
      APP/ozone_pwm_control.c
  9. 2
      APP/ozone_pwm_control.h
  10. 330
      APP/port.c
  11. 16
      APP/port.h
  12. 2
      APP/pwm.c
  13. 2
      APP/systick.c
  14. 166
      README.md
  15. 1212
      project_ozone/Listings/project_o.map
  16. 42
      project_ozone/project_o.uvgui.zel

160
APP/adc.c

@ -1,160 +0,0 @@
#include "adc.h"
static float prv_adc_get_value();
// uint16_t meanvalue;
ADC_InitStruType x;
GPIO_InitSettingType y;
bool adccapture_error = false;
static void prv_adc_pa2_init() {
y.Signal = GPIO_Pin_Signal_Analog; //
y.Dir = GPIO_Direction_Input; //
y.Func = GPIO_Reuse_Func0;
// x.CHS设置adc采集的通道每个引脚对应一个通道
GPIO_Init(GPIO_Pin_A2, &y);
//Tadclk=1/(PCLK/4)0.083us
x.CLKS = ADC_CLKS_PCLK;
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */
//*3.3/4096=
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,这个是设置adc具体是要哪个电压来做参考adc的参考电压为多少 */
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */
x.CHS = ADC_CHS_AIN8;
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */
//st*2+1(Tadclk)=1.743us
x.ST = 10; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
static void prv_adc_pb8_init() {
y.Signal = GPIO_Pin_Signal_Analog; //
y.Dir = GPIO_Direction_Input; //
y.Func = GPIO_Reuse_Func0;
// x.CHS设置adc采集的通道每个引脚对应一个通道
GPIO_Init(GPIO_Pin_B8, &y);
//Tadclk=1/(PCLK/4)0.083us
x.CLKS = ADC_CLKS_PCLK;
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */
//*3.3/4096=
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,这个是设置adc具体是要哪个电压来做参考adc的参考电压为多少 */
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */
x.CHS = ADC_CHS_AIN3;
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */
//st*2+1(Tadclk)=1.743us
x.ST = 10; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
static void prv_adc_pb9_init() {
y.Signal = GPIO_Pin_Signal_Analog; //
y.Dir = GPIO_Direction_Input; //
y.Func = GPIO_Reuse_Func0;
// x.CHS设置adc采集的通道每个引脚对应一个通道
GPIO_Init(GPIO_Pin_B9, &y);
//Tadclk=1/(PCLK/32)
x.CLKS = ADC_CLKS_PCLK;
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */
//*3.3/4096=
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,这个是设置adc具体是要哪个电压来做参考adc的参考电压为多少 */
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */
x.CHS = ADC_CHS_AIN4;
// x.CHS = ADC_CHS_AIN8;
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */
//st*2+1(Tadclk)=1.743us
x.ST = 10; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
static float prv_adc_get_value() {
ErrorStatus status = ADC_SoftStart();
adccapture_error = false;
if (status != SUCCESS) {
adccapture_error = true;
return 0;
}
uint32_t inticket = get_sys_ticket();
while (ADC_GetConvStatus() != RESET) {
if (port_haspassedms(inticket) > 10) {
// printf("prv_adc_get_value ch:%d\n", x.CHS);
// printf("fail\n", x.CHS);
adccapture_error = true;
return 0;
}
}
// printf("success %d\n", port_haspassedms(inticket));
uint16_t adcv = ADC_GetConvValue();
ADC_SoftStop();
// printf("success\n", x.CHS);
// printf("%d\r\n", adcv);
return adcv * 3.3 / 4096;
}
static float prv_adc_get_value_average(int average) {
if (average == 0) {
average = 1;
}
float value = 0;
for (size_t i = 0; i < average; i++) {
value += prv_adc_get_value();
}
return value / average;
}
float adc_get_value_pa2(void) {
prv_adc_pa2_init();
return prv_adc_get_value_average(AVERAGE_TABLE_SIZE);
}
float adc_get_value_pb8(void) {
prv_adc_pb8_init();
return prv_adc_get_value_average(AVERAGE_TABLE_SIZE);
}
float adc_get_value_pb9(void) {
prv_adc_pb9_init();
return prv_adc_get_value_average(AVERAGE_TABLE_SIZE);
}
float adc_get_value_pa2_filter(float factor) {
static float last = 0;
float now_raw = adc_get_value_pa2();
if (adccapture_error) {
return last;
}
float now = ((float)last * (1.0f - factor)) + ((float)now_raw * factor);
last = now;
return now;
}
float adc_get_value_pb8_filter(float factor) {
static float last = 0;
float now_raw = adc_get_value_pb8();
if (adccapture_error) {
return last;
}
float now = ((float)last * (1.0f - factor)) + ((float)now_raw * factor);
last = now;
return now;
}
float adc_get_value_pb9_filter(float factor) {
static float last = 0;
float now_raw = adc_get_value_pb9();
if (adccapture_error) {
return last;
}
float now = ((float)last * (1.0f - factor)) + ((float)now_raw * factor);
last = now;
return now;
}

14
APP/adc.h

@ -1,14 +0,0 @@
#pragma once
#include "port.h"
#include "systick.h"
#define AVERAGE_TABLE_SIZE 1
float adc_get_value_pa2(void);
float adc_get_value_pb8(void);
float adc_get_value_pb9(void);
float adc_get_value_pa2_filter(float factor);
float adc_get_value_pb8_filter(float factor);
float adc_get_value_pb9_filter(float factor);

82
APP/current_through_mos_capturer.c

@ -1,82 +0,0 @@
#include "port.h"
#include "systick.h"
static ADC_InitStruType x;
static GPIO_InitSettingType y;
static bool adccapture_error = false;
static uint16_t prv_adc_get_value() {
ErrorStatus status = ADC_SoftStart();
adccapture_error = false;
if (status != SUCCESS) {
adccapture_error = true;
return 0;
}
uint32_t inticket = get_sys_ticket();
while (ADC_GetConvStatus() != RESET) {
if (port_haspassedms(inticket) > 10) {
adccapture_error = true;
return 0;
}
}
uint16_t adcv = ADC_GetConvValue();
ADC_SoftStop();
return adcv ;
}
static void prv_adc_pb9_init() {
y.Signal = GPIO_Pin_Signal_Analog; //
y.Dir = GPIO_Direction_Input; //
y.Func = GPIO_Reuse_Func0;
// x.CHS设置adc采集的通道每个引脚对应一个通道
GPIO_Init(GPIO_Pin_B9, &y);
//Tadclk=1/(PCLK/32)
x.CLKS = ADC_CLKS_PCLK;
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */
//*3.3/4096=
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,这个是设置adc具体是要哪个电压来做参考adc的参考电压为多少 */
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */
x.CHS = ADC_CHS_AIN4;
// x.CHS = ADC_CHS_AIN8;
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */
//st*2+1(Tadclk)=1.743us
x.ST = 0; /* AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_8; /* AD分辨率12位 */
ADC_Init(&x);
prv_adc_get_value();
}
extern uint32_t getCNT();
extern uint32_t getTOP();
uint16_t capture(int timeoff) {
static bool inited = false;
if (inited == false) {
prv_adc_pb9_init();
inited = true;
}
uint16_t expectCNTBegin = getTOP() / 100.0 * timeoff;
uint16_t expectCNTEnd = getTOP() / 100.0 * (timeoff + 1);
// printf("%d %d , %d\n", timeoff, expectCNTBegin, expectCNTEnd);
int icount = 0;
while (true) {
volatile uint16_t countnow = T16Nx_GetCNT1(T16N0);
// printf("%d\n",countnow);
for (size_t i = 0; i < icount % 10; i++) {
}
icount++;
if (countnow >= expectCNTBegin && countnow < expectCNTEnd) {
break;
}
}
uint16_t v = prv_adc_get_value();
return v;
}

3
APP/light.c

@ -1,5 +1,5 @@
#include "light.h" #include "light.h"
#if 0
static bool s_interval_working_mode; static bool s_interval_working_mode;
static rgb_light_mode_t s_rgb_now_state; static rgb_light_mode_t s_rgb_now_state;
static rgb_light_mode_t s_rgb_light_mode_config; static rgb_light_mode_t s_rgb_light_mode_config;
@ -161,3 +161,4 @@ void light_module_schedule(void) {
prv_light_module_rgb_light_control_schedule(); prv_light_module_rgb_light_control_schedule();
prv_time_light_control_schedule(); prv_time_light_control_schedule();
} }
#endif

42
APP/light.h

@ -1,31 +1,31 @@
#ifndef _LIGHT_H_ #ifndef _LIGHT_H_
#define _LIGHT_H_ #define _LIGHT_H_
#include "board.h"
#include "lib_config.h"
#include "port.h"
#include "system_ES8P5066.h"
#include "systick.h"
// #include "board.h"
// #include "lib_config.h"
// #include "port.h"
// #include "system_ES8P5066.h"
// #include "systick.h"
typedef enum {
krgb_close = 0, /*关闭灯*/
krgb_color_green = 1, /*打开绿灯*/
krgb_color_blue = 2, /*打开蓝灯*/
krgb_color_red = 3, /*打开红灯*/
// typedef enum {
// krgb_close = 0, /*关闭灯*/
// krgb_color_green = 1, /*打开绿灯*/
// krgb_color_blue = 2, /*打开蓝灯*/
// krgb_color_red = 3, /*打开红灯*/
} rgb_light_mode_t;
// } rgb_light_mode_t;
void light_module_set_rgb_mode(rgb_light_mode_t mode);
void light_module_set_error_light_mode(bool open, uint8_t error_mode);
void light_module_set_autoshutdown_indicator_light(bool light);
void light_module_set_rgb_in_interval_working_mode(bool state);
void light_module_close_all_light(void);
// void light_module_set_rgb_mode(rgb_light_mode_t mode);
// void light_module_set_error_light_mode(bool open, uint8_t error_mode);
// void light_module_set_autoshutdown_indicator_light(bool light);
// void light_module_set_rgb_in_interval_working_mode(bool state);
// void light_module_close_all_light(void);
void light_module_schedule(void);
// void light_module_schedule(void);
//
int hook_get_autoshutdown_timecount();
//
bool hook_get_ozone_generator_working_flag();
// //
// int hook_get_autoshutdown_timecount();
// //
// bool hook_get_ozone_generator_working_flag();
#endif #endif

144
APP/main.c

@ -5,6 +5,7 @@
#include "adc.h" #include "adc.h"
#include "board.h" #include "board.h"
#if 0
#define PWM_FREQHZ 25000 //硬件pwm频率 #define PWM_FREQHZ 25000 //硬件pwm频率
/*********************************************************************************************************************** /***********************************************************************************************************************
@ -17,54 +18,25 @@ void onkey(zkey_t* key, zkey_state_t key_state);
static zkey_t s_keys[] = { static zkey_t s_keys[] = {
ZKEY_INIT("timerkey", port_gpio_get_timer_key_state), //2 ZKEY_INIT("timerkey", port_gpio_get_timer_key_state), //2
ZKEY_INIT("gearskey", port_gpio_get_gears_key_state), //1
ZKEY_INIT("levelkey", port_gpio_get_level_key_state), //1
ZKEY_INIT("intervalkey", port_gpio_get_interval_key_state), //3 ZKEY_INIT("intervalkey", port_gpio_get_interval_key_state), //3
ZKEY_INIT("switchkey", port_gpio_get_switch_key_state),
ZKEY_INIT("powerkey", port_gpio_get_power_key_state),
}; };
zkey_module_t key_module = ZMODULE_INIT(s_keys, onkey); zkey_module_t key_module = ZMODULE_INIT(s_keys, onkey);
extern uint32_t target_frequencyhz;
extern uint32_t target_duty;
/***********************************************************************************************************************
* =========================================================================================================== *
***********************************************************************************************************************/
static bool error_even_trigger_after_stop_ozone_work_state; //
//
bool g_setting_interval_work_flag = false; //
work_level_t g_setting_level = kwork_level_hight; //
//
bool g_power_flag = false; //
static int g_error_num;
bool g_auto_shutdown_flag = false; //使
static uint32_t g_auto_shutdown_countdown_s; //
bool s_rxbuf_is_ready = false;
char rx_buffer[50]; //
uint8_t rx_data; //
uint8_t rx_count = 0; //
uint32_t uart0_lastreceive_ticket = 0;
// int freqhz = 29300;
int freqhz = 34450;
int dutyus = 4;
void ozone_pwm_control_update();
/***********************************************************************************************************************
* =======================================================HOOK======================================================== *
***********************************************************************************************************************/
bool hook_get_ozone_generator_working_flag() { return ozone_pwm_control_hardware_is_enable(); }
int hook_get_autoshutdown_timecount() { return g_auto_shutdown_countdown_s; }
void onkey(zkey_t* key, zkey_state_t key_state) { void onkey(zkey_t* key, zkey_state_t key_state) {
if (key == &s_keys[2] /*左3*/ && zks_falling_edge == key_state) { if (key == &s_keys[2] /*左3*/ && zks_falling_edge == key_state) {
freqhz += 50;
ozone_pwm_control_update(); ozone_pwm_control_update();
printf("onkey2\n");
} }
if (key == &s_keys[0] /*左2*/ && zks_falling_edge == key_state) { if (key == &s_keys[0] /*左2*/ && zks_falling_edge == key_state) {
freqhz -= 50;
ozone_pwm_control_update();
printf("onkey0\n");
}
if (key == &s_keys[1] /*左2*/ && zks_falling_edge == key_state) {
}
if (key == &s_keys[3] /*左2*/ && zks_falling_edge == key_state) {
printf("onkey3\n");
ozone_pwm_control_update(); ozone_pwm_control_update();
} }
} }
@ -77,13 +49,13 @@ void UART0_IRQHandler(void) {
* @brief * @brief
* *
*/ */
rx_data = UART_RecByte(UART0);
if (!s_rxbuf_is_ready) {
if (rx_count < sizeof(rx_buffer) - 1) {
rx_buffer[rx_count++] = rx_data;
uart0_lastreceive_ticket = get_sys_ticket();
}
}
// rx_data = UART_RecByte(UART0);
// if (!s_rxbuf_is_ready) {
// if (rx_count < sizeof(rx_buffer) - 1) {
// rx_buffer[rx_count++] = rx_data;
// uart0_lastreceive_ticket = get_sys_ticket();
// }
// }
UART_ClearITPendingBit(UART0, UART_FLAG_TB); UART_ClearITPendingBit(UART0, UART_FLAG_TB);
UART_ClearITPendingBit(UART0, UART_FLAG_RB); UART_ClearITPendingBit(UART0, UART_FLAG_RB);
@ -203,13 +175,15 @@ float power_filter(float nowpower, float factor) {
} }
uint16_t capture(int timeoff); uint16_t capture(int timeoff);
#endif
int main(void) { int main(void) {
HRC_Config(Enable, SCU_HRC_48M, Enable); //SCU_CLK_HRC HRC_Config(Enable, SCU_HRC_48M, Enable); //SCU_CLK_HRC
SystemInit();
DeviceClockAllEnable(); //
User_SysTickInit(); //(1ms中断)
SysTick_Enable();
SystemInit(); //
DeviceClockAllEnable(); //
#if 0
// //
unused_gpio_init(); unused_gpio_init();
gpio_init(); gpio_init();
@ -218,9 +192,7 @@ int main(void) {
// //
zkey_init(&key_module); zkey_init(&key_module);
// //
port_fan_set(true); port_fan_set(true);
// //
printf("Initialization completed \r\n"); printf("Initialization completed \r\n");
printf("version:%s\r\n", VERSION); printf("version:%s\r\n", VERSION);
@ -228,71 +200,7 @@ int main(void) {
// stop_pwm_output(); // stop_pwm_output();
while (true) { while (true) {
/*******************************************************************************************************************
* ===================================================================================================== *
*******************************************************************************************************************/
DO_IT_EACH_MS(200) {
static uint8_t debug_led_state = 1;
debug_led_state = !debug_led_state;
port_debug_set(debug_led_state);
port_led_r_set(debug_led_state);
port_led_g_set(debug_led_state);
port_led_b_set(debug_led_state);
}
END()
static float fan_w = 0;
static float ozone_w = 0;
DO_IT_EACH_MS(1 * 5) { //
float pa2_now = adc_get_value_pa2();
float pb8_now = adc_get_value_pb8();
float pa2 = adc_get_value_pa2_filter(0.005);
float pb8 = adc_get_value_pb8_filter(0.005);
fan_w = 12 * pa2 / 1; //
ozone_w = 12 * pb8 / 0.5; //
}
END()
DO_IT_EACH_MS(3000) { //
printf("{plotter:%f %f}\r\n", fan_w, ozone_w);
}
END()
try_process_rx_order();
/***********************************************************************************************************************
* =================================================================================================== *
***********************************************************************************************************************/
DO_IT_EACH_MS(KEY_PERIOD) { zkey_do_loop_in_each_period(NULL); }
END();
ozone_pwm_control_module_loop();
// DO_IT_EACH_MS(5 * 1000) {
// for (size_t i = 0; i < 95; i++) {
// uint16_t now = capture(i);
// printf("{p:%f}\r\n", now*1.0);
// }
// for (size_t i = 0; i < 100; i++) {
// printf("{p:2.0}\r\n");
// }
// }
// END();
#if 0
DO_IT_EACH_MS(1) {
static int count = 0;
count++;
if (count % 25 == 12) {
set_pwm_modbul_freq_duty2(freqhz / 2, 0);
} else if (count % 25 == 0) {
ozone_pwm_control_update();
}
}
END();
#endif
// End.................................. // End..................................
} }
#endif
} }

6
APP/main.h

@ -32,11 +32,11 @@ void update_interval_period_duty(uint8_t interval_duty);
void restore_the_mode_before_intermittent_work(void); void restore_the_mode_before_intermittent_work(void);
void process_rgb_flicker(void); void process_rgb_flicker(void);
void power_on_ozone_working_status(void); void power_on_ozone_working_status(void);
void update_ozone_work_gears(work_level_t gears);
void process_gearskey_press_even(void);
void update_ozone_work_level(work_level_t level);
void process_levelkey_press_even(void);
void shutdown(void); void shutdown(void);
void starting_up(void); void starting_up(void);
void process_switchkey(void);
void process_powerkey(void);
void updae_timing_light_state(void); void updae_timing_light_state(void);
void update_timing_time(void); void update_timing_time(void);
void try_shutdown(void); void try_shutdown(void);

2
APP/ozone_pwm_control.c

@ -1,3 +1,4 @@
#if 0
#include "ozone_pwm_control.h" #include "ozone_pwm_control.h"
#include "pwm.h" #include "pwm.h"
static bool s_ozone_pwm_control_enable_falg = false; static bool s_ozone_pwm_control_enable_falg = false;
@ -78,3 +79,4 @@ void ozone_pwm_control_module_loop(void) {
} }
} }
} }
#endif

2
APP/ozone_pwm_control.h

@ -1,3 +1,4 @@
#if 0
#ifndef _OZONE_PWM_CONTROL_H_ #ifndef _OZONE_PWM_CONTROL_H_
#define _OZONE_PWM_CONTROL_H_ #define _OZONE_PWM_CONTROL_H_
@ -22,3 +23,4 @@ bool ozone_pwm_control_is_enable(void);
bool ozone_pwm_control_hardware_is_enable(void); bool ozone_pwm_control_hardware_is_enable(void);
#endif #endif
#endif

330
APP/port.c

@ -1,91 +1,214 @@
#include "port.h" #include "port.h"
// io led4+1 RGB:3 1
/***********************************************************************************************************************
* ======================================================ticket======================================================= *
***********************************************************************************************************************/
uint32_t g_sys_sick = 0;
void SysTick_IRQHandler(void) { g_sys_sick++; }
void port_systicket_init(void) {
SYSTICK_InitStruType x;
// x.SysTick_Value = SystemCoreClock / 10000;//4800(SystemCoreClock=48M)
// x.SysTick_ClkSource = SysTick_ClkS_Cpu;//48M
// x.SysTick_ITEnable = Enable;
// SysTick_Init(&x);//48M4800 t=1s/f(f=48M/4800)
x.SysTick_Value = SystemCoreClock / 1000; //
x.SysTick_ClkSource = SysTick_ClkS_Cpu; //48M
x.SysTick_ITEnable = Enable; //
SysTick_Init(&x); //48M4800 t=1s/f(f=48M/48000)
SysTick_Disable(); //
SysTick_Enable();
}
/** /**
* @brief 使io设置为输出模式
*
* @brief ticket辅助方法
*/ */
void unused_gpio_init(void) {
GPIO_InitSettingType x;
x.Signal = GPIO_Pin_Signal_Digital;
x.Dir = GPIO_Direction_Output; //
// x.Dir = GPIO_Direction_Input;
x.Func = GPIO_Reuse_Func0;
x.ODE = GPIO_ODE_Output_Disable;
x.DS = GPIO_DS_Output_Normal;
x.PUE = GPIO_PUE_Input_Disable;
x.PDE = GPIO_PDE_Input_Enable;
GPIO_Init(GPIO_Pin_A10, &x);
GPIO_Init(GPIO_Pin_A23, &x);
GPIO_Init(GPIO_Pin_A27, &x); // 26
GPIO_Init(GPIO_Pin_A28, &x); // 27
GPIO_Init(GPIO_Pin_B0, &x);
//adc
GPIO_Init(GPIO_Pin_B8, &x);
GPIO_Init(GPIO_Pin_B9, &x);
GPIO_Init(GPIO_Pin_A2, &x);
GPIO_WriteBit(GPIO_Pin_A10, 0);
GPIO_WriteBit(GPIO_Pin_A23, 0);
GPIO_WriteBit(GPIO_Pin_A27, 0);
GPIO_WriteBit(GPIO_Pin_A28, 0);
GPIO_WriteBit(GPIO_Pin_B0, 0);
GPIO_WriteBit(GPIO_Pin_B8, 0);
GPIO_WriteBit(GPIO_Pin_B9, 0);
GPIO_WriteBit(GPIO_Pin_A2, 0);
uint32_t port_get_now_ms(void) { return g_sys_sick; }
uint32_t port_haspassedms(uint32_t ticket) {
uint32_t nowticket = port_get_now_ms();
if (nowticket >= ticket) {
return nowticket - ticket;
}
return UINT32_MAX - ticket + nowticket;
}
void port_delay_ms(__IO uint32_t nTime) {
uint32_t TimingDelay = 0;
TimingDelay = port_get_now_ms();
// printf("nTime%d\r\n",nTime);
while (port_haspassedms(TimingDelay) < nTime)
;
} }
void port_do_debug_light_state(void) {
static uint32_t lastprocess = 0;
static uint8_t debug_led_state = 1;
if (port_haspassedms(lastprocess) > 1000) {
lastprocess = port_get_now_ms();
debug_led_state = !debug_led_state;
port_debug_set(debug_led_state);
}
}
/***********************************************************************************************************************
* =======================================================GPIO======================================================== *
***********************************************************************************************************************/
static GPIO_InitSettingType default_input_config = {
default_input_config.Signal = GPIO_Pin_Signal_Digital, //
default_input_config.Dir = GPIO_Direction_Input, //
default_input_config.Func = GPIO_Reuse_Func0, //
default_input_config.PUE = GPIO_PUE_Input_Disable, //
default_input_config.PDE = GPIO_PDE_Input_Disable //
};
static GPIO_InitSettingType default_output_config = {
default_output_config.Signal = GPIO_Pin_Signal_Digital, //
default_output_config.Dir = GPIO_Direction_Output, //
default_output_config.Func = GPIO_Reuse_Func0, //
default_output_config.ODE = GPIO_ODE_Output_Disable, //
default_output_config.DS = GPIO_DS_Output_Normal, //
default_output_config.PUE = GPIO_PUE_Input_Disable, //
default_output_config.PDE = GPIO_PDE_Input_Enable //
};
static void led_gpio_init(void) {
GPIO_InitSettingType x;
x.Signal = GPIO_Pin_Signal_Digital;
x.Dir = GPIO_Direction_Output;
x.Func = GPIO_Reuse_Func0;
x.ODE = GPIO_ODE_Output_Disable;
x.DS = GPIO_DS_Output_Normal;
x.PUE = GPIO_PUE_Input_Disable;
x.PDE = GPIO_PDE_Input_Enable;
GPIO_Init(GPIO_Pin_A3, &x);
GPIO_Init(GPIO_Pin_B13, &x);
GPIO_Init(GPIO_Pin_A5, &x);
GPIO_Init(GPIO_Pin_A6, &x);
GPIO_Init(GPIO_Pin_A7, &x);
GPIO_Init(GPIO_Pin_A8, &x);
GPIO_Init(GPIO_Pin_A9, &x);
GPIO_Init(GPIO_Pin_B1, &x); //
GPIO_Init(GPIO_Pin_A22, &x);
// led rgb debug
GPIO_WriteBit(GPIO_Pin_A3, 0);
GPIO_WriteBit(GPIO_Pin_A5, 0);
GPIO_WriteBit(GPIO_Pin_A6, 0);
GPIO_WriteBit(GPIO_Pin_A7, 0);
GPIO_WriteBit(GPIO_Pin_A8, 0);
GPIO_WriteBit(GPIO_Pin_A9, 0);
GPIO_WriteBit(GPIO_Pin_B13, 0);
GPIO_WriteBit(GPIO_Pin_A22, 0);
GPIO_WriteBit(GPIO_Pin_B1, 0);
// default_input_config
static void gpio_init_as_output(GPIO_Pin Pin, GPIO_InitSettingType* setting, int initvalue) {
GPIO_Init(Pin, setting);
GPIO_WriteBit(GPIO_Pin_A3, initvalue);
} }
static void gpio_init_as_input(GPIO_Pin Pin, GPIO_InitSettingType* setting) { GPIO_Init(Pin, setting); }
static void key_gpio_init(void) {
/***********************************************************************************************************************
* ========================================================ADC======================================================== *
***********************************************************************************************************************/
extern void ADC_Set_CH(ADC_TYPE_CHS AdcCH);
ADC_TYPE_CHS adc_get_chnum(GPIO_Pin gpiopin) {
/** /**
* @brief PA11~PA13
* @brief
* :http://192.168.1.3:3000/manufacturer_eastsoft/ES8P5066_res/raw/branch/master/ES8P5066_Datasheet_C%20V1.1.pdf
* Page25:1. 5. 2
* *
* | **PIN NAME (FUNO(D))** | **FUN4(A)** |
* | ------------------------- | ----------- |
* | PA1 | AVREFP/AIN7 |
* | PA2 | AIN8 |
* | PA3 | AIN9 |
* | PA4 | AIN10 |
* | PA5 | AIN11 |
* | PA6 | AIN12 |
* | PA7 | AIN13 |
* | PM | AIN14 |
* | PA9 | AIN15 |
* | PA10 | |
* | PA11 | AIN1 |
* | PAl2 | AIN2 |
* | PA13 | AIN6 |
* | PA14(ISCK) | AIN16 |
* | PA15(ISDA) | AIN17 |
* | PA16 | |
* | PA22 | |
* | PA23 | |
* | PA24 | AIN19 |
* | PA25 | |
* | PA27 | |
* | PA28 | |
* | PBO | |
* | PB1 | |
* | PB8 | AIN3 |
* | PB9 | AIN4 |
* | PB10 | OSCI |
* | PB11 | OSCO |
* | PB12(MRSTN) | AIN0 |
* | PB13 | AIN5 |
*/
if (gpiopin == GPIO_Pin_A1 /* */) return ADC_CHS_AIN7;
if (gpiopin == GPIO_Pin_A2 /* */) return ADC_CHS_AIN8;
if (gpiopin == GPIO_Pin_A3 /* */) return ADC_CHS_AIN9;
if (gpiopin == GPIO_Pin_A4 /* */) return ADC_CHS_AIN10;
if (gpiopin == GPIO_Pin_A5 /* */) return ADC_CHS_AIN11;
if (gpiopin == GPIO_Pin_A6 /* */) return ADC_CHS_AIN12;
if (gpiopin == GPIO_Pin_A7 /* */) return ADC_CHS_AIN13;
if (gpiopin == GPIO_Pin_A14 /**/) return ADC_CHS_AIN14;
if (gpiopin == GPIO_Pin_A9 /* */) return ADC_CHS_AIN15;
if (gpiopin == GPIO_Pin_A11 /**/) return ADC_CHS_AIN1;
if (gpiopin == GPIO_Pin_A12 /**/) return ADC_CHS_AIN2;
if (gpiopin == GPIO_Pin_A13 /**/) return ADC_CHS_AIN6;
if (gpiopin == GPIO_Pin_A14 /**/) return ADC_CHS_AIN16;
if (gpiopin == GPIO_Pin_A15 /**/) return ADC_CHS_AIN17;
if (gpiopin == GPIO_Pin_A24 /**/) return ADC_CHS_AIN19;
if (gpiopin == GPIO_Pin_B8 /* */) return ADC_CHS_AIN3;
if (gpiopin == GPIO_Pin_B9 /* */) return ADC_CHS_AIN4;
if (gpiopin == GPIO_Pin_B12 /**/) return ADC_CHS_AIN0;
if (gpiopin == GPIO_Pin_B13 /**/) return ADC_CHS_AIN5;
ZASSERT(0);
return (ADC_TYPE_CHS)-1;
}
uint32_t adc_get_value(ADC_TYPE_CHS adc_ch) {
ADC_Set_CH(adc_ch);
ADC_SoftStart();
port_delay_ms(1);
ADC_SoftStop();
while (ADC_GetIFStatus(ADC_IF) == RESET)
;
uint32_t adcv = ADC_GetConvValue();
ADC_ClearIFStatus(ADC_IF);
return adcv;
}
/***********************************************************************************************************************
* =======================================================PORT-GPIO======================================================== *
***********************************************************************************************************************/
void port_unused_gpio_init(void) {
/**
* @brief
* http://192.168.1.3:3000/manufacturer_eastsoft/ES8P5066_res/raw/branch/master/AN142_应用笔记_ES8P5066%20V1.0.pdf
* Page8:1. 13 使GPIO端口处理
* 使 GPIO
*
*/ */
GPIO_InitSettingType x;
x.Signal = GPIO_Pin_Signal_Digital;
x.Dir = GPIO_Direction_Input;
x.Func = GPIO_Reuse_Func0;
x.PUE = GPIO_PUE_Input_Disable;
x.PDE = GPIO_PDE_Input_Disable;
GPIO_Init(GPIO_Pin_A11, &x); //
GPIO_Init(GPIO_Pin_A16, &x); //
GPIO_Init(GPIO_Pin_A13, &x);
GPIO_Init(GPIO_Pin_A12, &x);
// GPIO_InitSettingType x;
// x.Signal = GPIO_Pin_Signal_Digital;
// x.Dir = GPIO_Direction_Output; //
// x.Func = GPIO_Reuse_Func0;
// x.ODE = GPIO_ODE_Output_Disable;
// x.DS = GPIO_DS_Output_Normal;
// x.PUE = GPIO_PUE_Input_Disable;
// x.PDE = GPIO_PDE_Input_Enable;
// GPIO_Init(GPIO_Pin_A10, &x);
// GPIO_Init(GPIO_Pin_A23, &x);
// GPIO_Init(GPIO_Pin_A27, &x); // 26
// GPIO_Init(GPIO_Pin_A28, &x); // 27
// GPIO_Init(GPIO_Pin_B0, &x);
// //adc
// GPIO_Init(GPIO_Pin_B8, &x);
// GPIO_Init(GPIO_Pin_B9, &x);
// GPIO_Init(GPIO_Pin_A2, &x);
// GPIO_WriteBit(GPIO_Pin_A10, 0);
// GPIO_WriteBit(GPIO_Pin_A23, 0);
// GPIO_WriteBit(GPIO_Pin_A27, 0);
// GPIO_WriteBit(GPIO_Pin_A28, 0);
// GPIO_WriteBit(GPIO_Pin_B0, 0);
// GPIO_WriteBit(GPIO_Pin_B8, 0);
// GPIO_WriteBit(GPIO_Pin_B9, 0);
// GPIO_WriteBit(GPIO_Pin_A2, 0);
} }
void gpio_init(void) {
led_gpio_init();
key_gpio_init();
void port_gpio_init(void) {
// LED-GPIO初始化
gpio_init_as_output(GPIO_Pin_A3 /* */, &default_output_config, 0);
gpio_init_as_output(GPIO_Pin_B13 /**/, &default_output_config, 0);
gpio_init_as_output(GPIO_Pin_A5 /* */, &default_output_config, 0);
gpio_init_as_output(GPIO_Pin_A6 /* */, &default_output_config, 0);
gpio_init_as_output(GPIO_Pin_A7 /* */, &default_output_config, 0);
gpio_init_as_output(GPIO_Pin_A8 /* */, &default_output_config, 0);
gpio_init_as_output(GPIO_Pin_A9 /* */, &default_output_config, 0);
//
gpio_init_as_output(GPIO_Pin_A22 /**/, &default_output_config, 0);
//GPIO初始化
gpio_init_as_output(GPIO_Pin_B1 /* */, &default_output_config, 0);
//GPIO初始化
gpio_init_as_input(GPIO_Pin_A11 /**/, &default_input_config);
gpio_init_as_input(GPIO_Pin_A16 /**/, &default_input_config);
gpio_init_as_input(GPIO_Pin_A13 /**/, &default_input_config);
gpio_init_as_input(GPIO_Pin_A12 /**/, &default_input_config);
} }
void port_debug_set(bool state) { GPIO_SET(A, 22, !, state); } void port_debug_set(bool state) { GPIO_SET(A, 22, !, state); }
@ -96,7 +219,6 @@ void port_fan_set(bool state) {
} }
GPIO_SET(B, 1, !!, state); GPIO_SET(B, 1, !!, state);
} }
void port_led0_set(bool state) { GPIO_SET(A, 3, !, state); } void port_led0_set(bool state) { GPIO_SET(A, 3, !, state); }
void port_led1_set(bool state) { GPIO_SET(B, 13, !, state); } void port_led1_set(bool state) { GPIO_SET(B, 13, !, state); }
void port_led2_set(bool state) { GPIO_SET(A, 5, !, state); } void port_led2_set(bool state) { GPIO_SET(A, 5, !, state); }
@ -106,11 +228,59 @@ void port_led_g_set(bool state) { GPIO_SET(A, 8, !, state); }
void port_led_b_set(bool state) { GPIO_SET(A, 9, !, state); } void port_led_b_set(bool state) { GPIO_SET(A, 9, !, state); }
bool port_gpio_get_timer_key_state(void) { return GPIO_GET(A, 11, !!); } bool port_gpio_get_timer_key_state(void) { return GPIO_GET(A, 11, !!); }
bool port_gpio_get_gears_key_state(void) { return GPIO_GET(A, 16, !!); }
bool port_gpio_get_switch_key_state(void) { return GPIO_GET(A, 12, !!); }
bool port_gpio_get_level_key_state(void) { return GPIO_GET(A, 16, !!); }
bool port_gpio_get_power_key_state(void) { return GPIO_GET(A, 12, !!); }
bool port_gpio_get_interval_key_state(void) { return GPIO_GET(A, 13, !!); } bool port_gpio_get_interval_key_state(void) { return GPIO_GET(A, 13, !!); }
bool port_led0_get_state(void) { return GPIO_GET(A, 3, !); } bool port_led0_get_state(void) { return GPIO_GET(A, 3, !); }
bool port_led1_get_state(void) { return GPIO_GET(B, 13, !); } bool port_led1_get_state(void) { return GPIO_GET(B, 13, !); }
bool port_led2_get_state(void) { return GPIO_GET(A, 5, !); } bool port_led2_get_state(void) { return GPIO_GET(A, 5, !); }
bool port_led3_get_state(void) { return GPIO_GET(A, 6, !); }
bool port_led3_get_state(void) { return GPIO_GET(A, 6, !); }
/***********************************************************************************************************************
* =====================================================PORT-ADC====================================================== *
***********************************************************************************************************************/
void ADCInit(void) {}
static void adcinit() {
// ADC_GPIO_INIT
{
GPIO_InitSettingType y;
y.Signal = GPIO_Pin_Signal_Analog;
y.Dir = GPIO_Direction_Input;
y.Func = GPIO_Reuse_Func0;
GPIO_Init(GPIO_Pin_A2, &y);
}
{
GPIO_InitSettingType y;
y.Signal = GPIO_Pin_Signal_Analog;
y.Dir = GPIO_Direction_Input;
y.Func = GPIO_Reuse_Func0;
GPIO_Init(GPIO_Pin_B8, &y);
}
// ADCINIT
ADC_InitStruType x;
x.CLKS = ADC_CLKS_PCLK;
x.CLKDIV = ADC_CLKDIV_1_32; /* ADC时钟源预分频 */
x.VREF_SEL = ADC_VREF_SEL_0; /* 内部参考电压2.048v,仅设置内部参考电压为多少 */
x.VREFP = ADC_VREFP_VDD; /* 选择芯片的工作电压VDD,*/
x.VREFN = ADC_VREFN_VSS; /* 负向参考电压选择 */
x.SMPS = ADC_SMPS_SOFT; /* AD采样模式为软件控制 */
x.ST = 10; /*采样时间st*2+1(个Tadclk)=1.743us AD硬件采样时间选择 */
x.BITSEL = ADC_BITSEL_12; /* AD分辨率12位 */
x.CHS = ADC_CHS_AIN0; /*这里使用通道零作为默认,当没有使能ADC采集时,这个通道数关系不大*/
ADC_Init(&x);
}
float port_adc_get_fan_power() {
uint32_t adcraw = adc_get_value(adc_get_chnum(GPIO_Pin_A2));
float voltage = adcraw * 3.3 / 4096;
return voltage * voltage / 1; // u^2/R
}
float port_adc_get_ozone_generator_power() {
uint32_t adcv = adc_get_value(adc_get_chnum(GPIO_Pin_B8));
float voltage = adcv * 3.3 / 4096;
return voltage * voltage / 0.5; // u^2/R
}

16
APP/port.h

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <stdbool.h> //定义布尔 #include <stdbool.h> //定义布尔
#include "lib_config.h" #include "lib_config.h"
#include "system_ES8P5066.h" #include "system_ES8P5066.h"
// #define UART0_RXD0_PIN GPIO_Pin_A22 // #define UART0_RXD0_PIN GPIO_Pin_A22
@ -8,8 +9,8 @@
#define UART0_TXD0_PIN GPIO_Pin_A25 #define UART0_TXD0_PIN GPIO_Pin_A25
#define GPIO_GET(port, pin, mirror) (mirror(GPIO_ReadBit(GPIO_Pin_##port##pin) == 1)) #define GPIO_GET(port, pin, mirror) (mirror(GPIO_ReadBit(GPIO_Pin_##port##pin) == 1))
#define GPIO_SET(port, pin, mirror, _state) GPIO_WriteBit(GPIO_Pin_##port##pin, mirror _state ? 1 : 0); #define GPIO_SET(port, pin, mirror, _state) GPIO_WriteBit(GPIO_Pin_##port##pin, mirror _state ? 1 : 0);
void unused_gpio_init(void);
void gpio_init(void);
void port_unused_gpio_init(void);
void port_gpio_init(void);
// //
void port_debug_set(bool state); void port_debug_set(bool state);
@ -23,12 +24,19 @@ void port_led_b_set(bool state);
void port_fan_set(bool state); void port_fan_set(bool state);
bool port_gpio_get_timer_key_state(void); bool port_gpio_get_timer_key_state(void);
bool port_gpio_get_gears_key_state(void);
bool port_gpio_get_level_key_state(void);
bool port_gpio_get_interval_key_state(void); bool port_gpio_get_interval_key_state(void);
bool port_gpio_get_switch_key_state(void);
bool port_gpio_get_power_key_state(void);
bool port_led0_get_state(void); bool port_led0_get_state(void);
bool port_led1_get_state(void); bool port_led1_get_state(void);
bool port_led2_get_state(void); bool port_led2_get_state(void);
bool port_led3_get_state(void); bool port_led3_get_state(void);
//
#define ZASSERT(condition) \
if (!condition) { \
printf("%s:%d:ASSERT(%s) fail\n", __FILE__, __LINE__, #condition); \
while (true) { \
} \
}

2
APP/pwm.c

@ -1,3 +1,4 @@
#if 0
#include "pwm.h" #include "pwm.h"
#include "board.h" #include "board.h"
@ -163,3 +164,4 @@ void set_pwm_modbul_freq_duty2(uint32_t frequencyhz, double duty) {
} }
void stop_pwm_output() { T16Nx_Disable(T16N0); } void stop_pwm_output() { T16Nx_Disable(T16N0); }
#endif

2
APP/systick.c

@ -1,3 +1,4 @@
#if 0
#include "systick.h" #include "systick.h"
extern uint32_t g_sys_sick; extern uint32_t g_sys_sick;
@ -59,3 +60,4 @@ void Delayms(__IO uint32_t nTime)
// printf("nTime%d\r\n",nTime); // printf("nTime%d\r\n",nTime);
while (port_haspassedms(TimingDelay) <= nTime); while (port_haspassedms(TimingDelay) <= nTime);
} }
#endif

166
README.md

@ -11,3 +11,169 @@
实现采集流过MOS的电流的大小的测量代码 实现采集流过MOS的电流的大小的测量代码
``` ```
## 代码结构
```
《---------------代码功能模块----------------》
功率采集模块:
臭氧工作控制模块:
start
stop
setCenterFrequency
Config{
centerFrequency//中心频率
power//功率大小
levelNum//档位
freqChangeStep//频率修改
maxFreq
minFreq
controlDuty
}
struct{
getPower() ----> getPowerFail ---> not SetFreq
setFreq()
stopFan()
startFan()
}
getPower
找到
(expectPower-nowPower) *
-----------------------------------------------------------------
频率越小功率越小,只适合在某个特定的频率范围内
当频率匹配时:
当频率不匹配时:
方案一:
当功率变大时,逐渐减小频率,直到功率恢复。
当功率变小时,逐渐增加频率,直到功率恢复。
存在的问题:
如果设备一直工作在频率匹配的情况下,这个方案没有问题。但如果由于变压器的差异,MOS管的差异,臭氧发生棒的差异,导致设备没有工作在频率不匹配的情况下
方案二:
设备自动查找匹配频率:
设备上电,
从某个频率开始,逐渐增加频率,记录功率。
计算功率变化的斜率,
斜率过零点-0->+0 的频率,便是设备的匹配频率。
减小步长,在该点附近,再匹配一次,找到更精准的频率点。
记录频率。
如何检测当前频率不匹配 5W的时候,测出了8W的功率,且频率调整已经到了极限位置。
1. 功率检测功能异常,读取功率为零。
断路
变压器烧毁
臭氧发生棒异常
2. 功率大于额定值
MOS短路
变压器短路
3.功率大小超出额定范围,但没有大的离谱。
PowerCapture
```
```
《---------------使用说明----------------》
电源按键:
按下电源按键,指示灯亮蓝灯,设备设置为一档。再次按下电源按键,设备关机。
档位按键:
按下档位,设备在一档和二档之间切换,一档工作时候,设备亮蓝灯,二档工作时设备亮绿灯。
定时关机按键:
按下按键,设备定时指示灯,面板指示灯亮一个灯,亮两个灯,亮三个灯,亮四个灯,全部熄灭。分别代表着设备15分钟,30分钟,45分钟,60分钟后自动关机。在配置定时关机时间时,面板的定时指示灯闪烁,用户不操作3s后,停止闪烁。
间歇工作按键:
按下按键后,效果等同于定时工作按键,只不过定时时间到了,设备状态指示灯亮绿灯,设备停止工作,面板指示灯熄灭,等待8小时后,设备继续工作。
《---------------代码功能模块----------------》
【2】
功率测量模块:
周期循环获取功率
【3】
臭氧发生控制模块:
1.当功率变大时,逐渐减小频率,直到功率恢复。
2.当功率变小时,逐渐增加频率,直到功率恢复。
3.通过定死的频率范围控制频率更改的范围,不做任何出错检查
【4】
异常监控模块
1.功率检测功能异常,读取功率为零
2.读取功率和期望功率差值过大,且臭氧发生控制模块已经到了调整范围的极限。
【1】
灯光控制模块
1.普通工作状态指示灯配置
2.异常显示
```
| **PIN NAME (FUNO(D))** | **FUN4(A)** |
| ------------------------- | ----------- |
| PA1 | AVREFP/AIN7 |
| PA2 | AIN8 |
| PA3 | AIN9 |
| PA4 | AIN10 |
| PA5 | AIN11 |
| PA6 | AIN12 |
| PA7 | AIN13 |
| PM | AIN14 |
| PA9 | AIN15 |
| PA10 | |
| PA11 | AIN1 |
| PAl2 | AIN2 |
| PA13 | AIN6 |
| PA14(ISCK) | AIN16 |
| PA15(ISDA) | AIN17 |
| PA16 | |
| PA22 | |
| PA23 | |
| PA24 | AIN19 |
| PA25 | |
| PA27 | |
| PA28 | |
| PBO | |
| PB1 | |
| PB8 | AIN3 |
| PB9 | AIN4 |
| PB10 | OSCI |
| PB11 | OSCO |
| PB12(MRSTN) | AIN0 |
| PB13 | AIN5 |

1212
project_ozone/Listings/project_o.map
File diff suppressed because it is too large
View File

42
project_ozone/project_o.uvgui.zel
File diff suppressed because it is too large
View File

Loading…
Cancel
Save