Added backlight

This commit is contained in:
AlexeiBazlaev 2021-01-27 21:35:04 +07:00
parent a2cd4a6f5e
commit e86661c0b5
17 changed files with 490 additions and 170 deletions

Binary file not shown.

View File

@ -1766,9 +1766,15 @@
<Compile Include="src\include\ntc.h"> <Compile Include="src\include\ntc.h">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
<Compile Include="src\include\power_regulator.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\include\realsence.h"> <Compile Include="src\include\realsence.h">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
<Compile Include="src\include\tcc_user.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\include\tec.h"> <Compile Include="src\include\tec.h">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
@ -1811,9 +1817,15 @@
<Compile Include="src\source\ntc.c"> <Compile Include="src\source\ntc.c">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
<Compile Include="src\source\power_regulator.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\source\realsence.c"> <Compile Include="src\source\realsence.c">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
<Compile Include="src\source\tcc_user.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="src\source\tec.c"> <Compile Include="src\source\tec.c">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>

View File

@ -56,7 +56,7 @@
#define configCPU_CLOCK_HZ ( 48000000) #define configCPU_CLOCK_HZ ( 48000000)
#define configTICK_RATE_HZ ( 1000 ) #define configTICK_RATE_HZ ( 1000 )
#define configMAX_PRIORITIES ( 5 ) #define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 130 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 64 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 4 * 1024 ) ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 4 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 24 ) #define configMAX_TASK_NAME_LEN ( 24 )
#define configUSE_TRACE_FACILITY 1 #define configUSE_TRACE_FACILITY 1

View File

@ -25,4 +25,5 @@ float adc_get_V(uint16_t value);
float adc_get_Q(uint16_t value); float adc_get_Q(uint16_t value);
uint16_t adc_read_value_spec(ADC_chan_t); uint16_t adc_read_value_spec(ADC_chan_t);
float adc_get_V_spec(ADC_chan_t chan); float adc_get_V_spec(ADC_chan_t chan);
#endif /* ADC_H_ */ #endif /* ADC_H_ */

View File

@ -8,10 +8,11 @@
#ifndef MCU_CONTROL_H_ #ifndef MCU_CONTROL_H_
#define MCU_CONTROL_H_ #define MCU_CONTROL_H_
#include "stdint-gcc.h"
#define MAX_STR_FLOAT 12 #define MAX_STR_FLOAT 12
void MCU_control_init(void); void MCU_control_init(void);
void MCU_control(void); void MCU_control(void);
float GetTecCurrent(float currentSenseResistence);
#endif /* MCU_CONTROL_H_ */ #endif /* MCU_CONTROL_H_ */

View File

@ -0,0 +1,20 @@
/*
* power_regulator.h
*
* Created: 18.01.2021 22:07:56
* Author: Lexus
*/
#ifndef POWER_REGULATOR_H_
#define POWER_REGULATOR_H_
#include "stdbool.h"
#include <asf.h>
void temperature_control(float TEC_Temp, float *TEC_Power, bool enable);
//void TEC_power_set(bool value);
#endif /* POWER_REGULATOR_H_ */

View File

@ -0,0 +1,17 @@
/*
* tcc.h
*
* Created: 18.01.2021 22:11:39
* Author: Lexus
*/
#ifndef TCC_H_
#define TCC_H_
#include "tc.h"
void configure_tcc(void);
void print_tcc_status(void);
void configure_tc(void);
void configure_tc_callbacks(void);
void tc_callback(struct tc_module *const module_inst);
#endif /* TCC_H_ */

View File

