This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F280025C:ADC 未读取值

Guru**** 2457760 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1314852/tms320f280025c-adc-not-read-the-value

器件型号:TMS320F280025C

您好!

  我需要在 ADC 中断服务例程中读取电压。 已 触发 ADC 中断。 当我将 ADC 引脚连接到3.3V 和接地时、ADC 会正确读取电压。 我已经将 ADC 引脚连接到电位器。 目前、电位器的输出电压为1.8V、但 Code Composer Studio 中的 ADC 读数为0。 当我使用万用表测量控制器引脚的电压时、它显示的正确电压为1.8V。

我使用的是 ADCA3/C5

我正在附上代码供您参考:-

#include "f28x_project.h"

//
// Defines
//
#define RESULTS_BUFFER_SIZE 256

//
// Globals
//
uint16_t sensorSample = 0;
uint16_t isrCount = 0;
int16_t sensorTemp = 0;

//
// Function Prototypes
//
void initADC(void);
void initEPWM(void);
void initADCSOC(void);
__interrupt void AdcA1ISR(void);

//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
InitSysCtrl();

//
// Initialize GPIO
//
InitGpio();

//
// Disable CPU interrupts
//
DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
//
InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
IER = 0x0000;
IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
InitPieVectTable();

//
// Map ISR functions
//
EALLOW;
PieVectTable.ADCA1_INT = &AdcA1ISR; // Function for Adca interrupt 1
EDIS;

//
// Configure the ADC and power it up
//
initADC();

//
// Configure the ePWM
//
initEPWM();

//
// Setup the ADC for ePWM triggered conversions on channel 1
//
initADCSOC();


EALLOW;

//
// Enable PIE interrupt
//
PieCtrlRegs.PIEIER1.bit.INTx1 = 1;

//
// Sync ePWM
//
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;

//
// Enable global Interrupts and higher priority real-time debug events:
//
IER |= M_INT1; // Enable group 1 interrupts

EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

InitTempSensor(3.3f);

//
// Start ePWM
//
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA
EPwm1Regs.TBCTL.bit.CTRMODE = 0; // Unfreeze, and enter up count mode

//
// Wait while ePWM causes ADC conversions, which then cause interrupts,
// which fill the results buffer, eventually setting the bufferFull
// flag
//
while(1)
{
}
}

//
// initADC - Function to configure and power up Adca.
//
void initADC(void)
{
//
// Setup VREF as internal
//
SetVREF(ADC_ADCA, ADC_EXTERNAL, ADC_VREF3P3);

EALLOW;

//
// Set AdcaLK divider to /4
//
AdcaRegs.ADCCTL2.bit.PRESCALE = 6;

//
// Set pulse positions to late EOC
//
AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;

//
// Power up the ADC and then delay for 1 ms
//
AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
EDIS;

DELAY_US(1000);
}

//
// initEPWM - Function to configure ePWM1 to generate the SOC.
//
void initEPWM(void)
{
EALLOW;

EPwm1Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group
EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC on up-count
EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event

EPwm1Regs.CMPA.bit.CMPA = 0x0800; // Set compare A value to 2048 counts
EPwm1Regs.TBPRD = 0x1000; // Set period to 4096 counts

EPwm1Regs.TBCTL.bit.CTRMODE = 3; // Freeze counter

EDIS;
}

//
// initADCSOC - Function to configure ADCA's SOC0 to be triggered by ePWM1.
//
void initADCSOC(void)
{
//
// Select the channels to convert and the end of conversion flag
//
EALLOW;

AdcaRegs.ADCSOC0CTL.bit.CHSEL = 0x03; // SOC0 will convert pin C12

AdcaRegs.ADCSOC0CTL.bit.ACQPS = 19; // Sample window is 10 SYSCLK cycles
AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 5; // Trigger on ePWM1 SOCA

AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC0 will set INT1 flag
AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared

EDIS;
}

//
// Adca1ISR - ADC C Interrupt 1 ISR
//
__interrupt void AdcA1ISR(void)
{

isrCount++;

if (isrCount==1000)
{
isrCount=0;
}
//
// Add the latest result to the buffer
// ADCRESULT0 is the result register of SOC0
sensorSample = AdcaResultRegs.ADCRESULT0;
// sensorTemp = GetTemperatureC(sensorSample);

//
// Clear the interrupt flag
//
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1;

//
// Check if overflow has occurred
//
if(1 == AdcaRegs.ADCINTOVF.bit.ADCINT1)
{
AdcaRegs.ADCINTOVFCLR.bit.ADCINT1 = 1; //clear INT1 overflow flag
AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //clear INT1 flag
}

//
// Acknowledge the interrupt
//
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

请告诉我为什么我无法读取 ADC 电压?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Sayali、

    您使用的是外部 电压基准还是内部基准? 在代码中、注释显示为"internal"、但 SetVREF 函数会将其配置为外部。

    此致、
    伊袋

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我使用外部基准

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您是否确认 VREFHIAC 引脚上连接了正确的基准电压源、并且施加的电压确实为3.3V?

    谢谢。
    伊袋

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我检查了所有连接... 我看到 Vrefhi 引脚处为3.3V。 一旦、请逐行检查代码。 目标是确定问题是出在代码还是在硬件方面。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    Sayali、

    源代码看起来没有问题。 目前我能想到的唯一一件事就是尝试提高 ACQPS。 如果您使用电位器、那么您的源阻抗将会很高、因此您需要确保采样电容器有足够的充电时间。

    此致、
    伊袋