rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
adc_inputs_onchip.cpp File Reference

Detailed Description

Low level ADC code.

rusEfi uses two ADC devices on the same 16 pins at the moment. Two ADC devices are used in order to distinguish between fast and slow devices. The idea is that but only having few channels in 'fast' mode we can sample those faster?

Slow ADC group is used for IAT, CLT, AFR, VBATT etc - this one is currently sampled at 500Hz

Fast ADC group is used for MAP, MAF HIP - this one is currently sampled at 10KHz We need frequent MAP for map_averaging.cpp

10KHz equals one measurement every 3.6 degrees at 6000 RPM

PS: analog muxes allow to double number of analog inputs oh, and ADC3 is dedicated for knock

Date
Jan 14, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file adc_inputs_onchip.cpp.

Functions

float adcGetRawVoltage (const char *msg, adc_channel_e hwChannel)
 
float adcGetScaledVoltage (const char *msg, adc_channel_e hwChannel)
 
static void fastAdcDoneCB (ADCDriver *adcp)
 
static void fastAdcErrorCB (ADCDriver *, adcerror_t err)
 
static void fastAdcStartTrigger (GPTDriver *)
 

Variables

static ADCConversionGroup adcgrpcfgFast
 
static volatile NO_CACHE adcsample_t fastAdcSampleBuf [ADC_BUF_DEPTH_FAST *ADC_MAX_CHANNELS_COUNT]
 
AdcDevice fastAdcADC_FAST_DEVICE
 
static efitick_t lastTick = 0
 
static const PWMConfig pwmcfg
 
static const GPTConfig fast_adc_config
 

Function Documentation

◆ adcGetRawVoltage()

float adcGetRawVoltage ( const char msg,
adc_channel_e  hwChannel 
)

Definition at line 33 of file adc_inputs_onchip.cpp.

33 {
34 return adcRawValueToRawVoltage(adcGetRawValue(msg, hwChannel));
35}

Referenced by adcGetScaledVoltage(), printAdcChannedReport(), AdcSubscription::PrintInfo(), printMAPInfo(), and AdcSubscription::UpdateSubscribers().

Here is the caller graph for this function:

◆ adcGetScaledVoltage()

float adcGetScaledVoltage ( const char msg,
adc_channel_e  hwChannel 
)

Definition at line 38 of file adc_inputs_onchip.cpp.

38 {
39 // TODO: merge getAnalogInputDividerCoefficient() and boardAdjustVoltage() into single board hook?
40 float voltage = adcGetRawVoltage(msg, hwChannel) * getAnalogInputDividerCoefficient(hwChannel);
41 return boardAdjustVoltage(voltage, hwChannel);
42}
float PUBLIC_API_WEAK boardAdjustVoltage(float voltage, adc_channel_e)
float adcGetRawVoltage(const char *msg, adc_channel_e hwChannel)
float getAnalogInputDividerCoefficient(adc_channel_e hwChannel)

Referenced by getAfr(), printAdcChannedReport(), and updateRawSensors().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fastAdcDoneCB()

static void fastAdcDoneCB ( ADCDriver *  adcp)
static

Definition at line 142 of file adc_inputs_onchip.cpp.

142 {
143 // State may not be complete if we get a callback for "half done"
144 if (adcIsBufferComplete(adcp)) {
145 efitick_t nowTick = getTimeNowNt();
146 efitick_t diff = nowTick - lastTick;
147 lastTick = nowTick;
148
149 engine->outputChannels.fastAdcPeriod = (uint32_t)diff;
151
152 onFastAdcComplete(adcp->samples);
153 }
154}
void onFastAdcComplete(adcsample_t *samples)
Definition hardware.cpp:276
static efitick_t lastTick
TunerStudioOutputChannels outputChannels
Definition engine.h:109
efitick_t getTimeNowNt()
Definition efitime.cpp:19
static EngineAccessor engine
Definition engine.h:412
Here is the call graph for this function:

◆ fastAdcErrorCB()

static void fastAdcErrorCB ( ADCDriver *  ,
adcerror_t  err 
)
static

Definition at line 156 of file adc_inputs_onchip.cpp.

156 {
157 engine->outputChannels.fastAdcLastError = (uint8_t)err;
159 if (err == ADC_ERR_OVERFLOW) {
161 }
162 // TODO: restart?
163}
@ ADC_ERR_OVERFLOW

◆ fastAdcStartTrigger()

static void fastAdcStartTrigger ( GPTDriver )
static

Definition at line 186 of file adc_inputs_onchip.cpp.

187{
188#if EFI_INTERNAL_ADC
189 /*
190 * Starts an asynchronous ADC conversion operation, the conversion
191 * will be executed in parallel to the current PWM cycle and will
192 * terminate before the next PWM cycle.
193 */
195#endif /* EFI_INTERNAL_ADC */
196}
AdcDevice fastAdc
void startConversionI(void)
Here is the call graph for this function:

Variable Documentation

◆ ADC_FAST_DEVICE

AdcDevice fastAdc& ADC_FAST_DEVICE

Definition at line 138 of file adc_inputs_onchip.cpp.

Referenced by AdcDevice::startConversionI().

◆ adcgrpcfgFast

ADCConversionGroup adcgrpcfgFast
static

Definition at line 80 of file adc_inputs_onchip.cpp.