@ -1,24 +1,22 @@
/** /**
* \file * \file
* *
* \brief CDC Application Main functions * \brief TE_Controller
* *
* Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries. * Copyright (c) 2020-2021 Realsence Inc. and its subsidiaries.
*
* \asf_license_start
* *
* \page License * \page License
* *
* Subject to your compliance with these terms, you may use Microchip * Subject to your compliance with these terms, you may use Realsence
* software and any derivatives exclusively with Microchip products. * software and any derivatives exclusively with Realsence products.
* It is your responsibility to comply with third party license terms applicable * It is your responsibility to comply with third party license terms applicable
* to your use of third party software (including open source software) that * to your use of third party software (including open source software) that
* may accompany Microchip software. * may accompany Realsence software.
* *
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, * THIS SOFTWARE IS SUPPLIED BY Realsence "AS IS". NO WARRANTIES,
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL Realsence BE
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
@ -26,14 +24,9 @@
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*
* \asf_license_stop
*
*/
/*
* Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
*/ */
#include <asf.h> #include <asf.h>
#include "conf_usb.h" #include "conf_usb.h"
#include "ui.h" #include "ui.h"
@ -43,6 +36,13 @@
#include "realsence.h" #include "realsence.h"
#include "ntc.h" #include "ntc.h"
#include <arm_math.h> #include <arm_math.h>
#include "dht.h"
#include "mcu_control.h"
#include "adc_user.h"
#include "power_regulator.h"
#include "tec.h"
#include "backlight.h"
#include "ws2812.h"
#define PORT_STDIO 0 #define PORT_STDIO 0
#define PORT_DATA 1 #define PORT_DATA 1
@ -50,130 +50,38 @@
uint16_t adc_value = 100; uint16_t adc_value = 100;
//char rcvBuff[128] = {0}; //char rcvBuff[128] = {0};
char str[128] = {0}; char str[128] = {0};
UBaseType_t uxHighWaterMark_cdc_rx_check; UBaseType_t uxHighWaterMark_cdc_rx_check, uxHighWaterMark_cdc_tx;
UBaseType_t uxHighWaterMark_led_blink, uxHighWaterMark_mesure; UBaseType_t uxHighWaterMark_led_blink, uxHighWaterMark_mesure, uxHighWaterMark_regulator, uxHighWaterMark_backlight;
static volatile bool main_b_cdc_enable = false; static volatile bool main_b_cdc_enable = false;
struct measured_params m_params; struct measured_params m_params;
Controller_t Controller; Controller_t Controller;
/*! \brief Main function. Execution starts here. /************************************************************************
*/ * \brief Main function. Execution starts here.
************************************************************************/
int main(void) int main(void)
{ {
irq_initialize_vectors(); irq_initialize_vectors();
cpu_irq_enable(); cpu_irq_enable();
// Initialize the sleep manager
sleepmgr_init(); sleepmgr_init();
#if !SAM0
sysclk_init();
board_init();
#else
system_init(); system_init();
#endif
// Start USB stack to authorize VBus monitoring InitTask_cdc_rx_tx();
InitTask_cdc_rx_check();
// Init LED
InitTask_led_blink();//ui_init();//ui_powerdown(); InitTask_led_blink();//ui_init();//ui_powerdown();
InitTask_measure(); InitTask_measure();
InitTask_regulator();
InitTask_backlight();
vTaskStartScheduler(); vTaskStartScheduler();
while(true){ __BKPT();
__BKPT();
}
} }
void Task_cdc_rx_check(void *parameters)
{
#define PORT0 0
iram_size_t len = 0;
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
while(true)
{
if(main_b_cdc_enable &&
(len = udi_cdc_multi_get_nb_received_data(PORT0)) > 0 &&
udi_cdc_read_no_polling(str, (len<=128)?len:128) > 0 )
{
str[len]=0;
printf("<%s\n", str);
}
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
}
}
/*void Task_cdc_rx_check(void *parameters)
{
#define PORT0 0
char rcvBuf[128];
char *pStr = rcvBuf;
int len=0;
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
while(true)
{
if (main_b_cdc_enable)
{
int symb = udi_cdc_getc();
if(symb)
{
len += sprintf(pStr++, "%c", symb);
}
if(symb == '\n')
{
udi_cdc_write_buf(rcvBuf, len);
pStr = rcvBuf;
len = 0;
}
}
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
}
}*/
void InitTask_cdc_rx_check(void)
{
// Enable USB Stack Device
stdio_usb_init();//udc_start();
stdio_usb_enable();
xTaskCreate(Task_cdc_rx_check, (const char*)"Task_cdc_rx_check", configMINIMAL_STACK_SIZE*3, NULL,configMAX_PRIORITIES-1, NULL);
}
void Task_led_blink(void *parameters)
{
//long int c1=0;
//long int c2=0;
int cnt=0;
/* Inspect our own high water mark on entering the task. */
uxHighWaterMark_led_blink = uxTaskGetStackHighWaterMark( NULL );
while(1)
{
if (main_b_cdc_enable && udi_cdc_multi_is_tx_ready(PORT0))
printf(">%u sec\n\r", (cnt++));//// stdio_usb_putchar (NULL, "data");//
vTaskDelay(1000);
LED_Toggle(LED_PIN);
/*if((c1 % 50000) == 0){
//periodic_event_1s();
if(!stdio_cdc_opened){
if(c2 % 2){
set_led(false);
}else{
set_led(true);
}
}else{
if(c2 % 3){
set_led(false);
}else{
set_led(true);
}
}
c2++;
}
c1++;*/
uxHighWaterMark_led_blink = uxTaskGetStackHighWaterMark( NULL );
}
}
/************************************************************************
* \fn void Task_measure(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void Task_measure(void *parameters) void Task_measure(void *parameters)
{ {
uxHighWaterMark_mesure = uxTaskGetStackHighWaterMark( NULL ); uxHighWaterMark_mesure = uxTaskGetStackHighWaterMark( NULL );
@ -181,19 +89,193 @@ void Task_measure(void *parameters)
{ {
Controller.temps.MCU_Temp = NTC_MCU_get_temp(NULL); Controller.temps.MCU_Temp = NTC_MCU_get_temp(NULL);
Controller.temps.TEC_Temp = NTC_TEC_get_temp(NULL, NULL); Controller.temps.TEC_Temp = NTC_TEC_get_temp(NULL, NULL);
if (main_b_cdc_enable && udi_cdc_multi_is_tx_ready(PORT0)) //measurement_DHT22();
{ Controller.tecState.tecV_N = adc_get_V_spec(chan_LFB);
if(fpclassify(Controller.temps.MCU_Temp) == FP_NAN) Controller.tecState.tecV_P = adc_get_V_spec(chan_SFB);
printf(">NTC_MCU_TEMP = NAN\n\r"); Controller.tecState.tecI = GetTecCurrent(CURRENT_SENSE_RESISTENCE);
else
printf(">NTC_MCU_TEMP = %d\n\r", (int)Controller.temps.MCU_Temp);//printf(">NTC_MCU_TEMP = %d, NTC_TEC_TEMP = %d\n\r", (int)Controller.temps.MCU_Temp, (int)Controller.temps.TEC_Temp);
}
LED_Toggle(LED_PIN);
uxHighWaterMark_mesure = uxTaskGetStackHighWaterMark( NULL ); uxHighWaterMark_mesure = uxTaskGetStackHighWaterMark( NULL );
vTaskDelay(1000); vTaskDelay(20);
} }
} }
/************************************************************************
* \fn void Task_regulator(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void Task_regulator(void *parameters)
{
uxHighWaterMark_regulator = uxTaskGetStackHighWaterMark( NULL );
for (;;)
{
temperature_control(Controller.temps.MCU_Temp, &m_params.TEC_Power, ENABLE);
uxHighWaterMark_regulator = uxTaskGetStackHighWaterMark( NULL );
//vTaskDelay(1000);
}
}
/************************************************************************
* \fn void Task_cdc_rx(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void Task_cdc_rx(void *parameters)
{
#define PORT0 0
iram_size_t len = 0;
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
while(true)
{
if(main_b_cdc_enable &&
(len = udi_cdc_multi_get_nb_received_data(PORT0)) > 0 &&
udi_cdc_read_no_polling(str, (len<=128)?len:128) > 0 )
{
str[len]=0;
printf("<%s\n", str);
}
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
}
}
/************************************************************************
* \fn void Task_cdc_tx(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void Task_cdc_tx(void *parameters)
{
#define PORT0 0
uxHighWaterMark_cdc_tx = uxTaskGetStackHighWaterMark( NULL );
while(true)
{
if (main_b_cdc_enable && udi_cdc_multi_is_tx_ready(PORT0))
{
if(fpclassify(Controller.temps.MCU_Temp) == FP_NAN)
printf(">NTC_MCU_TEMP = NAN\n\r");
else
printf(">NTC_MCU_TEMP = %d\n\r", (int)Controller.temps.MCU_Temp);//printf(">NTC_MCU_TEMP = %d, NTC_TEC_TEMP = %d\n\r", (int)Controller.temps.MCU_Temp, (int)Controller.temps.TEC_Temp);
}
LED_Toggle(LED_PIN);
vTaskDelay(1000);
uxHighWaterMark_cdc_tx = uxTaskGetStackHighWaterMark( NULL );
}
}
/************************************************************************
* \fn void Task_led_blink(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void Task_backlight(void *parameters)
{ uint32_t cnt10 = 0;
uxHighWaterMark_backlight = uxTaskGetStackHighWaterMark( NULL );
while(1)
{
backlight_color_show(255, 0, 0);
vTaskDelay(1000);
backlight_color_show(255, 100, 0);
vTaskDelay(1000);
backlight_color_show(0, 255, 0);
vTaskDelay(1000);
/*backlight_event_100ms();
vTaskDelay(100);
if(!((++cnt10)%10))
backlight_event_1s();*/
uxHighWaterMark_backlight = uxTaskGetStackHighWaterMark( NULL );
}
}
/************************************************************************
* \fn void InitTask_cdc_rx_tx(void)
* \brief
* \param
* \return
************************************************************************/
void InitTask_cdc_rx_tx(void)
{
// Enable USB Stack Device
stdio_usb_init();//udc_start();
stdio_usb_enable();
xTaskCreate(Task_cdc_rx, (const char*)"Task_cdc_rx", configMINIMAL_STACK_SIZE*1, NULL,configMAX_PRIORITIES-1, NULL);
xTaskCreate(Task_cdc_tx, (const char*)"Task_cdc_tx", configMINIMAL_STACK_SIZE*3, NULL,configMAX_PRIORITIES-1, NULL);
}
/************************************************************************
* \fn void InitTask_regulator(void)
* \brief
* \param
* \return
************************************************************************/
void InitTask_regulator(void)
{
xTaskCreate(Task_regulator, (const char*)"Task_regulator", configMINIMAL_STACK_SIZE*3, NULL,configMAX_PRIORITIES-1, NULL);
}
/************************************************************************
* \fn void InitTask_measure(void)
* \brief
* \param
* \return
************************************************************************/
void InitTask_measure(void)
{
configure_adc();
xTaskCreate(Task_measure, (const char*)"Task_measure", configMINIMAL_STACK_SIZE*2, NULL,configMAX_PRIORITIES-1, NULL);
}
/************************************************************************
* \fn void InitTask_backlight(void)
* \brief
* \param
* \return
************************************************************************/
void InitTask_backlight(void)
{
ws2812_configure_port_pins();
backlight_init();
backlight_mode_demo();
xTaskCreate(Task_backlight, (const char*)"Task_backlight", configMINIMAL_STACK_SIZE*1, NULL,configMAX_PRIORITIES-1, NULL);
}
/************************************************************************
* \fn void Task_led_blink(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void Task_led_blink(void *parameters)
{
int cnt=0;
uxHighWaterMark_led_blink = uxTaskGetStackHighWaterMark( NULL );
while(1)
{
if (main_b_cdc_enable && udi_cdc_multi_is_tx_ready(PORT0))
printf(">%u sec\n\r", (cnt++));//// stdio_usb_putchar (NULL, "data");//
vTaskDelay(1000);
LED_Toggle(LED_PIN);
uxHighWaterMark_led_blink = uxTaskGetStackHighWaterMark( NULL );
}
}
/************************************************************************
* \fn void Task_led_blink(void *parameters)
* \brief
* \param
* \return
************************************************************************/
void InitTask_led_blink(void) void InitTask_led_blink(void)
{ {
led_configure_port_pins(); led_configure_port_pins();
@ -201,11 +283,7 @@ void InitTask_led_blink(void)
//xTaskCreate(Task_led_blink, (const char*)"Task_led_blink", configMINIMAL_STACK_SIZE*2, NULL,configMAX_PRIORITIES-1, NULL); //xTaskCreate(Task_led_blink, (const char*)"Task_led_blink", configMINIMAL_STACK_SIZE*2, NULL,configMAX_PRIORITIES-1, NULL);
} }
void InitTask_measure(void)
{
configure_adc();
xTaskCreate(Task_measure, (const char*)"Task_measure", configMINIMAL_STACK_SIZE*2, NULL,configMAX_PRIORITIES-1, NULL);
}
void main_suspend_action(void) void main_suspend_action(void)
@ -257,16 +335,7 @@ void main_cdc_disable(uint8_t port)
uart_close(port); uart_close(port);
} }
/*void main_cdc_set_dtr(uint8_t port, bool b_enable)
{
if (b_enable) {
// Host terminal has open COM
ui_com_open(port);
}else{
// Host terminal has close COM
ui_com_close(port);
}
}*/
void main_cdc_set_dtr(uint8_t port, bool b_enable) void main_cdc_set_dtr(uint8_t port, bool b_enable)
{ {
if(port == PORT_STDIO){ if(port == PORT_STDIO){
@ -292,21 +361,42 @@ void led_configure_port_pins(void)
port_pin_set_config(LED_PIN, &config_port_pin); port_pin_set_config(LED_PIN, &config_port_pin);
} }
void vApplicationMallocFailedHook (void) { /************************************************************************
* \fn void vApplicationMallocFailedHook (void)
* \brief
* \param
* \return
************************************************************************/
void vApplicationMallocFailedHook (void)
{
while (1) while (1)
{ {
__BKPT(); __BKPT();
}; };
} }
void vApplicationStackOverflowHook (void) { /************************************************************************
* \fn void vApplicationStackOverflowHook (void)
* \brief
* \param
* \return
************************************************************************/
void vApplicationStackOverflowHook (void)
{
while (1) while (1)
{ {
__BKPT(); __BKPT();
}; };
} }
void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress) { /************************************************************************
* \fn void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress)
* \brief
* \param
* \return
************************************************************************/
void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress)
{
__attribute__((unused)) volatile uint32_t r0; __attribute__((unused)) volatile uint32_t r0;
__attribute__((unused)) volatile uint32_t r1; __attribute__((unused)) volatile uint32_t r1;
__attribute__((unused)) volatile uint32_t r2; __attribute__((unused)) volatile uint32_t r2;
@ -407,3 +497,42 @@ void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress) {
* - conf_foo.h configuration of each module * - conf_foo.h configuration of each module
* - ui.c implement of user's interface (leds,buttons...) * - ui.c implement of user's interface (leds,buttons...)
*/ */
/*void Task_cdc_rx(void *parameters)
{
#define PORT0 0
char rcvBuf[128];
char *pStr = rcvBuf;
int len=0;
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
while(true)
{
if (main_b_cdc_enable)
{
int symb = udi_cdc_getc();
if(symb)
{
len += sprintf(pStr++, "%c", symb);
}
if(symb == '\n')
{
udi_cdc_write_buf(rcvBuf, len);
pStr = rcvBuf;
len = 0;
}
}
uxHighWaterMark_cdc_rx_check = uxTaskGetStackHighWaterMark( NULL );
}
}*/
/*void main_cdc_set_dtr(uint8_t port, bool b_enable)
{
if (b_enable) {
// Host terminal has open COM
ui_com_open(port);
}else{
// Host terminal has close COM
ui_com_close(port);
}
}*/

View File

@ -39,6 +39,10 @@
#include "usb_protocol_cdc.h" #include "usb_protocol_cdc.h"
#define CURRENT_SENSE_RESISTENCE 0.005f
#define TEC_TEMP_MAX 35.0f
#define TEC_TEMP_MIN 5.0f
#define TEC_TEMP_NORM 25.0f
typedef struct measured_params{ typedef struct measured_params{
float TEC_Temp; float TEC_Temp;
@ -62,9 +66,11 @@ typedef struct
typedef struct typedef struct
{ {
float tecV; float tecV_P;
float tecV_N;
float tecI; float tecI;
} TecState_t; } TecState_t;
typedef struct typedef struct
{ {
Temperatures_t temps; Temperatures_t temps;
@ -75,14 +81,18 @@ void prvGetRegistersFromStack (uint32_t *pulFaultStackAddress);
void led_configure_port_pins(void); void led_configure_port_pins(void);
void vApplicationMallocFailedHook (void); void vApplicationMallocFailedHook (void);
void vApplicationStackOverflowHook (void); void vApplicationStackOverflowHook (void);
void Task_cdc_rx_check(void *parameters); void Task_cdc_rx(void *parameters);
void Task_cdc_tx(void *parameters);
void Task_led_blink(void *parameters); void Task_led_blink(void *parameters);
void Task_measure(void *parameters); void Task_measure(void *parameters);
void Task_regulator(void *parameters); void Task_regulator(void *parameters);
void InitTask_cdc_rx_check(void); void Task_backlight(void *parameters);
void InitTask_backlight(void);
void InitTask_cdc_rx(void);
void InitTask_led_blink(void); void InitTask_led_blink(void);
void InitTask_regulator(void); void InitTask_regulator(void);
void InitTask_measure(void); void InitTask_measure(void);
void InitTask_cdc_rx_tx(void);
/*! \brief Opens the communication port /*! \brief Opens the communication port
* This is called by CDC interface when USB Host enable it. * This is called by CDC interface when USB Host enable it.

View File

@ -39,12 +39,6 @@ void configure_adc(void)
//adc_start_conversion(&adc_instance); //adc_start_conversion(&adc_instance);
} }
/*uint16_t adc_read_value(void)
{
uint16_t result = 0xFFFF;
adc_read(&adc_instance, &result);
return result;
}*/
uint16_t adc_read_value(void){ uint16_t adc_read_value(void){
adc_start_conversion(&adc_instance); adc_start_conversion(&adc_instance);
uint16_t result; uint16_t result;
@ -72,3 +66,8 @@ float adc_get_V(uint16_t value)
float Uvcc=3.3; float Uvcc=3.3;
return adc_get_Q(value) * Uvcc; return adc_get_Q(value) * Uvcc;
} }
float adc_get_V_spec(ADC_chan_t chan){
uint16_t value = adc_read_value_spec(chan);
return adc_get_V(value);
}

View File

@ -31,7 +31,7 @@ void backlight_event_100ms(void){
led_data[0 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00; led_data[0 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
led_data[1 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0xff; led_data[1 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0xff;
led_data[2 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00; led_data[2 + (LEN_WS2812/2 - i - 1)*3 + (LEN_WS2812/2)*3] = 0x00;
}else{ }else{
led_data[0 + i*3] = 0x00; led_data[0 + i*3] = 0x00;
led_data[1 + i*3] = 0x00; led_data[1 + i*3] = 0x00;
led_data[2 + i*3] = 0x00; led_data[2 + i*3] = 0x00;
@ -63,31 +63,31 @@ void backlight_event_1s(void){
led_data[1 + i*3] = 0xff; led_data[1 + i*3] = 0xff;
led_data[2 + i*3] = 0xff; led_data[2 + i*3] = 0xff;
} }
}else if((s1_cnt % modes) == 1){ }else if((s1_cnt % modes) == 1){
for(uint16_t i=0; i < LEN_WS2812;i++){ for(uint16_t i=0; i < LEN_WS2812;i++){
led_data[0 + i*3] = 0xff; led_data[0 + i*3] = 0xff;
led_data[1 + i*3] = 0x00; led_data[1 + i*3] = 0x00;
led_data[2 + i*3] = 0x00; led_data[2 + i*3] = 0x00;
} }
}else if((s1_cnt % modes) == 2){ }else if((s1_cnt % modes) == 2){
for(uint16_t i=0; i < LEN_WS2812;i++){ for(uint16_t i=0; i < LEN_WS2812;i++){
led_data[0 + i*3] = 0x00; led_data[0 + i*3] = 0x00;
led_data[1 + i*3] = 0xff; led_data[1 + i*3] = 0xff;
led_data[2 + i*3] = 0x00; led_data[2 + i*3] = 0x00;
} }
}else if((s1_cnt % modes) == 3){ }else if((s1_cnt % modes) == 3){
for(uint16_t i=0; i < LEN_WS2812;i++){ for(uint16_t i=0; i < LEN_WS2812;i++){
led_data[0 + i*3] = 0x00; led_data[0 + i*3] = 0x00;
led_data[1 + i*3] = 0x00; led_data[1 + i*3] = 0x00;
led_data[2 + i*3] = 0xff; led_data[2 + i*3] = 0xff;
} }
}else if((s1_cnt % modes) == 4){ }else if((s1_cnt % modes) == 4){
for(uint16_t i=0; i < LEN_WS2812;i++){ for(uint16_t i=0; i < LEN_WS2812;i++){
led_data[0 + i*3] = 0x00; led_data[0 + i*3] = 0x00;
led_data[1 + i*3] = 0x00; led_data[1 + i*3] = 0x00;
led_data[2 + i*3] = 0x00; led_data[2 + i*3] = 0x00;
} }
}else if((s1_cnt % modes) == 5){ }else if((s1_cnt % modes) == 5){
mode_run_light=true; mode_run_light=true;
mode_run_light_cnt=0; mode_run_light_cnt=0;
} }
@ -111,13 +111,14 @@ void backlight_init(void){
} }
void backlight_ws2812_sendarray(void){ void backlight_ws2812_sendarray(void){
cpu_irq_disable(); portENTER_CRITICAL();//cpu_irq_disable();
ws2812_sendarray(led_data,sizeof(led_data)); ws2812_sendarray(led_data,sizeof(led_data));
cpu_irq_enable(); portEXIT_CRITICAL();//cpu_irq_enable();
} }
void backlight_color_show(uint8_t R, uint8_t G, uint8_t B){ void backlight_color_show(uint8_t R, uint8_t G, uint8_t B){
for(uint16_t i=0; i < LEN_WS2812; i++){ for(uint16_t i=0; i < LEN_WS2812; i++)
{
led_data[0 + i*3] = G; led_data[0 + i*3] = G;
led_data[1 + i*3] = R; led_data[1 + i*3] = R;
led_data[2 + i*3] = B; led_data[2 + i*3] = B;

View File

@ -10,7 +10,7 @@
#define lineDown() port_pin_set_output_level(DHT_Pin, 0) #define lineDown() port_pin_set_output_level(DHT_Pin, 0)
#define lineUp() port_pin_set_output_level(DHT_Pin, 1) #define lineUp() port_pin_set_output_level(DHT_Pin, 1)
#define getLine() port_pin_get_input_level(DHT_Pin) #define getLine() port_pin_get_input_level(DHT_Pin)
#define Delay(d) delay_ms(d) #define Delay(d) vTaskDelay(d)
#define CPU_IRQ_enable() cpu_irq_enable() #define CPU_IRQ_enable() cpu_irq_enable()
#define CPU_IRQ_disable() cpu_irq_disable() #define CPU_IRQ_disable() cpu_irq_disable()
@ -37,9 +37,9 @@ static void goToInput(void) {
uint8_t DHT_getData(DHT_type t, DHT_data* p_data){ uint8_t DHT_getData(DHT_type t, DHT_data* p_data){
uint8_t ret; uint8_t ret;
CPU_IRQ_disable(); //CPU_IRQ_disable();
ret = _DHT_getData(t, p_data); ret = _DHT_getData(t, p_data);
CPU_IRQ_enable(); //CPU_IRQ_enable();
return ret; return ret;
} }

View File

@ -30,7 +30,6 @@
#define ws2812_DEL ws2812_DEL8 ws2812_DEL2 #define ws2812_DEL ws2812_DEL8 ws2812_DEL2
void ws2812_sendarray(uint8_t *data,int datlen) void ws2812_sendarray(uint8_t *data,int datlen)
{ {
uint8_t gpio_pin = PIN_PA23; uint8_t gpio_pin = PIN_PA23;

View File

@ -11,11 +11,16 @@
#include "adn8831.h" #include "adn8831.h"
#include "tm_onewire.h" #include "tm_onewire.h"
#include "tm_ds18b20.h" #include "tm_ds18b20.h"
#include "adc_user.h"
void MCU_control_init(void){ void MCU_control_init(void){
} }
float GetTecCurrent(float currentSenseResistence)
{
return adc_get_V_spec(chan_CS)/currentSenseResistence;
}
void MCU_control(void){ void MCU_control(void){
char t_TEC_str[MAX_STR_FLOAT]; char t_TEC_str[MAX_STR_FLOAT];
char t_MCU_str[MAX_STR_FLOAT]; char t_MCU_str[MAX_STR_FLOAT];
@ -56,7 +61,7 @@ void MCU_control(void){
char DS1820_Temp_str[MAX_STR_FLOAT]; char DS1820_Temp_str[MAX_STR_FLOAT];
//bool ow_connected __attribute__((used)) =false; //bool ow_connected __attribute__((used)) =false;
float DS1820_temp=0.0; float DS1820_temp=0.0;
cpu_irq_disable(); //cpu_irq_disable();
if (TM_OneWire_First(&ow_instance)) { if (TM_OneWire_First(&ow_instance)) {
//ow_connected=true; //ow_connected=true;
if(TM_DS18B20_Is(ow_instance.ROM_NO)){ if(TM_DS18B20_Is(ow_instance.ROM_NO)){
@ -71,7 +76,7 @@ void MCU_control(void){
} }
} }
} }
cpu_irq_enable(); //cpu_irq_enable();
make_float2str(DS1820_Temp_str, MAX_STR_FLOAT, (float)DS1820_temp); make_float2str(DS1820_Temp_str, MAX_STR_FLOAT, (float)DS1820_temp);
// printf("Info: t_MCU: %10s, t_TEC:%10s, Vin_LFB: %6s, Vin_SFB: %6s, Vin_CS: %6s, DHT22_Temp: %s, DHT22_Hum: %s, OW_STATE: %d, DS1820_Temp: %s\r\n",t_MCU_str, t_TEC_str, Vin_LFB_str, Vin_SFB_str, Vin_CS_str, DHT22_Temp, DHT22_Hum, (int)ow_connected, DS1820_Temp_str); // printf("Info: t_MCU: %10s, t_TEC:%10s, Vin_LFB: %6s, Vin_SFB: %6s, Vin_CS: %6s, DHT22_Temp: %s, DHT22_Hum: %s, OW_STATE: %d, DS1820_Temp: %s\r\n",t_MCU_str, t_TEC_str, Vin_LFB_str, Vin_SFB_str, Vin_CS_str, DHT22_Temp, DHT22_Hum, (int)ow_connected, DS1820_Temp_str);

View File

@ -0,0 +1,43 @@
/*
* power_regulator.c
*
* Created: 18.01.2021 22:07:23
* Author: Lexus
*/
#include "power_regulator.h"
#include <math.h>
#include "tec.h"
struct tcc_module tcc_instance;
void temperature_control(float TEC_Temp, float *TEC_Power, bool enable)
{
if(!enable)
{
TEC_set_level(0);
return;
}
float temp_goal=10;
float temp_diff = (temp_goal - TEC_Temp)*1;
float TEC_intensity_max=0.5;
float TEC_power_calc = *TEC_Power;
float K=1.0/10.0; // 100% power per 20 grad.
float Power = K*temp_diff;
if(Power > 1.0) Power = 1.0;
if(Power < -1.0) Power = -1.0;
TEC_power_calc = Power*TEC_intensity_max;
if(fabsf(fabsf(TEC_power_calc) - fabsf(*TEC_Power)) > 0.010)//(isless(TEC_power_calc,*TEC_Power) || isgreater(TEC_power_calc,*TEC_Power))
{
*TEC_Power = TEC_power_calc;
TEC_set_level(*TEC_Power);
}
}
/*void TEC_power_set(bool value){
TEC_power = value;
}*/

View File

@ -0,0 +1,78 @@
/*
* tcc.c
*
* Created: 18.01.2021 22:11:12
* Author: Lexus
*/
#include "tcc_user.h"
#include "stdbool.h"
#include <asf.h>
struct tcc_module tcc_instance;
struct tc_module tc_instance;
bool tc_callback_flag=false;
void configure_tcc(void)
{
struct tcc_config config_tcc;
tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE);
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1;
config_tcc.counter.period = PWM_GCLK_PERIOD;
config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
tcc_init(&tcc_instance, CONF_PWM_MODULE, &config_tcc);
tcc_enable(&tcc_instance);
}
void print_tcc_status(void){
uint32_t tcc_status, tcc_counter;
uint16_t ch;
tcc_status = tcc_get_status(&tcc_instance);
tcc_counter = tcc_get_count_value(&tcc_instance);
printf("TCC: CNT: %6ld, STATUS: %10ld, SYNC_READY: %d, CAPTURE_OVERFLOW: %d, COUNTER_EVENT: %d, COUNTER_RETRIGGERED: %d, COUNT_OVERFLOW: %d, RAMP_CYCLE_INDEX: %d, STOPPED: %d\r\n", tcc_counter, tcc_status,
(int)((tcc_status & TCC_STATUS_SYNC_READY)?1:0),
(int)((tcc_status & TCC_STATUS_CAPTURE_OVERFLOW)?1:0),
(int)((tcc_status & TCC_STATUS_COUNTER_EVENT)?1:0),
(int)((tcc_status & TCC_STATUS_COUNTER_RETRIGGERED)?1:0),
(int)((tcc_status & TCC_STATUS_COUNT_OVERFLOW)?1:0),
(int)((tcc_status & TCC_STATUS_RAMP_CYCLE_INDEX)?1:0),
(int)((tcc_status & TCC_STATUS_STOPPED)?1:0)
);
for(ch=0;ch<4;ch++){
printf("channel: %d, CHANNEL_MATCH_CAPTURE: %d, CHANNEL_OUTPUT: %d\r\n", ch,
(int)((tcc_status & TCC_STATUS_CHANNEL_MATCH_CAPTURE(ch))?1:0),
(int)((tcc_status & TCC_STATUS_CHANNEL_OUTPUT(ch))?1:0)
);
}
}
void configure_tc(void)
{
struct tc_config config_tc;
tc_get_config_defaults(&config_tc);
config_tc.counter_size = TC_COUNTER_SIZE_16BIT;
config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1024;
config_tc.counter_16_bit.compare_capture_channel[0] = 4687; // 1000ms
tc_init(&tc_instance, TC3, &config_tc);
tc_enable(&tc_instance);
}
void tc_callback(struct tc_module *const module_inst){
tc_callback_flag=true;
tc_set_count_value(&tc_instance, 0);
}
void configure_tc_callbacks(void)
{
tc_register_callback(
&tc_instance,
tc_callback,
TC_CALLBACK_CC_CHANNEL0);
tc_enable_callback(&tc_instance, TC_CALLBACK_CC_CHANNEL0);
}

View File

@ -65,31 +65,34 @@ void pin_set_output(uint8_t pin, bool output_flag, uint8_t value){
port_pin_set_config(pin, &config_port_pin); port_pin_set_config(pin, &config_port_pin);
} }
// Range from -1 to 0 // Range from -1 to 1
void TEC_set_level(float value){ void TEC_set_level(float value)
{
tcc_reset(&tcc_instance); tcc_reset(&tcc_instance);
if(fpclassify(value) == FP_ZERO){//if(value == (float)0.0){// if(fpclassify(value) == FP_ZERO || fpclassify(value) == FP_NAN)
// TEC OFF {
pin_set_output(PIN_SPGATE, true, 1); pin_set_output(PIN_SPGATE, true, 1);
pin_set_output(PIN_SNGATE, true, 0); pin_set_output(PIN_SNGATE, true, 0);
pin_set_output(PIN_LPGATE, true, 1); pin_set_output(PIN_LPGATE, true, 1);
pin_set_output(PIN_LNGATE, true, 0); pin_set_output(PIN_LNGATE, true, 0);
}else{ }
else
{
struct port_config config_port_pin; struct port_config config_port_pin;
port_get_config_defaults(&config_port_pin); port_get_config_defaults(&config_port_pin);
config_port_pin.direction = PORT_PIN_DIR_INPUT; config_port_pin.direction = PORT_PIN_DIR_INPUT;
config_port_pin.input_pull = PORT_PIN_PULL_NONE; config_port_pin.input_pull = PORT_PIN_PULL_NONE;
port_pin_set_config(PIN_SNGATE, &config_port_pin); port_pin_set_config(PIN_SNGATE, &config_port_pin);
struct tcc_config config_tcc; struct tcc_config config_tcc;
tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE); tcc_get_config_defaults(&config_tcc, CONF_PWM_MODULE);
config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1; config_tcc.counter.clock_prescaler = TCC_CLOCK_PRESCALER_DIV1;
config_tcc.counter.period = PWM_GCLK_PERIOD; config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
config_tcc.counter.period = PWM_GCLK_PERIOD;
config_tcc.compare.wave_generation = TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM;
uint8_t pin_output, chan; uint8_t pin_output, chan;
if(value > 0.0){ if(value > 0.0)
{
TEC_L_set(true); // to +12 TEC_L_set(true); // to +12
pin_set_output(PIN_SPGATE, true, 1); pin_set_output(PIN_SPGATE, true, 1);
pin_set_output(PIN_SNGATE, false, 0); pin_set_output(PIN_SNGATE, false, 0);
@ -99,7 +102,9 @@ void TEC_set_level(float value){
config_tcc.pins.wave_out_pin_mux[pin_output] = MUX_PA17F_TCC0_WO7; config_tcc.pins.wave_out_pin_mux[pin_output] = MUX_PA17F_TCC0_WO7;
config_tcc.compare.match[chan] = PWM_GCLK_PERIOD*value; config_tcc.compare.match[chan] = PWM_GCLK_PERIOD*value;
}else{ }
else
{
TEC_L_set(false); // to GND TEC_L_set(false); // to GND
pin_set_output(PIN_SPGATE, false, 0); pin_set_output(PIN_SPGATE, false, 0);
pin_set_output(PIN_SNGATE, true, 0); pin_set_output(PIN_SNGATE, true, 0);