configure all sample times - fix MRE knock sampling (#1841)

* configure all sample times

* smpr 1 vs smpr 2

* man I can't type

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-10-02 17:49:56 -07:00 committed by GitHub
parent 20312b0009
commit b3596f8969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 16 deletions

View File

@ -7,14 +7,6 @@
#define KNOCK_ADC_CH1 ADC_CHANNEL_IN3 #define KNOCK_ADC_CH1 ADC_CHANNEL_IN3
#define KNOCK_PIN_CH1 GPIOA_3 #define KNOCK_PIN_CH1 GPIOA_3
// knock 2 - pin PF5 NOT used! - not used for MRE
#define KNOCK_ADC_CH2 ADC_CHANNEL_IN15
#define KNOCK_PIN_CH2 GPIOF_5
// Sample rate & time - depends on the exact MCU // Sample rate & time - depends on the exact MCU
#define KNOCK_SAMPLE_TIME ADC_SAMPLE_84 #define KNOCK_SAMPLE_TIME ADC_SAMPLE_84
#define KNOCK_SAMPLE_RATE (STM32_PCLK2 / (4 * (84 + 12))) #define KNOCK_SAMPLE_RATE (STM32_PCLK2 / (4 * (84 + 12)))
#ifndef MRE_SW_KNOCK_ADC
#define MRE_SW_KNOCK_ADC
#endif

View File

@ -38,15 +38,33 @@ static void completionCallback(ADCDriver* adcp, adcsample_t*, size_t) {
static void errorCallback(ADCDriver*, adcerror_t err) { static void errorCallback(ADCDriver*, adcerror_t err) {
} }
static const uint32_t smpr1 =
ADC_SMPR1_SMP_AN10(KNOCK_SAMPLE_TIME) |
ADC_SMPR1_SMP_AN11(KNOCK_SAMPLE_TIME) |
ADC_SMPR1_SMP_AN12(KNOCK_SAMPLE_TIME) |
ADC_SMPR1_SMP_AN13(KNOCK_SAMPLE_TIME) |
ADC_SMPR1_SMP_AN14(KNOCK_SAMPLE_TIME) |
ADC_SMPR1_SMP_AN15(KNOCK_SAMPLE_TIME);
static const uint32_t smpr2 =
ADC_SMPR2_SMP_AN0(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN1(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN2(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN3(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN4(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN5(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN6(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN7(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN8(KNOCK_SAMPLE_TIME) |
ADC_SMPR2_SMP_AN9(KNOCK_SAMPLE_TIME);
static const ADCConversionGroup adcConvGroupCh1 = { FALSE, 1, &completionCallback, &errorCallback, static const ADCConversionGroup adcConvGroupCh1 = { FALSE, 1, &completionCallback, &errorCallback,
0, 0,
ADC_CR2_SWSTART, ADC_CR2_SWSTART,
#ifdef MRE_SW_KNOCK_ADC // sample times for channels 10...18
ADC_SMPR2_SMP_AN3(KNOCK_SAMPLE_TIME), // sample times for channels 10...18 smpr1,
#else // sample times for channels 0...9
ADC_SMPR1_SMP_AN14(KNOCK_SAMPLE_TIME), // sample times for channels 10...18 smpr2,
#endif
0,
0, // htr 0, // htr
0, // ltr 0, // ltr
@ -61,8 +79,10 @@ static const ADCConversionGroup adcConvGroupCh1 = { FALSE, 1, &completionCallbac
static const ADCConversionGroup adcConvGroupCh2 = { FALSE, 1, &completionCallback, &errorCallback, static const ADCConversionGroup adcConvGroupCh2 = { FALSE, 1, &completionCallback, &errorCallback,
0, 0,
ADC_CR2_SWSTART, ADC_CR2_SWSTART,
ADC_SMPR1_SMP_AN14(KNOCK_SAMPLE_TIME), // sample times for channels 10...18 // sample times for channels 10...18
0, smpr1,
// sample times for channels 0...9
smpr2,
0, // htr 0, // htr
0, // ltr 0, // ltr