16 changed files with 1131 additions and 1094 deletions
-
160APP/adc.c
-
14APP/adc.h
-
82APP/current_through_mos_capturer.c
-
3APP/light.c
-
42APP/light.h
-
142APP/main.c
-
6APP/main.h
-
2APP/ozone_pwm_control.c
-
2APP/ozone_pwm_control.h
-
334APP/port.c
-
16APP/port.h
-
2APP/pwm.c
-
2APP/systick.c
-
166README.md
-
1212project_ozone/Listings/project_o.map
-
42project_ozone/project_o.uvgui.zel
@ -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; |
|||
} |
@ -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); |
@ -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; |
|||
} |
@ -1,31 +1,31 @@ |
|||
#ifndef _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 |
1212
project_ozone/Listings/project_o.map
File diff suppressed because it is too large
View File
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
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue