Other Parts Discussed in Thread: BOOSTXL-DRV8305EVM, DRV8305
Tool/software:
Good Morning! I'm attempting to setup the ADC but I'm struggling to get it to work correctly. All the values I am reading are the same, and when i put an oscilloscope onto the motor driver sense pins i do not seem to see a signal at all. Please see the attached code.
#include "adc.h"
#include "adc_priv.h"
#include "..\other\adc.h"
#include "..\other\hw_ints.h"
#include "..\other\device.h"
COIL_FEEDBACK_TYPE Coil_Feedback;
void ConfigureAdc(void)
{
EALLOW;
//
// Interrupts that are used in this example are re-mapped to ISR functions
// found within this file.
//
Interrupt_register(INT_ADCA1, &adcA1ISR);
//
// Set up the ADC and the ePWM and initialize the SOC
//
InitAdc(ADCA_BASE);
InitAdc(ADCB_BASE);
InitAdc(ADCC_BASE);
InitAdcSoc();
EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_U_CMPA);
//EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_ZERO_OR_PERIOD);
EPWM_setADCTriggerEventPrescale(EPWM1_BASE, EPWM_SOC_A, 1);
Interrupt_enable(INT_ADCA1);
EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
EDIS;
}
void InitAdc(uint32_t adcBase)
{
//
// Set ADCDLK divider to /4
//
ADC_setPrescaler(adcBase, ADC_CLK_DIV_4_0);
//
// Set resolution and signal mode (see #defines above) and load
// corresponding trims.
//
#if(EX_ADC_RESOLUTION == 12)
ADC_setMode(adcBase, ADC_RESOLUTION_12BIT, ADC_MODE_SINGLE_ENDED);
#elif(EX_ADC_RESOLUTION == 16)
ADC_setMode(adcBase, ADC_RESOLUTION_16BIT, ADC_MODE_DIFFERENTIAL);
#endif
//
// Set pulse positions to late
//
ADC_setInterruptPulseMode(adcBase, ADC_PULSE_END_OF_CONV);
//
// Power up the ADCs and then delay for 1 ms
//
ADC_enableConverter(adcBase);
//
// Delay for 1ms to allow ADC time to power up
//
DEVICE_DELAY_US(1000);
}
//
// Function to configure SOCs on ADCA and ADCB to be triggered by ePWM1.
//
void InitAdcSoc(void)
{
//
// Select the channels to convert and the configure the ePWM trigger
//
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN14, ADC_SAMPLING_WINDOW); // ADCIN14
ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN3, ADC_SAMPLING_WINDOW); // ADCINC3
ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER2, ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN3, ADC_SAMPLING_WINDOW); // ADCINA3
ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER3, ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN2, ADC_SAMPLING_WINDOW); // ADCINC2
ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER4, ADC_TRIGGER_EPWM1_SOCA,
ADC_CH_ADCIN2, ADC_SAMPLING_WINDOW); // ADCINB2
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)
{
Coil_Feedback.V_Sen_A_Raw = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
Coil_Feedback.V_Sen_B_Raw = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER1);
Coil_Feedback.V_Sen_Pvdd_Raw = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER2);
Coil_Feedback.I_Sen_A_Raw = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER3);
Coil_Feedback.I_Sen_B_Raw = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER4);
Coil_Feedback.V_Sen_A = (U16)((F32)V_SEN_GAIN * Coil_Feedback.V_Sen_A_Raw);
Coil_Feedback.V_Sen_B = (U16)((F32)V_SEN_GAIN * Coil_Feedback.V_Sen_B_Raw);
Coil_Feedback.V_Sen_Pvdd = (U16)((F32)V_SEN_GAIN * Coil_Feedback.V_Sen_Pvdd_Raw);
Coil_Feedback.Measured_Current = I_SEN_GAIN * ((F32)Coil_Feedback.I_Sen_A_Raw - Coil_Feedback.I_Sen_B_Raw);
//
// Clear the interrupt flag
//
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
//
// Check if overflow has occurred
//
if(true == ADC_getInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1))
{
ADC_clearInterruptOverflowStatus(ADCA_BASE, ADC_INT_NUMBER1);
ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
}
//
// Acknowledge the interrupt
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
}
//
// End of file
//