TI中文支持网
TI专业的中文技术问题搜集分享网站

TMS320F280021: adc采集

WindowF F阅读(26)

Part Number:TMS320F280021

您好,在使用f280021时,发现adc转换出现了问题,他的波动有点剧烈,而且显示的值也有异常,于是使用了例程f280025c的adc_ex10_multiple_soc_epwm.syscfg,进行了一些引脚改动使得可以用来驱动f280021,并将主程序更改为以下内容

//#############################################################################
//
// FILE: adc_ex10_multiple_soc_epwm.c
//
// TITLE: ADC ePWM Triggering Multiple SOC
//
//! \addtogroup driver_example_list
//! <h1>ADC ePWM Triggering Multiple SOC</h1>
//!
//! This example sets up ePWM1 to periodically trigger a set of conversions on
//! ADCA and ADCC. This example demonstrates multiple ADCs working together
//! to process of a batch of conversions using the available parallelism
//! across multiple ADCs.
//!
//! ADCA Interrupt ISRs are used to read results of both ADCA and ADCC.
//!
//! \b External \b Connections \n
//! – A0, A1, A2 and C2, C3, C4 pins should be connected to signals to be
//! converted.
//!
//! \b Watch \b Variables \n
//! – \b adcAResult0 – Digital representation of the voltage on pin A0
//! – \b adcAResult1 – Digital representation of the voltage on pin A1
//! – \b adcAResult2 – Digital representation of the voltage on pin A2
//! – \b adcCResult0 – Digital representation of the voltage on pin C2
//! – \b adcCResult1 – Digital representation of the voltage on pin C3
//! – \b adcCResult2 – Digital representation of the voltage on pin C4
//!
//
//#############################################################################
//
//
// $Copyright:
// Copyright (C) 2023 Texas Instruments Incorporated – http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions// are met:
//// Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.
//// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the// documentation and/or other materials provided with the// distribution.
//// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//#############################################################################
//

//
// Included Files
//
#include "driverlib.h"
#include "device.h"
#include "board.h"

//
// Globals
//
uint16_t adcAResult0;
uint16_t adcAResult1;
uint16_t adcAResult2;
uint16_t adcCResult0;
uint16_t adcCResult1;
uint16_t adcCResult2;

float32_t adcAResult0_f;
float32_t adcAResult1_f;
float32_t adcAResult2_f;
float32_t adcCResult0_f;
float32_t adcCResult1_f;
float32_t adcCResult2_f;
//
// Function Prototypes
//
void initEPWM();
__interrupt void adcA1ISR(void);

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

//
// Disable pin locks and enable internal pullups.
//
Device_initGPIO();

//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();

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

//
// Set up the ADCA and ADCC and initialize the ADC SOC.
// ADC Resolution – 12-bit, signal mode – single ended
// ADCA SOC0, SOC1, SOC2 are configured to convert A0,
// A1 and A2 channels with EPWM1SOCA as SOC trigger.
// ADCC SOC0, SOC1, SOC2 are configured to convert C2,
// C3, C4 channels with EPWM1SOCA as trigger
//
Board_init();

/*custom*/
ADC_setupSOC(myADC0_BASE, ADC_SOC_NUMBER3, ADC_TRIGGER_EPWM1_SOCA, ADC_CH_ADCIN6, 8U);
ADC_setInterruptSOCTrigger(myADC0_BASE, ADC_SOC_NUMBER3, ADC_INT_SOC_TRIGGER_NONE);
ADC_setInterruptSource(myADC0_BASE, ADC_INT_NUMBER1, ADC_SOC_NUMBER3);
ADC_clearInterruptStatus(myADC0_BASE, ADC_INT_NUMBER1);
ADC_disableContinuousMode(myADC0_BASE, ADC_INT_NUMBER1);
ADC_enableInterrupt(myADC0_BASE, ADC_INT_NUMBER1);

/*custom*/

//
// Configure EPWM1 ADC SOCA trigger
//
initEPWM();

//
// Enable ADC interrupt
//
Interrupt_enable(INT_ADCA1);

//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;

//
// Start ePWM1, enabling SOCA and putting the counter in up-count mode
//
EPWM_enableADCTrigger(EPWM1_BASE, EPWM_SOC_A);
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_UP);

//
// Take conversions indefinitely in loop
//
do
{
//
// Wait while ePWM causes ADC conversions.
// ADCA1 ISR processes each new set of conversions.
//
}
while(1);
}

