Thread 中讨论的其他器件: SYSBIOS、 TM4C123GH6PM、 C2000WARE、 controlSUITE
工具与软件:
嘿、Fellas、我是一名新手、正在使用具有控制卡的 TMS320F28335、您可以看到下面。 我正在对其运行 SYS/BIOS、并想使用 ADC 来测量交流电压。 我无法通过数据表弄清楚初始化序列。 我从一个示例开始、但它显示了错误。 我发布了 我写入用于切换 GPIO 的代码、现在我要尝试在其中添加一个 ADC 任务。 但在此之前、我想通过内置功能来校准 ADC、所以会出现错误。
代码如下:
/*
* ======== main.c ========
*/
#include <xdc/std.h>
#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/hal/Hwi.h>
#include <ti/sysbios/knl/Semaphore.h>
extern const ti_sysbios_knl_Semaphore_Handle sem0,sem1;
#include "include/DSP28x_Project.h"
#define GPAQSEL1 (*((volatile UInt16 *)0x6F82)) //GPA Qualifier Select. It works like how many samples required to register an Input
#define GPAMUX1 (*((volatile UInt16 *)0x6F86)) // GPA MUX 1 register for gpio 0 -15
#define GPADIR (*((volatile UInt16 *)0x6F8A)) // GPA Direction Input/Output
#define GPAPUD (*((volatile UInt16 *)0x6F8C)) // GPA Internal Pull-Up 0-enable/1-Disable
#define GPACTRL (*((volatile UInt16 *)0x6F80)) // GPIO Port control
#define GPADAT (*((volatile UInt16 *)0x6FC0)) // GPIO Data Register
#define GPASET (*((volatile UInt16 *)0x6FC2)) // GPIO SET pin state
#define GPACLEAR (*((volatile UInt16 *)0x6FC4)) // GPIO Clear pin state
#define GPATOGGLE (*((volatile UInt16 *)0x6FC6)) // GPIO Toggle the pin state
#define ADC_Cal (void (*) (void)) 0x380080
UInt16 counter=0;
static UInt32 count=0;
/*
* ======== taskFxn ========
*/
Void taskFx1(UArg a0, UArg a1)
{
for(;;){
Semaphore_pend(sem0, BIOS_WAIT_FOREVER);
count+= 1;
System_printf("enter taskFx1(): %i",count);
// System_printf((char*)count);
Task_sleep(1000);
GPASET = (1<<2);
// Task_sleep(1000);
// GPATOGGLE = (1<<2);
// System_printf("exit taskFxn()\n");
// Task_sleep(1000);
System_flush(); /* force SysMin output to console */
Semaphore_post(sem1);
}
}
Void taskFx2(UArg a0, UArg a1)
{
for(;;){
Semaphore_pend(sem1, BIOS_WAIT_FOREVER);
Task_sleep(1000);
GPACLEAR = (1<<2);
if(counter >= 10){
counter = 0;
System_printf("\tenter taskFx2()\n");
// GPACLEAR = (1<<2);
// Task_sleep(100);
GPATOGGLE = (1<<1);
// System_printf("Exit taskFxn()\n");
// Task_yeild(&task);
System_flush(); /* force SysMin output to console */
}
counter++;
Semaphore_post(sem0);
}
}
/*
* ======== main ========
*/
Int main()
{
EALLOW;
Task_Handle task,task2;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;
(*ADC_Cal) ();
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0;
Error_Block eb;
GPAMUX1 = 0;
GPAQSEL1 |= 2; // Sampling 6 times- If the state is same for 6 clocks it'll be registered on DSP
GPADIR = 0;
GPADIR |= (3<<1); //PIN 2 as OUTPUT and rest are INPUT by default
GPAPUD = 0; //Clear pull up register
GPAPUD |= 0xFFFE; // Enable pull-up for GPIOA 2
GPACTRL = 0; // Enable CLock for Pin 7-0
GPACLEAR |= (3<<1);
EDIS;
System_printf("enter main()\n");
Error_init(&eb);
task = Task_create(taskFx1, NULL, &eb);
task2 = Task_create(taskFx2, NULL, &eb);
// Semaphore_create(sem0, NULL, &eb);
// Semaphore_create(sem1, NULL, &eb);
// Semaphore_post(sem0);
if (task == NULL || task2 == NULL) {
System_printf("Task_create() failed!\n");
BIOS_exit(0);
}
BIOS_start(); /* does not return */
return(0);
}
这是.cfg 文件:
var Defaults = xdc.useModule('xdc.runtime.Defaults');
var Diags = xdc.useModule('xdc.runtime.Diags');
var Error = xdc.useModule('xdc.runtime.Error');
var Log = xdc.useModule('xdc.runtime.Log');
var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
var Main = xdc.useModule('xdc.runtime.Main');
var Memory = xdc.useModule('xdc.runtime.Memory')
var SysMin = xdc.useModule('xdc.runtime.SysMin');
var System = xdc.useModule('xdc.runtime.System');
var Text = xdc.useModule('xdc.runtime.Text');
var BIOS = xdc.useModule('ti.sysbios.BIOS');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Swi = xdc.useModule('ti.sysbios.knl.Swi');
var Task = xdc.useModule('ti.sysbios.knl.Task');
var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
var Hwi = xdc.useModule('ti.sysbios.family.c28.Hwi');
/*
* Uncomment this line to globally disable Asserts.
* All modules inherit the default from the 'Defaults' module. You
* can override these defaults on a per-module basis using Module.common$.
* Disabling Asserts will save code space and improve runtime performance.
Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
*/
/*
* Uncomment this line to keep module names from being loaded on the target.
* The module name strings are placed in the .const section. Setting this
* parameter to false will save space in the .const section. Error and
* Assert messages will contain an "unknown module" prefix instead
* of the actual module name.
Defaults.common$.namedModule = false;
*/
/*
* Minimize exit handler array in System. The System module includes
* an array of functions that are registered with System_atexit() to be
* called by System_exit().
*/
System.maxAtexitHandlers = 4;
/*
* Uncomment this line to disable the Error print function.
* We lose error information when this is disabled since the errors are
* not printed. Disabling the raiseHook will save some code space if
* your app is not using System_printf() since the Error_print() function
* calls System_printf().
Error.raiseHook = null;
*/
/*
* Uncomment this line to keep Error, Assert, and Log strings from being
* loaded on the target. These strings are placed in the .const section.
* Setting this parameter to false will save space in the .const section.
* Error, Assert and Log message will print raw ids and args instead of
* a formatted message.
Text.isLoaded = false;
*/
/*
* Uncomment this line to disable the output of characters by SysMin
* when the program exits. SysMin writes characters to a circular buffer.
* This buffer can be viewed using the SysMin Output view in ROV.
SysMin.flushAtExit = false;
*/
/*
* The BIOS module will create the default heap for the system.
* Specify the size of this default heap.
*/
BIOS.heapSize = 0x800;
/*
* Build a custom SYS/BIOS library from sources.
*/
BIOS.libType = BIOS.LibType_Custom;
/* System stack size (used by ISRs and Swis) */
Program.stack = 0x100;
/* Circular buffer size for System_printf() */
SysMin.bufSize = 0x200;
/*
USER CODE
*/
var sem0Params = new Semaphore.Params();
sem0Params.instance.name = "sem0";
Program.global.sem0 = Semaphore.create(1, sem0Params);
var sem1Params = new Semaphore.Params();
sem1Params.instance.name = "sem1";
Program.global.sem1 = Semaphore.create(1, sem1Params);
var task1Params = new Task.Params();
task1Params.instance.name = "task1";
Program.global.task1 = Task.create("&taskFx1", task1Params);
var task1Params = new Task.Params();
task1Params.instance.name = "task2";
Program.global.task2 = Task.create("&taskFx2", task1Params);
/*
* Create and install logger for the whole system
*/
var loggerBufParams = new LoggerBuf.Params();
loggerBufParams.numEntries = 32;
var logger0 = LoggerBuf.create(loggerBufParams);
Defaults.common$.logger = logger0;
Main.common$.diags_INFO = Diags.ALWAYS_ON;
System.SupportProxy = SysMin;
错误:

我想要的是使用 ePWM 触发 ADC SoC、或者假设我要对220V 的交流50Hz 波进行采样、至少为2uS。 我只是想从头开始了解它。 我用中断(不是 TI-RTOS)在 TM4C123GH6PM 上完成了相同的任务、一切都运行正常。 但 C2000的数据表不太友好。