Other Parts Discussed in Thread: BOOSTXL-DRV8305EVM
Tool/software:
Good afternoon, I'm working on implementing the ADC module into my project but it is currently reading incorrect values. It works well with non changing voltages, but once a triangle wave is applied to the pin with the BOOSTXL-DRV8305EVM motor driver sense pins it will only read the m
#include "adc.h" #include "adc_priv.h" #include "..\other\adc.h" #include "..\other\hw_ints.h" #include "..\other\device.h" //#include "C:\ti\C2000Ware_5_05_00_00\device_support\f2837xd\headers\include\F2837xD_adc.h" COIL_FEEDBACK_TYPE Coil_Feedback; U16 Array[1024]; U16 i; 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_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_NUMBER0, ADC_TRIGGER_EPWM2_SOCA, // ADC_CH_ADCIN3, ADC_SAMPLING_WINDOW); // ADCINC3 // ADC_setupSOC(ADCA_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_EPWM2_SOCA, // ADC_CH_ADCIN3, ADC_SAMPLING_WINDOW); // ADCINA3 // ADC_setupSOC(ADCC_BASE, ADC_SOC_NUMBER1, ADC_TRIGGER_EPWM2_SOCA, // ADC_CH_ADCIN2, ADC_SAMPLING_WINDOW); // ADCINC2 // ADC_setupSOC(ADCB_BASE, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM2_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_A_Raw = AdcaResultRegs.ADCRESULT0 if (i > 1023) { i = 0; } Array[i++] = Coil_Feedback.V_Sen_A_Raw; // Coil_Feedback.V_Sen_B_Raw = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER0); // Coil_Feedback.V_Sen_Pvdd_Raw = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER1); // Coil_Feedback.I_Sen_A_Raw = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER1); // Coil_Feedback.I_Sen_B_Raw = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER0); // 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 //