//
// Function to configure ePWM1 to generate the SOC.
//
void initEPWM(void)
{
//
// Disable SOCA
//
EPWM_disableADCTrigger(EPWM1_BASE, EPWM_SOC_A);

//
// Configure the SOC to occur on the first up-count event
//
EPWM_setADCTriggerSource(EPWM1_BASE, EPWM_SOC_A, EPWM_SOC_TBCTR_U_CMPA);
EPWM_setADCTriggerEventPrescale(EPWM1_BASE, EPWM_SOC_A, 1);

//
// Set the compare A value to 1000 and the period to 1999
// Assuming ePWM clock is 100MHz, this would give 50kHz sampling
// 50MHz ePWM clock would give 25kHz sampling, etc.
// The sample rate can also be modulated by changing the ePWM period
// directly (ensure that the compare A value is less than the period).
//
EPWM_setCounterCompareValue(EPWM1_BASE, EPWM_COUNTER_COMPARE_A, 1000);
EPWM_setTimeBasePeriod(EPWM1_BASE, 1999);

//
// Set the local ePWM module clock divider to /1
//
EPWM_setClockPrescaler(EPWM1_BASE,
EPWM_CLOCK_DIVIDER_1,
EPWM_HSCLOCK_DIVIDER_1);

//
// Freeze the counter
//
EPWM_setTimeBaseCounterMode(EPWM1_BASE, EPWM_COUNTER_MODE_STOP_FREEZE);
}

//
// ADC A Interrupt 1 ISR
//
__interrupt void adcA1ISR(void)
{
//
// Store results
//
adcAResult0 = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
adcAResult1 = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER1);
adcAResult2 = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER3); // custom change
adcCResult0 = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER0);
adcCResult1 = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER1);
adcCResult2 = ADC_readResult(ADCCRESULT_BASE, ADC_SOC_NUMBER2);

/*custom*/
adcAResult0_f = adcAResult0*(float32_t)0.08058608;
adcAResult1_f = adcAResult1*(float32_t)0.08058608;
adcAResult2_f = adcAResult2*(float32_t)0.08058608;
adcCResult0_f = adcCResult0*(float32_t)0.08058608;
adcCResult1_f = adcCResult1*(float32_t)0.08058608;
adcCResult2_f = adcCResult2*(float32_t)0.08058608;

/*custom*/
//
// 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
//

3.3V电压接入A6引脚时 adcAResult2显示为1537,而非4095,接入gnd显示372,而非0

Ben Qin:

你好,280021和280025应该是pin to pin的,不用改动引脚就可以驱动。

您还有其他的芯片吗?是只有这一片有问题还是都有问题?

,

WindowF F:

在21上的A6是4号引脚,而25是6号引脚,是的,都有问题,而且只有A6有问题,其他的AIO都是完好的,数值完全正确

,

Ben Qin:

芯片是在官网上购买的吗?如果是的话可以尝试在官网更换芯片。

TMS320F280049C: 有什么办法能替代 gcc 中的 __attribute__((used))

Quincy Wang阅读(28)

Part Number:TMS320F280049C

我准备移植一份使用 GCC 编译的代码,代码中有 __attribute__((used)) 修饰的变量。在C2000 的工程中,这个修饰并不会生效,导致代码执行异常。

请问 C2000 的编译套件,有和办法能达到类似的效果?

Ben Qin:

并没有移植这方面的相关资料,但是你可以参考下C2000编译器指南:

TMS320C28x Optimizing C/C++ Compiler v22.6.0.LTS User's Guide (Rev. Y)

TMS320F2800137: 使用flash Api写flash,oFlashStatus = Fapi_getFsmStatus();返回257

xiang li阅读(37)

Part Number:TMS320F2800137

void App_FlashUpdate(void)
{Fapi_StatusType oReturnCheck;Fapi_FlashStatusType  oFlashStatus;Uint16 u16Temp[8] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};DINT;EALLOW;oReturnCheck = Fapi_initializeAPI(FlashTech_CPU0_BASE_ADDRESS,120);if(oReturnCheck != Fapi_Status_Success){App_WaitRestart();}oReturnCheck = Fapi_setActiveFlashBank(Fapi_FlashBank0);if(oReturnCheck != Fapi_Status_Success){App_WaitRestart();}ClearFSMStatus();Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTA, 0xFFFFFFFF);Fapi_setupBankSectorEnable(FLASH_WRAPPER_PROGRAM_BASE+FLASH_O_CMDWEPROTB, 0x00000000);oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)0x08EFF8,u16Temp,8,0,0,Fapi_AutoEccGeneration);while(Fapi_checkFsmForReady() == Fapi_Status_FsmBusy);if(oReturnCheck != Fapi_Status_Success){App_WaitRestart();// Check Flash API documentation for possible errors}DEVICE_DELAY_US(100);oFlashStatus = Fapi_getFsmStatus();if (oFlashStatus != 3){App_WaitRestart();}EDIS;App_WaitRestart();
}

