From b837c2aef0eb36e4530c92d602776bddca6f58db Mon Sep 17 00:00:00 2001 From: AlexeiBazlaev Date: Mon, 4 Jan 2021 13:30:00 +0700 Subject: [PATCH] 1.USB debugged 2.Added modules --- .vs/TE_Controller/v14/.atsuo | Bin 47104 -> 47104 bytes TE_Controller/TE_Controller.cproj | 4 +- TE_Controller/src/include/adc_user.h | 28 +++++++++++++ TE_Controller/src/include/dac_user.h | 2 +- TE_Controller/src/include/realsence.h | 2 +- TE_Controller/src/include/tmpgood.h | 4 +- TE_Controller/src/include/ws2812.h | 2 +- TE_Controller/src/source/adc_user.c | 55 ++++++++++++++++++++++++++ TE_Controller/src/source/adc_user.h | 10 ++--- TE_Controller/src/source/dac_user.c | 1 + TE_Controller/src/source/realsence.c | 4 +- TE_Controller/src/source/tmpgood.c | 4 +- TE_Controller/src/source/ws2812.c | 3 ++ 13 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 TE_Controller/src/include/adc_user.h create mode 100644 TE_Controller/src/source/adc_user.c diff --git a/.vs/TE_Controller/v14/.atsuo b/.vs/TE_Controller/v14/.atsuo index b4370d53972bd8cb54b8fefb3d072c308553212d..6513e8ecda1f4af1d2a74c079d3ccf726f84cee4 100644 GIT binary patch delta 3611 zcmdT`3s6*57(VB6S$1i`6$KF#E@TKLuprFOO^s!Z)59J%Q&v+`SyS0e(2#`{+xOqyl@+bA8E2XkRM$Y>n$)vr^mhoC>~x3@w*;@7uB?f`ZIZH(FUjXf}S1CIia0Tkc~$UQ(i z@T7liFXYp}Gk&`Ra=%~i+jvd9IFVY;y&^a5Eq8b+_i8iDABAX2`ED*=ld@LKh397g zJ^umiCBeKe8f^_^4gk*r2LU=d9K|rvlRDLR6rFL&l1Pq8qB98H2bbqXQ_M_pxWKCQ z#EjuWiAj|UF)WnXim*z?Gd?z2Vd%tEI2Wg5Y_vqE!}bbg{2rM~H?TtVj4vZ!p-w0> zajG*E?U`AF3S&3ZPRAQ0cT|ZHFX$}|n%C5*X6{j>&Y@kLZx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L0YD6s)NZ5nW!KY;?WpLWt`ak=EH_2^vBT+8!+I@L9%b3t>~ zB9oR5h_f_vw4s=*^CZ+Ma2l{agZ>rp>YRQJ{U8{c)927rVBiBeOY394Fmkk!4Q@&9 zoMH-W4AAp$=hN?{iE-U1J+EjL`$Q8kJ$>h;QKZyKMHSs$l<(i_Y!lBQW{>C*U7{@< z#i|umQYfAR#aL~@Uh?#1r#vlo<3{fiF9vU9oC>aeC$-9YrRToey#D%ibT;=8mc!AwVmEz3x8_(D-v0a@j(m&G&8hGs-UM@=Sx`%B0<(SASML) z^J{g!S7nRVEN?-S(2VC<>w6eoMN}hRC)pMAA>>VfW`;_oHnO8ynbp-FOCwtuZWSDG z{|`AGskdvUJ$_i)WD@>}zqXOLwmb@P-JEG$qKr;uY*xm0C4*F9-$VK9vg6CWwgZ!+ zXLfx49P63rQj3q)2IGHYOZ#Kla^DKK!fLWY)g>eQib=p>1jGI compile - + compile @@ -1696,7 +1696,7 @@ compile - + compile diff --git a/TE_Controller/src/include/adc_user.h b/TE_Controller/src/include/adc_user.h new file mode 100644 index 0000000..66e2f25 --- /dev/null +++ b/TE_Controller/src/include/adc_user.h @@ -0,0 +1,28 @@ +/* + * adc.h + * + * Created: 03.01.2021 23:34:13 + * Author: Lexus + */ + + +#ifndef ADC_H_ +#define ADC_H_ + +#define chan_NTC_MCU ADC_POSITIVE_INPUT_PIN1 +#define chan_NTC_TEC ADC_POSITIVE_INPUT_PIN5 +#define chan_LFB ADC_POSITIVE_INPUT_PIN19 +#define chan_CS ADC_POSITIVE_INPUT_PIN4 +#define chan_SFB ADC_POSITIVE_INPUT_PIN18 +#define chan_VTEC ADC_POSITIVE_INPUT_PIN6 +#define chan_ITEC ADC_POSITIVE_INPUT_PIN7 + +typedef enum adc_positive_input ADC_chan_t; + +void configure_adc(void); +uint16_t adc_read_value(void); +float adc_get_V(uint16_t value); +float adc_get_Q(uint16_t value); +uint16_t adc_read_value_spec(ADC_chan_t); +float adc_get_V_spec(ADC_chan_t chan); +#endif /* ADC_H_ */ \ No newline at end of file diff --git a/TE_Controller/src/include/dac_user.h b/TE_Controller/src/include/dac_user.h index 74d3fdb..1678843 100644 --- a/TE_Controller/src/include/dac_user.h +++ b/TE_Controller/src/include/dac_user.h @@ -9,6 +9,6 @@ #ifndef DAC_USER_H_ #define DAC_USER_H_ -void configure_dac_channel(void) +void configure_dac_channel(void); #endif /* DAC_USER_H_ */ \ No newline at end of file diff --git a/TE_Controller/src/include/realsence.h b/TE_Controller/src/include/realsence.h index 654815a..7c59e4f 100644 --- a/TE_Controller/src/include/realsence.h +++ b/TE_Controller/src/include/realsence.h @@ -10,6 +10,6 @@ #define REALSENCE_H_ void rs_configure_port_pins(void); -void rs_set(bool value); +void rs_set(_Bool value); #endif /* REALSENCE_H_ */ \ No newline at end of file diff --git a/TE_Controller/src/include/tmpgood.h b/TE_Controller/src/include/tmpgood.h index 3697ff3..6853152 100644 --- a/TE_Controller/src/include/tmpgood.h +++ b/TE_Controller/src/include/tmpgood.h @@ -9,7 +9,7 @@ #ifndef TMPGOOD_H_ #define TMPGOOD_H_ -void tmpgood_configure_port_pins(void) -bool tmpgood_get_state(void) +void tmpgood_configure_port_pins(void); +_Bool tmpgood_get_state(void); #endif /* TMPGOOD_H_ */ \ No newline at end of file diff --git a/TE_Controller/src/include/ws2812.h b/TE_Controller/src/include/ws2812.h index d452f95..0c5c8a8 100644 --- a/TE_Controller/src/include/ws2812.h +++ b/TE_Controller/src/include/ws2812.h @@ -9,6 +9,6 @@ #ifndef WS2812_H_ #define WS2812_H_ -void ws2812_configure_port_pins(void) +void ws2812_configure_port_pins(void); #endif /* WS2812_H_ */ \ No newline at end of file diff --git a/TE_Controller/src/source/adc_user.c b/TE_Controller/src/source/adc_user.c new file mode 100644 index 0000000..0081d44 --- /dev/null +++ b/TE_Controller/src/source/adc_user.c @@ -0,0 +1,55 @@ +/* + * adc.c + * + * Created: 03.01.2021 23:33:58 + * Author: Lexus + */ +#include "adc_user.h" +#include "adc.h" +struct adc_module adc_instance; +// init ADC +void configure_adc(void) +{ + struct adc_config config_adc; + adc_get_config_defaults(&config_adc); + + config_adc.positive_input = ADC_POSITIVE_INPUT_PIN1; + config_adc.negative_input = ADC_NEGATIVE_INPUT_GND; + config_adc.reference = ADC_REFERENCE_INTVCC0; + + config_adc.resolution = ADC_RESOLUTION_12BIT; + config_adc.gain_factor = ADC_GAIN_FACTOR_1X; + config_adc.gain_factor = ADC_GAIN_FACTOR_DIV2; + config_adc.clock_prescaler = ADC_CLOCK_PRESCALER_DIV512; // prescaler influence to accuracy of measures. Don't set less then 32 + + adc_init(&adc_instance, ADC, &config_adc); + + adc_enable(&adc_instance); +} + +uint16_t adc_read_value(void){ + adc_start_conversion(&adc_instance); + uint16_t result; + do { + /* Wait for conversion to be done and read out result */ + } while (adc_read(&adc_instance, &result) == STATUS_BUSY); + return result; +} + +uint16_t adc_read_value_spec(ADC_chan_t chan) +{ + adc_set_positive_input(&adc_instance, chan); + return adc_read_value(); +} + +float adc_get_Q(uint16_t value){ + float gane_factor=0.5; + float vref_k=1.0/1.48; + float ADC_range = 4096.0; + return (value*vref_k)/(gane_factor*ADC_range); +} + +float adc_get_V(uint16_t value){ + float Uvcc=3.3; + return adc_get_Q(value) * Uvcc; +} \ No newline at end of file diff --git a/TE_Controller/src/source/adc_user.h b/TE_Controller/src/source/adc_user.h index 17dd276..460b888 100644 --- a/TE_Controller/src/source/adc_user.h +++ b/TE_Controller/src/source/adc_user.h @@ -8,7 +8,7 @@ #ifndef ADC_H_ #define ADC_H_ - +#include #define chan_NTC_MCU ADC_POSITIVE_INPUT_PIN1 #define chan_NTC_TEC ADC_POSITIVE_INPUT_PIN5 #define chan_LFB ADC_POSITIVE_INPUT_PIN19 @@ -19,10 +19,10 @@ typedef enum adc_positive_input ADC_chan_t; -void configure_adc(void) -uint16_t adc_read_value(void) -float adc_get_V(uint16_t value) -float adc_get_Q(uint16_t value) +void configure_adc(void); +uint16_t adc_read_value(void); +float adc_get_V(uint16_t value); +float adc_get_Q(uint16_t value); uint16_t adc_read_value_spec(ADC_chan_t); float adc_get_V_spec(ADC_chan_t chan); #endif /* ADC_H_ */ \ No newline at end of file diff --git a/TE_Controller/src/source/dac_user.c b/TE_Controller/src/source/dac_user.c index 9b5c1ae..abd2d51 100644 --- a/TE_Controller/src/source/dac_user.c +++ b/TE_Controller/src/source/dac_user.c @@ -4,6 +4,7 @@ * Created: 04.01.2021 0:51:07 * Author: Lexus */ +#include #include "dac_user.h" struct dac_module dac_instance; void configure_dac_channel(void) diff --git a/TE_Controller/src/source/realsence.c b/TE_Controller/src/source/realsence.c index b299786..f37c740 100644 --- a/TE_Controller/src/source/realsence.c +++ b/TE_Controller/src/source/realsence.c @@ -5,6 +5,8 @@ * Author: Lexus */ #include "realsence.h" +#include "port.h" +#include "conf_board.h" bool rs_power; void rs_configure_port_pins(void) @@ -16,7 +18,7 @@ void rs_configure_port_pins(void) port_pin_set_config(PIN_RS_POWER, &config_port_pin); } -void rs_set(bool value){ +void rs_set(_Bool value){ port_pin_set_output_level(PIN_RS_POWER, value?0:1); rs_power = value; } diff --git a/TE_Controller/src/source/tmpgood.c b/TE_Controller/src/source/tmpgood.c index 653f5ac..3155c14 100644 --- a/TE_Controller/src/source/tmpgood.c +++ b/TE_Controller/src/source/tmpgood.c @@ -4,6 +4,8 @@ * Created: 03.01.2021 23:22:04 * Author: Lexus */ +#include "conf_board.h" +#include "port.h" void tmpgood_configure_port_pins(void) { struct port_config config_port_pin; @@ -13,7 +15,7 @@ void tmpgood_configure_port_pins(void) port_pin_set_config(TC_TMPGD, &config_port_pin); } -bool tmpgood_get_state(void) +_Bool tmpgood_get_state(void) { return port_pin_get_input_level(TC_TMPGD); } \ No newline at end of file diff --git a/TE_Controller/src/source/ws2812.c b/TE_Controller/src/source/ws2812.c index cf7a0f3..c65fdce 100644 --- a/TE_Controller/src/source/ws2812.c +++ b/TE_Controller/src/source/ws2812.c @@ -4,6 +4,9 @@ * Created: 03.01.2021 23:00:57 * Author: Lexus */ +#include "ws2812.h" +#include "conf_board.h" +#include "port.h" void ws2812_configure_port_pins(void) {