2020-02-15 22:09:55 +01:00
|
|
|
/* Reflow Oven Controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2020 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* This file is part of the Reflow Oven Controller Project.
|
|
|
|
*
|
|
|
|
* The reflow oven controller is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with the reflow oven controller project.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-02-02 00:01:08 +01:00
|
|
|
#ifndef __ADCMEAS_H__
|
|
|
|
#define __ADCMEAS_H__
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2020-02-12 21:00:35 +01:00
|
|
|
#include <stm32/stm32f4xx.h>
|
2020-02-02 00:46:12 +01:00
|
|
|
/**
|
|
|
|
* @brief Moving average filter coefficient for PT1000 measurement
|
|
|
|
*/
|
2020-02-02 00:01:08 +01:00
|
|
|
#define ADC_PT1000_FILTER_WEIGHT 0.005f
|
|
|
|
|
2020-02-02 00:46:12 +01:00
|
|
|
/**
|
|
|
|
* @brief ADC channel number of PT1000 sensor input
|
|
|
|
*/
|
2020-02-05 23:09:23 +01:00
|
|
|
#define ADC_PT1000_CHANNEL 2U
|
2020-02-02 00:46:12 +01:00
|
|
|
|
2020-02-02 01:49:37 +01:00
|
|
|
#define ADC_PT1000_PORT GPIOA
|
|
|
|
#define ADC_PT1000_PORT_RCC_MASK RCC_AHB1ENR_GPIOAEN
|
|
|
|
|
2020-02-05 23:09:23 +01:00
|
|
|
#define ADC_PT1000_PIN 2U
|
2020-02-02 01:49:37 +01:00
|
|
|
|
2020-02-05 23:09:23 +01:00
|
|
|
#define ADC_FILTER_STARTUP_CYCLES 800U
|
2020-02-02 20:24:44 +01:00
|
|
|
|
2020-02-05 23:09:23 +01:00
|
|
|
#define ADC_PT1000_SAMPLE_CNT_DELAY 1000U
|
|
|
|
|
|
|
|
#define ADC_PT1000_DMA_AVG_SAMPLES 6U
|
2020-02-02 01:49:37 +01:00
|
|
|
|
2020-02-02 00:46:12 +01:00
|
|
|
/**
|
|
|
|
* @brief Lower value for valid input range for PT1000 measurement
|
|
|
|
*
|
|
|
|
* If the input of the PT1000 sensor is below this value, an error is thrown. This is used to disable the temperature control loop
|
|
|
|
*/
|
2020-02-05 23:09:23 +01:00
|
|
|
#define ADC_PT1000_LOWER_WATCHDOG 200U
|
2020-02-02 00:46:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Upper value for valid input range for PT1000 measurement
|
|
|
|
*
|
|
|
|
* If the input of the PT1000 sensor is above this value, an error is thrown. This is used to disable the temperature control loop
|
|
|
|
*/
|
2020-02-05 23:09:23 +01:00
|
|
|
#define ADC_PT1000_UPPER_WATCHDOG 4000U
|
2020-02-02 00:01:08 +01:00
|
|
|
|
2020-04-26 18:09:39 +02:00
|
|
|
/**
|
|
|
|
* @brief Number of ADC samples the value has to be outside the Watchdog limit (@ref ADC_PT1000_UPPER_WATCHDOG and @ref ADC_PT1000_LOWER_WATCHDOG)
|
|
|
|
* in order to produce a watchdog error
|
|
|
|
*/
|
2020-04-26 19:53:06 +02:00
|
|
|
#define ADC_PT1000_WATCHDOG_SAMPLE_COUNT 25U
|
2020-04-26 18:09:39 +02:00
|
|
|
|
2020-02-15 01:04:40 +01:00
|
|
|
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1), ADC_PT1000_INACTIVE = (1UL<<2)};
|
2020-02-02 00:01:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor
|
|
|
|
*
|
|
|
|
* Used peripherals:
|
|
|
|
* - Timer 2 for sampling control
|
|
|
|
* - ADC1
|
|
|
|
*
|
|
|
|
* The filter weight \f$\alpha\f$ is configured for @ref ADC_PT1000_FILTER_WEIGHT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void adc_pt1000_setup_meas();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set moving average filter parameters
|
|
|
|
*
|
|
|
|
* The sampled resistance value is filtered with an exponential average filter
|
|
|
|
* specified by following difference equation:
|
|
|
|
*
|
|
|
|
* \f$ y[n] = (1-\alpha)y[n-1] + \alpha x[n] \f$
|
|
|
|
*
|
|
|
|
* @param alpha
|
|
|
|
*/
|
|
|
|
void adc_pt1000_set_moving_average_filter_param(float alpha);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the calibration data for the PT1000 measurement
|
|
|
|
*
|
|
|
|
* The resulting resistance reading is
|
2020-02-02 00:46:12 +01:00
|
|
|
* \f$R_{corrected} = (1 + \sigma) R_{raw} + O\f$
|
2020-02-02 00:01:08 +01:00
|
|
|
*
|
|
|
|
* @param offset Offset \f$O\f$
|
|
|
|
* @param sensitivity_deviation Sensitivity Deviation \f$\sigma\f$ after offset correction
|
|
|
|
*/
|
|
|
|
void adc_pt1000_set_resistance_calibration(float offset, float sensitivity_deviation, bool active);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the state and values of the resistance calibration
|
|
|
|
* @param offset Offset
|
|
|
|
* @param sensitivity_deviation Sensitivity deviation
|
|
|
|
* @param active Active state of the correction
|
|
|
|
*/
|
|
|
|
void adc_pt1000_get_resistance_calibration(float *offset, float *sensitivity_deviation, bool *active);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the current reistance value
|
|
|
|
*
|
2020-04-20 21:17:24 +02:00
|
|
|
* If the reistance calibration is enabled, this function applies the calculations of the raw resistance reading and
|
2020-02-02 00:01:08 +01:00
|
|
|
* returns the corrected value.
|
|
|
|
*
|
2020-02-02 20:24:44 +01:00
|
|
|
* If an ADC error is set, the status is negative. The status is 2 during the first measurements with a given filter setting. Technically, the resistance value is
|
2020-02-02 00:01:08 +01:00
|
|
|
* correct but the filter is not stable yet.
|
|
|
|
* Use adc_pt1000_check_error to check the error and reinitialize the ADC.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param[out] resistance Resistance output in Ohms
|
|
|
|
* @return Status
|
|
|
|
*/
|
|
|
|
int adc_pt1000_get_current_resistance(float *resistance);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stream the raw ADC data to an array in memory.
|
|
|
|
* @param adc_array Array to stream data to
|
|
|
|
* @param length Amount of data points to be measured
|
|
|
|
* @param flag_to_set This flag is set to 1 once the data has been measured and is transferred. A negative value indicates an error
|
|
|
|
* @return 0 if measurement could be started
|
|
|
|
*/
|
2020-02-15 01:04:40 +01:00
|
|
|
int adc_pt1000_stream_raw_value_to_memory(volatile float *adc_array, uint32_t length, volatile int *flag_to_set);
|
2020-02-02 00:01:08 +01:00
|
|
|
|
2020-02-10 22:38:24 +01:00
|
|
|
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count);
|
2020-02-02 00:01:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if the ADC measurement experienced any kind of error (DMA, Analog Watchdog, etc...)
|
|
|
|
*
|
|
|
|
* In case of an error, it may be necessary to call adc_pt1000_setup_meas() again in order to recover from the error
|
|
|
|
*/
|
2020-02-02 20:24:44 +01:00
|
|
|
enum adc_pt1000_error adc_pt1000_check_error();
|
2020-02-02 00:01:08 +01:00
|
|
|
|
2020-02-02 01:49:37 +01:00
|
|
|
void adc_pt1000_clear_error();
|
|
|
|
|
2020-02-02 20:24:44 +01:00
|
|
|
void adc_pt1000_disable();
|
|
|
|
|
2020-02-02 00:01:08 +01:00
|
|
|
#endif // __ADCMEAS_H__
|