mov det temperature sample from internal ADC to LTC1867
This commit is contained in:
parent
8ebe10e99f
commit
23c8d51951
@ -2,6 +2,8 @@ include_directories(.)
|
||||
include_directories(../../driver/stddriver/inc)
|
||||
include_directories(../../driver/cmsis/inc)
|
||||
|
||||
add_definitions(-DDET_TEMPERATURE_LTC1867)
|
||||
|
||||
file(GLOB FILELIST
|
||||
device.c
|
||||
user_misc.c
|
||||
|
||||
@ -14,6 +14,7 @@ A3 = 7.7743300e-8*/
|
||||
static float Ncp15wCoeff[4] = {2.3088245e-3, 2.1731924e-4, 1.7282124e-6, 7.7743300e-8};
|
||||
static uint16_t adc_data[4][12] __attribute__((section(".bss_ccm")));
|
||||
static uint16_t adc_data_sort[12] __attribute__((section(".bss_ccm")));
|
||||
uint16_t adc_det_temp_from_ltc1867 __attribute__((section(".bss_ccm")));
|
||||
|
||||
float adc_to_resistance(uint16_t adc_value)
|
||||
{
|
||||
@ -25,6 +26,16 @@ float adc_to_resistance(uint16_t adc_value)
|
||||
return (float)value1 / (float)value2;
|
||||
}
|
||||
|
||||
float adc_to_resistance16(uint16_t adc_value)
|
||||
{
|
||||
uint32_t value1, value2;
|
||||
|
||||
value1 = 100 * (uint32_t)adc_value;
|
||||
value2 = 65536 - (uint32_t)adc_value;
|
||||
|
||||
return (float)value1 / (float)value2;
|
||||
}
|
||||
|
||||
uint32_t adc_rtot(uint16_t adc_value)
|
||||
{
|
||||
int i = 0;
|
||||
@ -42,6 +53,23 @@ uint32_t adc_rtot(uint16_t adc_value)
|
||||
return (uint32_t)t;
|
||||
}
|
||||
|
||||
uint32_t adc_rtot16(uint16_t adc_value)
|
||||
{
|
||||
int i = 0;
|
||||
float t = 0;
|
||||
float rtemp;
|
||||
|
||||
rtemp = adc_to_resistance16(adc_value);
|
||||
rtemp = logf(rtemp);
|
||||
|
||||
for(i = 3; i >= 0; i--) {
|
||||
t = t * rtemp + Ncp15wCoeff[i];
|
||||
}
|
||||
t = 100.0f / t; /* unit: 0.01K */
|
||||
|
||||
return (uint32_t)t;
|
||||
}
|
||||
|
||||
void adc_input_data(uint8_t ch, uint16_t data)
|
||||
{
|
||||
static uint8_t idx[4] = {0, 0, 0, 0};
|
||||
@ -56,7 +84,7 @@ void adc_input_data(uint8_t ch, uint16_t data)
|
||||
uint16_t adc_get_filter_data(uint8_t ch)
|
||||
{
|
||||
uint32_t i, j, min_idx;
|
||||
uint16_t sum;
|
||||
uint32_t sum;
|
||||
|
||||
/* copy data to buffer */
|
||||
for (i = 0; i < ADC_FILTER_LEN - 1; i++) {
|
||||
@ -81,8 +109,8 @@ uint16_t adc_get_filter_data(uint8_t ch)
|
||||
for (i = 2; i < ADC_FILTER_LEN - 2; i++) {
|
||||
sum += adc_data_sort[i];
|
||||
}
|
||||
sum = (sum + 4) / (ADC_FILTER_LEN - 4);
|
||||
return sum;
|
||||
sum = (sum + (ADC_FILTER_LEN - 4) / 2) / (ADC_FILTER_LEN - 4);
|
||||
return (uint16_t)sum;
|
||||
}
|
||||
|
||||
void adc_init(void)
|
||||
@ -142,10 +170,20 @@ void adc_loop(void)
|
||||
}
|
||||
ms = system_tick_cnt;
|
||||
val = adc_read();
|
||||
#ifdef DET_TEMPERATURE_LTC1867
|
||||
if (ch == 0) {
|
||||
val = adc_det_temp_from_ltc1867;
|
||||
}
|
||||
#endif
|
||||
debug_write_data(20 + ch, (float)val);
|
||||
adc_input_data(ch, val); /* input data from ADC to sort buffer */
|
||||
if (ch == 0) {
|
||||
val = adc_get_filter_data(ch);
|
||||
#ifdef DET_TEMPERATURE_LTC1867
|
||||
value = adc_rtot16(val);
|
||||
#else
|
||||
value = adc_rtot(val);
|
||||
#endif
|
||||
value = adc_rtot(val);
|
||||
debug_write_data(24 + ch, (float)value);
|
||||
device_data.detector_temperature = value;
|
||||
|
||||
@ -12,7 +12,9 @@
|
||||
extern uint32_t system_tick_cnt;
|
||||
|
||||
float adc_to_resistance(uint16_t adc_value);
|
||||
float adc_to_resistance16(uint16_t adc_value);
|
||||
uint32_t adc_rtot(uint16_t adc_value);
|
||||
uint32_t adc_rtot16(uint16_t adc_value);
|
||||
void adc_input_data(uint8_t ch, uint16_t data);
|
||||
uint16_t adc_get_filter_data(uint8_t ch);
|
||||
void adc_init(void);
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#define diff32768(data) ((data > 32768) ? (data - 32768) : (32768 - data))
|
||||
|
||||
struct data_ltc1867_s data_ltc1867 __attribute__((section(".bss_ccm")));
|
||||
static const uint16_t ltc1867_spi_data[4] = {0xC400, 0x9400, 0xD400, 0x8400}; /* order: ch1, ch2, ch3, ch0 */
|
||||
static const uint16_t ltc1867_spi_data[LTC1867_CH_CNT] = {0xC400, 0x9400, 0xD400, 0xA400, 0x8400}; /* order: ch1, ch2, ch3, ch4, ch0 */
|
||||
|
||||
void ltc1867_init(void)
|
||||
{
|
||||
@ -98,7 +98,7 @@ void ltc1867_init(void)
|
||||
SPI_Init(SPI1, &SPI_InitStructure);
|
||||
SPI_Cmd(SPI1, ENABLE);
|
||||
ltc1867_spi_select();
|
||||
ltc1867_transfer(ltc1867_spi_data[3]);
|
||||
ltc1867_transfer(ltc1867_spi_data[LTC1867_CH_CNT - 1]);
|
||||
|
||||
/* data_ltc1867 init */
|
||||
data_ltc1867.sum[0] = 0; /* store temporary sum of half period sum */
|
||||
@ -175,7 +175,7 @@ uint16_t ltc1867_transfer(uint16_t data_send)
|
||||
|
||||
void TIM2_IRQHandler(void)
|
||||
{
|
||||
uint16_t val[4];
|
||||
uint16_t val[LTC1867_CH_CNT];
|
||||
|
||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
|
||||
|
||||
@ -188,8 +188,8 @@ void TIM2_IRQHandler(void)
|
||||
data_ltc1867.ledir_cnt = 0;
|
||||
}
|
||||
|
||||
/* sample 4 channel adc data */
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
/* sample 5 channel adc data */
|
||||
for (uint8_t i = 0; i < LTC1867_CH_CNT; i++) {
|
||||
ltc1867_conv(); /* this point start convert */
|
||||
ltc1867_delay(); /* delay 3.5us for convert time, reference for LTC1867 datasheet */
|
||||
ltc1867_spi_select(); /* convert complete, make convert pin low for reading sample data by SPI */
|
||||
@ -198,8 +198,9 @@ void TIM2_IRQHandler(void)
|
||||
/* split 2 for loop, because sample timing is strict, only place important code in sample duration */
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
data_ltc1867.sum[i] += diff32768(val[i]); /* add every channel original data for next process */
|
||||
debug_write_data(i, (float)val[i]); /* channel 1~4 for ltc1867 original sample data */
|
||||
debug_write_data(i, (float)val[i]); /* channel 0~3 for ltc1867 original sample data */
|
||||
}
|
||||
adc_det_temp_from_ltc1867 = val[4]; /* channel 4 for ltc1867 detector temperature sample data */
|
||||
data_ltc1867.val_idx++;
|
||||
if ((data_ltc1867.val_idx >= CALC_CNT) && (data_ltc1867.locked != 0)) {
|
||||
data_ltc1867.val_idx = 0;
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
#define TIMER_PERIOD_SAMPLE (TIMER_SRC_FREQ / LEDIR_FREQ / SAMPLES_PER_PERIOD - 1)
|
||||
#define TIMER_PERIOD_DELAY (TIMER_SRC_FREQ / 1000 / 1000 * 35 / 10 - 1) /* 3.5us */
|
||||
|
||||
#define LTC1867_CH_CNT (5)
|
||||
|
||||
#define PORT_LEDIR (GPIOB)
|
||||
#define PIN_LEDIR (GPIO_Pin_0)
|
||||
#define PORT_LTC1867 (GPIOA)
|
||||
@ -32,6 +34,7 @@ struct data_ltc1867_s {
|
||||
};
|
||||
|
||||
extern struct data_ltc1867_s data_ltc1867;
|
||||
extern uint16_t adc_det_temp_from_ltc1867;
|
||||
|
||||
void ltc1867_init(void);
|
||||
void ltc1867_ledir_on(void);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user