请教各位: 使用MSP430FR5969
我使用P3.0 (A12) 、 P3.2 (A14)、P3.3 (A15 ) 三个IO口,分别采三个ADC,但是都是以第一个采到的ADC的值为准,不会变化
P3.0采2.0V的电压,P3.2采0.5V的电压 P3.3采1.0V的电压,最后得到的结果总是以P3.0的值为准
但是单次分别采各自的电压是正确的,就是3个IO口一起采的时候,会出现这种情况。
请问是通道没有转换所以一直以第一个通道来采电压吗?还是有其他可能?
请教大家,谢谢!
下面是ADC的初始化和采ADC函数代码
- void init_adc()
- {
- //Initialize the ADC12B Module
- /*
- * Base address of ADC12B Module
- * Use internal ADC12B bit as sample/hold signal to start conversion
- * USE MODOSC 5MHZ Digital Oscillator as clock source
- * Use default clock divider/pre-divider of 1
- * Not use internal channel
- */
- ADC12_B_initParam initParam = {0};
- initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
- initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
- initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
- initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
- initParam.internalChannelMap = ADC12_B_NOINTCH;
- ADC12_B_init(ADC12_B_BASE, &initParam);
- //Enable the ADC12B module
- ADC12_B_enable(ADC12_B_BASE);
- /*
- * Base address of ADC12B Module
- * For memory buffers 0-7 sample/hold for 64 clock cycles
- * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
- * Disable Multiple Sampling
- */
- ADC12_B_setupSamplingTimer(ADC12_B_BASE, ADC12_B_CYCLEHOLD_16_CYCLES,
- ADC12_B_CYCLEHOLD_4_CYCLES, ADC12_B_MULTIPLESAMPLESDISABLE);
- //Configure Memory Buffer
- /*
- * Base address of the ADC12B Module
- * Configure memory buffer 0
- * Map input A3 to memory buffer 0
- * Vref+ = AVcc
- * Vref- = AVss
- * Memory buffer 0 is not the end of a sequence
- */
- ADC12_B_configureMemoryParam configureMemoryParam = {0};
- configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
- // configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A3;
- configureMemoryParam.refVoltageSourceSelect =
- ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
- configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
- configureMemoryParam.windowComparatorSelect =
- ADC12_B_WINDOW_COMPARATOR_DISABLE;
- configureMemoryParam.differentialModeSelect =
- ADC12_B_DIFFERENTIAL_MODE_DISABLE;
- ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);
- ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG0);
- //Enable memory buffer 0 interrupt
- ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE0, 0, 0);
- }
复制代码- uint16_t ADC12_B_Sampling(uint16_t GpioPort, uint16_t GpioPin, uint16_t InputSource)
- {
- int16_t i16Adcdata[16];
- int16_t i16swap = 0;
- int16_t i16_temp = 0, i16_temp1 = 0;
- GPIO_setAsPeripheralModuleFunctionOutputPin(GpioPort, GpioPin,
- GPIO_TERNARY_MODULE_FUNCTION);
- HWREG16(ADC12_B_BASE + OFS_ADC12MCTL0 + ADC12_B_MEMORY_0) = InputSource; //Set Input Source
- // __bic_SR_register(GIE);
- _disable_interrupts();
- for (i = 0; i < 16; i++)
- {
- // 开始采样和转化,在memory buffer 0 ,单通道单次转化
- ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0,
- ADC12_B_SINGLECHANNEL);
- while (!(HWREG8(ADC12_B_BASE + OFS_ADC12IFGR0) & ADC12IFG0));
- ADC_Get_Value = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);
- HWREG16(ADC12_B_BASE + (OFS_ADC12MEM0 + ADC12_B_MEMORY_0)) = 0;
- i16Adcdata[i] = ADC_Get_Value;
- __no_operation();
- __delay_cycles(5000);
- }
- // __bis_SR_register(GIE);
- _enable_interrupts();
- for (i16_temp = 0; i16_temp < 16; i16_temp++)
- {
- for (i16_temp1 = i16_temp + 1; i16_temp1 < 16; i16_temp1++)
- {
- if (i16Adcdata[i16_temp] < i16Adcdata[i16_temp1])
- {
- i16swap = i16Adcdata[i16_temp];
- i16Adcdata[i16_temp] = i16Adcdata[i16_temp1];
- i16Adcdata[i16_temp1] = i16swap;
- }
- }
- }
- for (i16_temp = 5; i16_temp < 12; i16_temp++)
- i16Adcdata[4] += i16Adcdata[i16_temp];
- i16Adcdata[4] += 8;
- i16Adcdata[4] = i16Adcdata[4] >> 3;
- ADV_Get_Aver_Value = i16Adcdata[4];
- // DEBUG_PRINT(MSG_ALWAYS, "ADV_Get_Aver_Value=====%d
", ADV_Get_Aver_Value);
- return ADV_Get_Aver_Value;
- }
复制代码
此帖出自
小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>