switch ADC to gpt (#1343)

* switch to gpt

* halconf

* fix kinetis

* fix kinetis

* fix guards

* comment cleanup
This commit is contained in:
Matthew Kennedy 2020-04-23 19:50:18 -07:00 committed by GitHub
parent 1bad5f3047
commit b6ee79327d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 31 additions and 48 deletions

View File

@ -55,7 +55,7 @@
* @note The default is @p TRUE.
*/
#if !defined(KINETIS_GPT_USE_PIT1) || defined(__DOXYGEN__)
#define KINETIS_GPT_USE_PIT1 FALSE
#define KINETIS_GPT_USE_PIT1 TRUE
#endif
/**

View File

@ -245,22 +245,17 @@
// todo: most of this should become configurable
// todo: switch to continues ADC conversion for slow ADC?
// https://github.com/rusefi/rusefi/issues/630
// todo: switch to continues ADC conversion for fast ADC?
#define EFI_INTERNAL_FAST_ADC_PWM &PWMD2
#define EFI_INTERNAL_FAST_ADC_GPT &GPTD2
// todo: why 64 SPLL prescaler doesn't work?
// 168000000/64/128/1025 = ~20Hz
// 168000000/64/16/16 = ~10.25kHz
// todo: warning! these numbers are "tricky"! need to investigate further!
//168000000/128/65535 = ~20Hz
#define PWM_FREQ_SLOW 20507 /* PWM clock frequency. */
#define PWM_PERIOD_SLOW 65535 /* PWM period (in PWM ticks). */
//168000000/128/131 = ~10kHz
#define PWM_FREQ_FAST 20507/*164062*/ /* PWM clock frequency. */
#define PWM_PERIOD_FAST 131 /* PWM period (in PWM ticks). */
#define GPT_FREQ_FAST 20507/*164062*/ /* PWM clock frequency. */
#define GPT_PERIOD_FAST 131 /* PWM period (in PWM ticks). */
#define EFI_SPI1_AF 3

View File

@ -111,7 +111,7 @@
* @brief Enables the PWM subsystem.
*/
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM TRUE
#define HAL_USE_PWM FALSE
#endif
/**

View File

@ -254,10 +254,8 @@
// todo: most of this should become configurable
// todo: switch to continuous ADC conversion for slow ADC?
// https://github.com/rusefi/rusefi/issues/630
// todo: switch to continues ADC conversion for fast ADC?
#define EFI_INTERNAL_FAST_ADC_PWM &PWMD4
#define EFI_INTERNAL_FAST_ADC_GPT &GPTD6
#define EFI_SPI1_AF 5

View File

@ -284,10 +284,8 @@
// todo: most of this should become configurable
// todo: switch to continues ADC conversion for slow ADC?
// https://github.com/rusefi/rusefi/issues/630
// todo: switch to continues ADC conversion for fast ADC?
#define EFI_INTERNAL_FAST_ADC_PWM &PWMD4
#define EFI_INTERNAL_FAST_ADC_GPT &GPTD6
#define EFI_SPI1_AF 5

View File

@ -120,7 +120,7 @@
* @brief Enables the PWM subsystem.
*/
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM TRUE
#define HAL_USE_PWM FALSE
#endif
/**

View File

@ -180,7 +180,7 @@
#define STM32_GPT_USE_TIM3 FALSE
#define STM32_GPT_USE_TIM4 FALSE
#define STM32_GPT_USE_TIM5 TRUE
#define STM32_GPT_USE_TIM6 FALSE
#define STM32_GPT_USE_TIM6 TRUE
#define STM32_GPT_USE_TIM7 FALSE
#define STM32_GPT_USE_TIM8 FALSE
#define STM32_GPT_USE_TIM9 FALSE
@ -272,9 +272,7 @@
#define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE
// maybe even swithc this one to software timer?
// todo: https://github.com/rusefi/rusefi/issues/630 ?
#define STM32_PWM_USE_TIM4 TRUE
#define STM32_PWM_USE_TIM4 FALSE
#define STM32_PWM_USE_TIM5 FALSE
#define STM32_PWM_USE_TIM8 FALSE
#define STM32_PWM_USE_TIM9 FALSE

View File

@ -111,7 +111,7 @@
* @brief Enables the PWM subsystem.
*/
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
#define HAL_USE_PWM TRUE
#define HAL_USE_PWM FALSE
#endif
/**

View File

@ -201,7 +201,7 @@
#define STM32_GPT_USE_TIM3 FALSE
#define STM32_GPT_USE_TIM4 FALSE
#define STM32_GPT_USE_TIM5 TRUE
#define STM32_GPT_USE_TIM6 FALSE
#define STM32_GPT_USE_TIM6 TRUE
#define STM32_GPT_USE_TIM7 FALSE
#define STM32_GPT_USE_TIM8 FALSE
#define STM32_GPT_USE_TIM9 FALSE
@ -283,7 +283,7 @@
#define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE
#define STM32_PWM_USE_TIM4 TRUE
#define STM32_PWM_USE_TIM4 FALSE
#define STM32_PWM_USE_TIM5 FALSE
#define STM32_PWM_USE_TIM8 FALSE
#define STM32_PWM_USE_TIM9 FALSE

View File

@ -69,16 +69,16 @@ AdcDevice::AdcDevice(ADCConversionGroup* hwConfig) {
memset(internalAdcIndexByHardwareIndex, 0xFFFFFFFF, sizeof(internalAdcIndexByHardwareIndex));
}
#if !defined(PWM_FREQ_FAST) || !defined(PWM_PERIOD_FAST)
#if !defined(GPT_FREQ_FAST) || !defined(GPT_PERIOD_FAST)
/**
* 8000 RPM is 133Hz
* If we want to sample MAP once per 5 degrees we need 133Hz * (360 / 5) = 9576Hz of fast ADC
*/
// todo: migrate to continues ADC mode? probably not - we cannot afford the callback in
// todo: continues mode. todo: look into our options
#define PWM_FREQ_FAST 100000 /* PWM clock frequency. I wonder what does this setting mean? */
#define PWM_PERIOD_FAST 10 /* PWM period (in PWM ticks). */
#endif /* PWM_FREQ_FAST PWM_PERIOD_FAST */
#define GPT_FREQ_FAST 100000 /* PWM clock frequency. I wonder what does this setting mean? */
#define GPT_PERIOD_FAST 10 /* PWM period (in PWM ticks). */
#endif /* GPT_FREQ_FAST GPT_PERIOD_FAST */
// is there a reason to have this configurable at runtime?
#ifndef ADC_SLOW_DEVICE
@ -198,13 +198,9 @@ ADC_TwoSamplingDelay_5Cycles, // cr1
AdcDevice fastAdc(&adcgrpcfg_fast);
#if HAL_USE_PWM
static void pwmpcb_fast(PWMDriver *pwmp) {
efiAssertVoid(CUSTOM_ERR_6659, getCurrentRemainingStack()> 32, "lwStAdcFast");
#if HAL_USE_GPT
static void fast_adc_callback(GPTDriver*) {
#if EFI_INTERNAL_ADC
(void) pwmp;
/*
* Starts an asynchronous ADC conversion operation, the conversion
* will be executed in parallel to the current PWM cycle and will
@ -228,7 +224,7 @@ static void pwmpcb_fast(PWMDriver *pwmp) {
fastAdc.conversionCount++;
#endif /* EFI_INTERNAL_ADC */
}
#endif /* HAL_USE_PWM */
#endif /* HAL_USE_GPT */
float getMCUInternalTemperature(void) {
#if defined(ADC_CHANNEL_SENSOR)
@ -269,13 +265,13 @@ int getInternalAdcValue(const char *msg, adc_channel_e hwChannel) {
return slowAdc.getAdcValueByHwChannel(hwChannel);
}
#if HAL_USE_PWM
static PWMConfig pwmcfg_fast = { PWM_FREQ_FAST, PWM_PERIOD_FAST, pwmpcb_fast, { {
PWM_OUTPUT_DISABLED, NULL }, { PWM_OUTPUT_DISABLED, NULL }, {
PWM_OUTPUT_DISABLED, NULL }, { PWM_OUTPUT_DISABLED, NULL } },
/* HW dependent part.*/
0, 0 };
#endif /* HAL_USE_PWM */
#if HAL_USE_GPT
static GPTConfig fast_adc_config = {
GPT_FREQ_FAST,
fast_adc_callback,
0, 0
};
#endif /* HAL_USE_GPT */
const char * getAdcMode(adc_channel_e hwChannel) {
if (slowAdc.isHwUsed(hwChannel)) {
@ -563,10 +559,10 @@ void initAdcInputs() {
/*
* Initializes the PWM driver.
*/
#if HAL_USE_PWM
pwmStart(EFI_INTERNAL_FAST_ADC_PWM, &pwmcfg_fast);
pwmEnablePeriodicNotification(EFI_INTERNAL_FAST_ADC_PWM);
#endif /* HAL_USE_PWM */
#if HAL_USE_GPT
gptStart(EFI_INTERNAL_FAST_ADC_GPT, &fast_adc_config);
gptStartContinuous(EFI_INTERNAL_FAST_ADC_GPT, GPT_PERIOD_FAST);
#endif /* HAL_USE_GPT */
}
addConsoleActionI("adc", (VoidInt) printAdcValue);

View File

@ -150,8 +150,6 @@ icuchannel_t getInputCaptureChannel(brain_pin_e hwPin) {
* (that's the kind of event you need for shaft position sensor)
* ChibiOS limitation is that only channels #1 and #2 could be used for input capture
*
* TODO: migrate slow ADC to software timer so that TIM8 is also available for input capture
* todo: https://github.com/rusefi/rusefi/issues/630 ?
* @return NULL if pin could not be used for ICU
*/
//Nullable