diff --git a/.vs/TE_Controller/v14/.atsuo b/.vs/TE_Controller/v14/.atsuo index b4370d5..6513e8e 100644 Binary files a/.vs/TE_Controller/v14/.atsuo and b/.vs/TE_Controller/v14/.atsuo differ diff --git a/TE_Controller/TE_Controller.cproj b/TE_Controller/TE_Controller.cproj index 0f6a720..e58519a 100644 --- a/TE_Controller/TE_Controller.cproj +++ b/TE_Controller/TE_Controller.cproj @@ -1678,7 +1678,7 @@ 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) {