Part Number:TMS320F28379D
#include "Includes.h" #include "RFFT.h" //adc.h ADC_RESOLUTION_xBIT 重复定义 #define RESULTS_BUFFER_SIZE2048 #define EX_ADC_RESOLUTION12 // #pragma DATA_SECTION(FFT_input, "ramgs0") uint16_t FFT_input[RESULTS_BUFFER_SIZE]; uint16_t periodCount;//采样率=100M/((periodCount-1)+1) volatile uint16_t bufferFull;// Flag to indicate buffer is full extern RFFT_Analyse_Struct rfft_analyse; void initADC(void); void initEPWM(void); void initADCSOC(void); __interrupt void adcA1ISR(void); void LED_Init(void); void configureDMAChannels(void); void initializeDMA(void); __interrupt void dmach1ISR(void); void main(void) { //确定运行模式,使用CPU2 #ifdef _STANDALONE #ifdef _FLASHIPCBootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_FLASH); #elseIPCBootCPU2(C1C2_BROM_BOOTMODE_BOOT_FROM_RAM); #endif #endif//设备初始化Device_init();//GPIO初始化Device_initGPIO();Interrupt_initModule();Interrupt_initVectorTable();Interrupt_register(INT_ADCA1, &adcA1ISR);Interrupt_register(INT_DMA_CH1, &dmach1ISR);periodCount=50;initADC();initEPWM();initADCSOC();LED_Init();SCI_A_Init(115200);for(int index = 0; index < RESULTS_BUFFER_SIZE; index++){FFT_input[index] = 0;}bufferFull = 0;Interrupt_enable(INT_ADCA1);Interrupt_enable(INT_DMA_CH1);initializeDMA();configureDMAChannels();DMA_clearTriggerFlag(DMA_CH1_BASE);// DMA channel 1//开启总中断Interrupt_enableMaster();DMA_startChannel(DMA_CH1_BASE);EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);while(bufferFull == 0){}bufferFull = 0; //RFFT_ADC_Init();for(int index = 0; index < RESULTS_BUFFER_SIZE; index++)micro_print(SCIA_BASE,"signal:%d\n",FFT_input[index]); //RFFT_ADC_Caculate();while(1){NOP;} } void LED_Init(void) {GPIO_setPinConfig(DEVICE_GPIO_CFG_LED1);GPIO_setMasterCore(DEVICE_GPIO_PIN_LED1, GPIO_CORE_CPU1);GPIO_setPadConfig(DEVICE_GPIO_PIN_LED1, GPIO_PIN_TYPE_STD);GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED1, GPIO_DIR_MODE_OUT);GPIO_WritePin(DEVICE_GPIO_PIN_LED1, 1);GPIO_setPinConfig(DEVICE_GPIO_CFG_LED2);GPIO_setMasterCore(DEVICE_GPIO_PIN_LED2, GPIO_CORE_CPU1);GPIO_setPadConfig(DEVICE_GPIO_PIN_LED2, GPIO_PIN_TYPE_STD);GPIO_setDirectionMode(DEVICE_GPIO_PIN_LED2, GPIO_DIR_MODE_OUT);GPIO_WritePin(DEVICE_GPIO_PIN_LED2, 1); } void initADC(void) {ADC_setPrescaler(ADCA_BASE, ADC_CLK_DIV_4_0); #if(EX_ADC_RESOLUTION == 12)ADC_setMode(ADCA_BASE, ADC_RESOLUTION_12BIT_0x00U, ADC_MODE_SINGLE_ENDED);//ADC_RESOLUTION_12BIT_0x00U #elif(EX_ADC_RESOLUTION == 16)ADC_setMode(ADCA_BASE, ADC_RESOLUTION_16BIT_0x40U, ADC_MODE_DIFFERENTIAL); #endifADC_setInterruptPulseMode(ADCA_BASE, ADC_PULSE_END_OF_CONV);ADC_enableConverter(ADCA_BASE);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, 10);EPWM_setTimeBasePeriod(EPWM1_BASE, periodCount-1);EPWM_setClockPrescaler(EPWM1_BASE,EPWM_CLOCK_DIVIDER_1,EPWM_HSCLOCK_DIVIDER_1);EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE); } void initADCSOC(void) {uint32_t adcBase = ADCA_BASE;uint16_t channel = ADC_CH_ADCIN0;uint16_t acqps; #if(EX_ADC_RESOLUTION == 12)acqps = 15; #elif(EX_ADC_RESOLUTION == 16)acqps = 64; #endif// Configure SOCs channel no. & acquisition window.// Trigger SCO0 from EPWM2SOCA.// Trigger all other SOCs from INT1 (EOC on SOC0).//ADC_setupSOC(adcBase, ADC_SOC_NUMBER0, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER1, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER2, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER3, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER4, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER5, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER6, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER7, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER8, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER9, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER10, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER11, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER12, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER13, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER14, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setupSOC(adcBase, ADC_SOC_NUMBER15, ADC_TRIGGER_EPWM1_SOCA,(ADC_Channel)channel, acqps);ADC_setInterruptSource(ADCA_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER15);ADC_enableInterrupt(ADCA_BASE, ADC_INT_NUMBER1);ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1); } __interrupt void adcA1ISR(void) {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);}Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1); } __interrupt void dmach1ISR(void) {bufferFull = 1;EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP7); } void initializeDMA(void) {DMA_initController();DMA_setEmulationMode(DMA_EMULATION_FREE_RUN); } void configureDMAChannels(void) {DMA_configAddresses(DMA_CH1_BASE, (uint16_t *)&FFT_input,(uint16_t *)ADCARESULT_BASE);DMA_configBurst(DMA_CH1_BASE, 16, 2, 2);DMA_configTransfer(DMA_CH1_BASE, (RESULTS_BUFFER_SIZE >> 4), -14, 2);DMA_configMode(DMA_CH1_BASE, DMA_TRIGGER_ADCA1,(DMA_CFG_ONESHOT_DISABLE | DMA_CFG_CONTINUOUS_DISABLE |DMA_CFG_SIZE_32BIT));DMA_enableTrigger(DMA_CH1_BASE);DMA_disableOverrunInterrupt(DMA_CH1_BASE);DMA_setInterruptMode(DMA_CH1_BASE, DMA_INT_AT_END);DMA_enableInterrupt(DMA_CH1_BASE); }
Yale Li:
能具体描述一下遇到的问题及你的需求吗?
,
? ??:
我想使用epwm1去触发16个soc用于adca0顺序转换,并用dma传送数据。但是采样频率一直保持在4m左右,更改epwm的频率采样率也不会变,我想知道是我的程序哪里有问题吗?
,
? ??:
我是参考的adc_ex6_soc_continuous_dma这个例程,我将该例程中soc1-soc15的软件触发改成了epwm1触发
,
? ??:
我使用epwm只触发soc0,采样率是可以调节的
,
Yale Li:
因为你使用的是同一个EPWM_SOC来触发所有的SOC,所以涉及到了SOC的转换优先级仲裁。因为一个ADC模块中只有1个ADC核,所以转换并不能同时发生,是以一定顺序进行的。在设计采样率的时候需要将这些因素也考虑进去。这部分内容请看一下spruhm8i_TMS320F2837xD Dual-Core Delfino Microcontrollers Technical Reference Manual (Rev. I)第1564页11.7 ADC Conversion Priority。