多个IO口采ADC的问题

2019-03-24 08:58发布

请教各位: 使用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函数代码

  1. void init_adc()
  2. {
  3. //Initialize the ADC12B Module
  4. /*
  5. * Base address of ADC12B Module
  6. * Use internal ADC12B bit as sample/hold signal to start conversion
  7. * USE MODOSC 5MHZ Digital Oscillator as clock source
  8. * Use default clock divider/pre-divider of 1
  9. * Not use internal channel
  10. */
  11. ADC12_B_initParam initParam = {0};
  12. initParam.sampleHoldSignalSourceSelect = ADC12_B_SAMPLEHOLDSOURCE_SC;
  13. initParam.clockSourceSelect = ADC12_B_CLOCKSOURCE_ADC12OSC;
  14. initParam.clockSourceDivider = ADC12_B_CLOCKDIVIDER_1;
  15. initParam.clockSourcePredivider = ADC12_B_CLOCKPREDIVIDER__1;
  16. initParam.internalChannelMap = ADC12_B_NOINTCH;
  17. ADC12_B_init(ADC12_B_BASE, &initParam);

  18. //Enable the ADC12B module
  19. ADC12_B_enable(ADC12_B_BASE);

  20. /*
  21. * Base address of ADC12B Module
  22. * For memory buffers 0-7 sample/hold for 64 clock cycles
  23. * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
  24. * Disable Multiple Sampling
  25. */
  26. ADC12_B_setupSamplingTimer(ADC12_B_BASE, ADC12_B_CYCLEHOLD_16_CYCLES,
  27. ADC12_B_CYCLEHOLD_4_CYCLES, ADC12_B_MULTIPLESAMPLESDISABLE);

  28. //Configure Memory Buffer
  29. /*
  30. * Base address of the ADC12B Module
  31. * Configure memory buffer 0
  32. * Map input A3 to memory buffer 0
  33. * Vref+ = AVcc
  34. * Vref- = AVss
  35. * Memory buffer 0 is not the end of a sequence
  36. */
  37. ADC12_B_configureMemoryParam configureMemoryParam = {0};
  38. configureMemoryParam.memoryBufferControlIndex = ADC12_B_MEMORY_0;
  39. //        configureMemoryParam.inputSourceSelect = ADC12_B_INPUT_A3;
  40. configureMemoryParam.refVoltageSourceSelect =
  41. ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;
  42. configureMemoryParam.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;
  43. configureMemoryParam.windowComparatorSelect =
  44. ADC12_B_WINDOW_COMPARATOR_DISABLE;
  45. configureMemoryParam.differentialModeSelect =
  46. ADC12_B_DIFFERENTIAL_MODE_DISABLE;
  47. ADC12_B_configureMemory(ADC12_B_BASE, &configureMemoryParam);

  48. ADC12_B_clearInterrupt(ADC12_B_BASE, 0, ADC12_B_IFG0);
  49. //Enable memory buffer 0 interrupt
  50. ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12_B_IE0, 0, 0);
  51. }
复制代码
  1. uint16_t ADC12_B_Sampling(uint16_t GpioPort, uint16_t GpioPin, uint16_t InputSource)
  2. {

  3. int16_t i16Adcdata[16];
  4. int16_t i16swap = 0;
  5. int16_t i16_temp = 0, i16_temp1 = 0;

  6. GPIO_setAsPeripheralModuleFunctionOutputPin(GpioPort, GpioPin,
  7. GPIO_TERNARY_MODULE_FUNCTION);

  8. HWREG16(ADC12_B_BASE + OFS_ADC12MCTL0 + ADC12_B_MEMORY_0) = InputSource; //Set Input Source

  9. //        __bic_SR_register(GIE);
  10. _disable_interrupts();

  11. for (i = 0; i < 16; i++)
  12. {
  13. // 开始采样和转化,在memory buffer 0 ,单通道单次转化
  14. ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0,
  15. ADC12_B_SINGLECHANNEL);

  16. while (!(HWREG8(ADC12_B_BASE + OFS_ADC12IFGR0) & ADC12IFG0));
  17. ADC_Get_Value = ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);
  18. HWREG16(ADC12_B_BASE + (OFS_ADC12MEM0 + ADC12_B_MEMORY_0)) = 0;
  19. i16Adcdata[i] = ADC_Get_Value;

  20. __no_operation();
  21. __delay_cycles(5000);
  22. }
  23. //        __bis_SR_register(GIE);
  24. _enable_interrupts();

  25. for (i16_temp = 0; i16_temp < 16; i16_temp++)
  26. {
  27. for (i16_temp1 = i16_temp + 1; i16_temp1 < 16; i16_temp1++)
  28. {
  29. if (i16Adcdata[i16_temp] < i16Adcdata[i16_temp1])
  30. {
  31. i16swap = i16Adcdata[i16_temp];
  32. i16Adcdata[i16_temp] = i16Adcdata[i16_temp1];
  33. i16Adcdata[i16_temp1] = i16swap;
  34. }
  35. }
  36. }

  37. for (i16_temp = 5; i16_temp < 12; i16_temp++)
  38. i16Adcdata[4] += i16Adcdata[i16_temp];
  39. i16Adcdata[4] += 8;
  40. i16Adcdata[4] = i16Adcdata[4] >> 3;
  41. ADV_Get_Aver_Value = i16Adcdata[4];


  42. //        DEBUG_PRINT(MSG_ALWAYS, "ADV_Get_Aver_Value=====%d ", ADV_Get_Aver_Value);

  43. return ADV_Get_Aver_Value;

  44. }
复制代码


此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
gh131413
2019-03-24 15:54
< 转换通道和IO口切换再加切换时间延迟一般是没有问题的,再查查程序看有没有问题……

一周热门 更多>

相关问题

    相关文章