1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 08:06:13 +01:00

Fixed logic of ADC ready

This commit is contained in:
pmantoine 2023-01-28 14:39:00 +08:00
parent 6cc66e26c1
commit be33bafa66

View File

@ -96,7 +96,7 @@ void DCCTimer::clearPWM() {
void DCCTimer::getSimulatedMacAddress(byte mac[6]) { void DCCTimer::getSimulatedMacAddress(byte mac[6]) {
volatile uint32_t *serno1 = (volatile uint32_t *)0x1FFF7A10; volatile uint32_t *serno1 = (volatile uint32_t *)0x1FFF7A10;
volatile uint32_t *serno2 = (volatile uint32_t *)0x1FFF7A14; volatile uint32_t *serno2 = (volatile uint32_t *)0x1FFF7A14;
volatile uint32_t *serno3 = (volatile uint32_t *)0x1FFF7A18; // volatile uint32_t *serno3 = (volatile uint32_t *)0x1FFF7A18;
volatile uint32_t m1 = *serno1; volatile uint32_t m1 = *serno1;
volatile uint32_t m2 = *serno2; volatile uint32_t m2 = *serno2;
@ -172,9 +172,9 @@ int ADCee::init(uint8_t pin) {
// Set the sampling rate for that analog input // Set the sampling rate for that analog input
if (adcchan < 10) if (adcchan < 10)
ADC1->SMPR2 |= (0b111 << (adcchan * 3)); // Channel sampling rate 480 cycles. 16MHz bus clock for ADC. 1/16MHz = 62.5ns. 480*62.5ns=30us ADC1->SMPR2 |= (0b111 << (adcchan * 3)); // Channel sampling rate 480 cycles
else else
ADC1->SMPR1 |= (0b111 << ((adcchan - 10) * 3)); // Channel sampling rate 480 cycles. 16MHz bus clock for ADC. 1/16MHz = 62.5ns. 480*62.5ns=30us ADC1->SMPR1 |= (0b111 << ((adcchan - 10) * 3)); // Channel sampling rate 480 cycles
// Read the inital ADC value for this analog input // Read the inital ADC value for this analog input
ADC1->SQR3 = adcchan; // 1st conversion in regular sequence ADC1->SQR3 = adcchan; // 1st conversion in regular sequence
@ -219,7 +219,7 @@ void ADCee::scan() {
if (waiting) { if (waiting) {
// look if we have a result // look if we have a result
if ((ADC1->SR & (1 << 1))) if (!(ADC1->SR & (1 << 1)))
return; // no result, continue to wait return; // no result, continue to wait
// found value // found value
analogvals[id] = ADC1->DR; analogvals[id] = ADC1->DR;