目的是将0x8EFF8的值0xbbbb写为0x0000

xiang li:

使用的flash API库

,

xiang li:

出现的问题是,经常写入失败,偶尔能够写入成功

写入失败的时候:oFlashStatus = Fapi_getFsmStatus();返回257
写入成功的时候:oFlashStatus = Fapi_getFsmStatus();返回0

,

xiang li:

我把0xbbbb写为0x0000,并没有将存储的0值程序化为1,为啥会报这个错误

,

xiang li:

找到问题了,u16Temp首地址为奇数,改为偶数就可以了,为啥必须是偶数,哪个文档有介绍吗

,

Ben Qin:

可以参考下下面这个链接的第10条回答:

(+) [FAQ] FAQ on Flash API usage for C2000 devices – C2000 microcontrollers forum – C2000Tm︎ microcontrollers – TI E2E support forums

TMS320F280025: Bootloader在实现程序跳转时提示No source available for "SysCtl_delay() at G:/**\**\**.out:{3} 0x82852{4}" ,或者直接跳到Interrupt_illegalOperationHandler这个中断

Black Wan阅读(33)

Part Number:TMS320F280025

我在使用两种方法实现程序跳转,分别会报下面图片中的两种错误

第一种:直接通过地址跳转

EALLOW;
IER = 0x0000;
IFR = 0x0000;
EDIS;
__disable_interrupts();
((void(*)())0x080000)();

第二种是看门狗复位

Ben Qin:

你好,您是指从bootloader跳转至app吗?你可以先参考下下面这个资料:

DSP bootloader程序引导开发指南(一)—— 初识Bootloader – 知乎 (zhihu.com)

,

Black Wan:

这个我知道,我现在是一样的程序,然后用280039的芯片就能正常跳转,280025是能从bootloader跳转到app,但是从app跳不回bootloader

,

Ben Qin:

我查看下相关资料后回复您。

TMS320F2800157: snprintf的问题

John Pan阅读(30)

Part Number:TMS320F2800157

snprintf在把整数转为字符串时,可以正常转。

在把浮点数转为字符串时,会导致程序异常。

请问要把浮点数转为字符串,应该怎么办?

#define SPRINTF_BUFFER_SIZE 100
char sprintfBuffer[SPRINTF_BUFFER_SIZE] = {0};
snprintf(sprintfBuffer, SPRINTF_BUFFER_SIZE-1, "%d", 12);      // 把整数转为字符串,OK
snprintf(sprintfBuffer, SPRINTF_BUFFER_SIZE-1, "%f", 1.23);    // 把浮点数转为字符串,程序会异常

John Pan:

还有一个问题

int tmpi = 12;

snprintf(sprintfBuffer, SPRINTF_BUFFER_SIZE-1, "%d\n", tmpi); // 值通过变量传给snprintf函数,转出来的字符串是"0",按理应该是12

,

John Pan:

还有一个问题

int tmpi = 12;

snprintf(sprintfBuffer, SPRINTF_BUFFER_SIZE-1, "%d\n", tmpi); // 值通过变量传给snprintf函数,转出来的字符串是"0",按理应该是12

—————————-这个问题解决了,不用管

,

Ben Qin:

查看下下面的资料看是否有帮助:

(+) CCS/LAUNCHXL-F28379D: Convert a Float number to String. – C2000 microcontrollers forum – C2000Tm︎ microcontrollers – TI E2E support forums

(+) CCS/LAUNCHXL-F28379D: Convert a Float to String. – C2000 microcontrollers forum – C2000Tm︎ microcontrollers – TI E2E support forums

Tips for Using Printf

TMS320F280049: 编译报错

Zhang Meimei阅读(25)

Part Number:TMS320F280049

编译时报错:Invalid project path: Missing project folder or file: \V1421Z\App\logic for Source path. 请大佬帮忙分析一下是什么问题

Yale Li:

根据报错信息来看,是工程文件夹或工程文件丢失,就是这个源文件路径:\V1421Z\App\logic

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1