Tool/software:
Hi,
I want to read a variable in differential ADC mode in the F28379D, but when I plot the data, the signal appears negatively offset. Additionally, when I increase the sampling frequency, instead of improving the signal, it starts to distort. Maybe you can help me check if I'm making a wrong declaration; I'm attaching the code I'm using.
#include "driverlib.h"
#include "device.h"
#define EX_ADC_RESOLUTION 16
#define ADC_BUFFER_SIZE 100 // Define the size of the data storage buffer
int16_t adcDifferentialResultBuffer[ADC_BUFFER_SIZE];
volatile uint16_t adcBufferIndex =0; // volatile because it's changed in ISR
volatile int TBPRD =999; // volatile because it's changed in ISR
volatile int CMPA =10; // volatile because it's changed in ISR
volatile uint16_t acqps=14;
void configureADC(uint32_t adcBase);
void initEPWM();
void initADCSOC(void);
__interrupt void adcA1ISR(void);
//
// Main
//
void main(void)
{
Device_init();
Device_initGPIO();
GPIO_setDirectionMode(16, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(16, GPIO_PIN_TYPE_STD);
GPIO_writePin(16, 0);
Interrupt_initModule();
Interrupt_initVectorTable();
Interrupt_register(INT_ADCA1, &adcA1ISR);
configureADC(ADCA_BASE);
initEPWM();
initADCSOC();
Interrupt_enable(INT_ADCA1);
EINT;
ERTM;
EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);
do
{
if (adcBufferIndex >= ADC_BUFFER_SIZE)
{
adcBufferIndex =0;
}
}
while(1);
}
void configureADC(uint32_t adcBase)
{
ADC_setPrescaler(adcBase, ADC_CLK_DIV_4_0);
ADC_setMode(adcBase, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
ADC_setInterruptPulseMode(adcBase, ADC_PULSE_END_OF_CONV);
ADC_enableConverter(adcBase);
DEVICE_DELAY_US(1000);
}
void initEPWM(void)
{
EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_U_CMPA);
EPWM_setADCTriggerEventPrescale(EPWM1_BASE, EPWM_SOC_A, 1);
EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, CMPA);
EPWM_setTimeBasePeriod(EPWM1_BASE, TBPRD);
EPWM_setClockPrescaler(EPWM1_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
}
void initADCSOC(void)
{
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN0, acqps);
ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER0);
ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
}
__interrupt void adcA1ISR(void)
{
GPIO_writePin(16, 1);
int16_t result_diff = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
if (adcBufferIndex < ADC_BUFFER_SIZE)
{
adcDifferentialResultBuffer[adcBufferIndex++] = result_diff;
}
else
{
adcBufferIndex = 0; // Reset to overwrite oldest data
adcDifferentialResultBuffer[adcBufferIndex++] = result_diff;
}
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
if(true == ADC_getInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1))
{
ADC_clearInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
}
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
GPIO_writePin(16, 0);
}