Add calibration routine from shell

This commit is contained in:
Mario Hüttel 2020-02-15 17:53:15 +01:00
parent 5a00950589
commit c565dab3ad
7 changed files with 23 additions and 16 deletions

View File

@ -11,4 +11,7 @@
#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif /* __HELPER_MACROS_H__ */

View File

@ -20,13 +20,16 @@
#ifndef __CALIBRATION_H__
#define __CALIBRATION_H__
#define CALIBRATION_MAX_STDDEV_OHM 1.0f
#define CALIBRATION_MAX_PEAK_PEAK_NOISE_OHM 8.0f
#include <stdint.h>
#include <shellmatta.h>
void calibration_calculate(float low_measured, float low_setpoint, float high_measured, float high_setpoint,
float *sens_deviation, float *sens_corrected_offset);
int calibration_acquire_data(float *mu, float *sigma, uint32_t count);
int calibration_acquire_data(float *mu, float *max_dev, uint32_t count);
int calibration_sequence_shell_cmd(shellmatta_handle_t shell);
#endif /* __CALIBRATION_H__ */

View File

@ -51,7 +51,7 @@ int dma_ring_buffer_periph_to_mem_initialize(struct dma_ring_buffer_to_mem *dma_
* @param[in] buff Ring buffer structure
* @param[out] data_buff Pointer to set to new data. This must not be modified!
* @param[out] len Length in elements
* @return 0 if successful (data, no data), -1 if error, and 1 if data with wrap around. Call function again in this case to retrieve rest after wrap around.
* @return 0 if successful, but no data), -1 if error, 1 if data, and 2 if data with wrap around. Call function again in this case to retrieve rest after wrap around.
*/
int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff, const void **data_buff, size_t *len);

View File

@ -31,6 +31,7 @@ int main()
const char *uart_input;
size_t uart_input_len;
shellmatta_handle_t shell_handle;
int uart_receive_status;
setup_nvic_priorities();
systick_setup();
@ -51,10 +52,9 @@ int main()
while(1) {
pt1000_value_status = adc_pt1000_get_current_resistance(&pt1000_value);
if (uart_receive_data_with_dma(&uart_input, &uart_input_len) >= 0) {
uart_receive_status = uart_receive_data_with_dma(&uart_input, &uart_input_len);
if (uart_receive_status >= 1)
shell_handle_input(shell_handle, uart_input, uart_input_len);
}
//systick_wait_ms(300);
}
}

View File

@ -152,14 +152,14 @@ static shellmatta_retCode_t shell_cmd_uptime(const shellmatta_handle_t handle,
return SHELLMATTA_OK;
}
static shellmatta_retCode_t shell_cmd_acquire_val(const shellmatta_handle_t handle,
static shellmatta_retCode_t shell_cmd_cal(const shellmatta_handle_t handle,
const char *arguments,
uint32_t length)
{
float mu, sigma;
(void)arguments;
(void)length;
calibration_acquire_data(&mu, &sigma, 128U);
shellmatta_printf(handle, "mu: %.2f\r\nsigma: %.3f\r\n", mu, sigma);
calibration_sequence_shell_cmd(handle);
return SHELLMATTA_OK;
}
//typedef struct shellmatta_cmd
@ -222,11 +222,11 @@ static shellmatta_cmd_t cmd[7] = {
.next = &cmd[6],
},
{
.cmd = "pt1000-acquire",
.cmdAlias = "ptac",
.helpText = "Acquire 128 samples",
.cmd = "calibrate",
.cmdAlias = "cal",
.helpText = "Calibrate resistance measurement",
.usageText = "",
.cmdFct = shell_cmd_acquire_val,
.cmdFct = shell_cmd_cal,
.next = NULL,
}
};

View File

@ -81,11 +81,12 @@ int dma_ring_buffer_periph_to_mem_get_data(struct dma_ring_buffer_to_mem *buff,
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
*len = buff->buffer_count - buff->get_idx;
buff->get_idx = 0;
ret_code = 1;
ret_code = 2;
} else if (put_idx > buff->get_idx) {
*data_buff = &(((char *)buff->data_ptr)[buff->get_idx * buff->element_size]);
*len = put_idx - buff->get_idx;
buff->get_idx += *len;
ret_code = 1;
} else {
/* No new data */
*len = 0;

View File

@ -67,6 +67,6 @@ int _read(void)
int _write(int fd, const void *buf, int count)
{
if (fd == 1)
uart_send_array((char*)buf, count);
uart_send_array_with_dma((char*)buf, count);
return count;
}