2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file adc_math.h
|
|
|
|
*
|
2017-11-24 16:16:00 -08:00
|
|
|
* todo: all this looks to be about internal ADC, merge this file with adc_inputs.h?
|
|
|
|
* these macro are also used in simulator so maybe not really merging with adc_inputs.h until simulator get's it's own implementation?
|
2017-11-24 14:40:20 -08:00
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
* @date Mar 18, 2014
|
2017-01-03 03:05:22 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ADC_MATH_H_
|
|
|
|
#define ADC_MATH_H_
|
|
|
|
|
2019-09-22 06:56:06 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#define ADC_MAX_VALUE 4095
|
|
|
|
|
2017-08-31 04:57:39 -07:00
|
|
|
#define adcToVolts(adc) ((engineConfiguration->adcVcc) / ADC_MAX_VALUE * (adc))
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-08-31 04:57:39 -07:00
|
|
|
#define voltsToAdc(volts) ((volts) * (ADC_MAX_VALUE / (engineConfiguration->adcVcc)))
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-06-15 16:46:50 -07:00
|
|
|
// voltage in MCU universe, from zero to VDD
|
2015-07-10 06:01:56 -07:00
|
|
|
#define getVoltage(msg, hwChannel) (adcToVolts(getAdcValue(msg, hwChannel)))
|
|
|
|
|
2019-09-22 06:56:06 -07:00
|
|
|
// DECLARE_ENGINE_PARAMETER_SUFFIX
|
|
|
|
float getVoltageDivided(const char *msg, adc_channel_e channel);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#endif /* ADC_MATH_H_ */
|