80 {
81#if defined(EFI_INTERNAL_FAST_ADC_PWM)
82 .circular = TRUE,
83#elif defined (EFI_INTERNAL_FAST_ADC_GPT)
84 .circular = FALSE,
85#endif
86 .num_channels = 0,
87 .end_cb = fastAdcDoneCB,
88 .error_cb = fastAdcErrorCB,
89 /* HW dependent part.*/
90 .cr1 = 0,
91#if defined(EFI_INTERNAL_FAST_ADC_PWM)
92 /* HW start using TIM8 CC 1 event rising edge
93 * See "External trigger for regular channels" for magic 13 number
94 * NOTE: Currently only TIM8 in PWM mode is supported */
95 .cr2 = ADC_CR2_EXTEN_0 | (13 << ADC_CR2_EXTSEL_Pos),
96#elif defined (EFI_INTERNAL_FAST_ADC_GPT)
97 /* SW start through GPT callback and SW kick */
98 .cr2 = ADC_CR2_SWSTART,
99#endif
100 /**
101 * here we configure all possible channels for fast mode. Some channels would not actually
102 * be used hopefully that's fine to configure all possible channels.
103 *
104 */
105 // sample times for channels 10...18
106 .smpr1 =
107 ADC_SMPR1_SMP_AN10(ADC_SAMPLING_FAST) |
108 ADC_SMPR1_SMP_AN11(ADC_SAMPLING_FAST) |
109 ADC_SMPR1_SMP_AN12(ADC_SAMPLING_FAST) |
110 ADC_SMPR1_SMP_AN13(ADC_SAMPLING_FAST) |
111 ADC_SMPR1_SMP_AN14(ADC_SAMPLING_FAST) |
112 ADC_SMPR1_SMP_AN15(ADC_SAMPLING_FAST),
113 // In this field must be specified the sample times for channels 0...9
114 .smpr2 =
115 ADC_SMPR2_SMP_AN0(ADC_SAMPLING_FAST) |
116 ADC_SMPR2_SMP_AN1(ADC_SAMPLING_FAST) |
117 ADC_SMPR2_SMP_AN2(ADC_SAMPLING_FAST) |
118 ADC_SMPR2_SMP_AN3(ADC_SAMPLING_FAST) |
119 ADC_SMPR2_SMP_AN4(ADC_SAMPLING_FAST) |
120 ADC_SMPR2_SMP_AN5(ADC_SAMPLING_FAST) |
121 ADC_SMPR2_SMP_AN6(ADC_SAMPLING_FAST) |
122 ADC_SMPR2_SMP_AN7(ADC_SAMPLING_FAST) |
123 ADC_SMPR2_SMP_AN8(ADC_SAMPLING_FAST) |
124 ADC_SMPR2_SMP_AN9(ADC_SAMPLING_FAST),
125 .htr = 0,
126 .ltr = 0,
127 .sqr1 = 0, // Conversion group sequence 13...16 + sequence length
128 .sqr2 = 0, // Conversion group sequence 7...12
129 .sqr3 = 0, // Conversion group sequence 1...6
130#if ADC_MAX_CHANNELS_COUNT > 16
131 .sqr4 = 0, // Conversion group sequence 19...24
132 .sqr5 = 0 // Conversion group sequence 25...30
133#endif /* ADC_MAX_CHANNELS_COUNT */
134};
static void fastAdcDoneCB(ADCDriver *adcp)
static void fastAdcErrorCB(ADCDriver *, adcerror_t err)

Referenced by portInitAdc().

◆ fast_adc_config

const GPTConfig fast_adc_config
static
Initial value:
= {
.frequency = GPT_FREQ_FAST,
.callback = fastAdcStartTrigger,
.cr2 = 0,
.dier = 0,
}
static void fastAdcStartTrigger(GPTDriver *)

Definition at line 198 of file adc_inputs_onchip.cpp.

198 {
199 .frequency = GPT_FREQ_FAST,
200 .callback = fastAdcStartTrigger,
201 .cr2 = 0,
202 .dier = 0,
203};

Referenced by AdcDevice::init().

◆ fastAdcSampleBuf

volatile NO_CACHE adcsample_t fastAdcSampleBuf[ADC_BUF_DEPTH_FAST *ADC_MAX_CHANNELS_COUNT]
static

Definition at line 136 of file adc_inputs_onchip.cpp.

◆ lastTick

efitick_t lastTick = 0
static

Definition at line 140 of file adc_inputs_onchip.cpp.

Referenced by fastAdcDoneCB().

◆ pwmcfg

const PWMConfig pwmcfg
static
Initial value:
= {
.frequency = GPT_FREQ_FAST * ADC_BUF_DEPTH_FAST,
.period = GPT_PERIOD_FAST,
.callback = nullptr,
.channels = {
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr},
{PWM_OUTPUT_ACTIVE_HIGH, nullptr}
},
.cr2 = 0,
.bdtr = 0,
.dier = 0,
}

Definition at line 167 of file adc_inputs_onchip.cpp.

167 {
168 /* on each trigger event regular group of channels is converted,
169 * to get whole buffer filled we need ADC_BUF_DEPTH_FAST trigger events */
170 .frequency = GPT_FREQ_FAST * ADC_BUF_DEPTH_FAST,
171 .period = GPT_PERIOD_FAST,
172 .callback = nullptr,
173 .channels = {
174 {PWM_OUTPUT_ACTIVE_HIGH, nullptr},
175 {PWM_OUTPUT_ACTIVE_HIGH, nullptr},
176 {PWM_OUTPUT_ACTIVE_HIGH, nullptr},
177 {PWM_OUTPUT_ACTIVE_HIGH, nullptr}
178 },
179 .cr2 = 0,
180 .bdtr = 0,
181 .dier = 0,
182};

Referenced by AdcDevice::init().

Go to the source code of this file.