Hi,
I am trying to use C3x/C4x Optimizing C Compiler to compile a c code to run on a dps. I used a batch file to compile it and I want to open an external txt file to get the input for the C program. However, I get this error msg when I compile:
@echo off
cl30 -g -mn -v40 -q -x2 -o2 -fr . -iC:\M44\Include\Target -iC:\c3xtools\INCLUDE .\PMSM.c
IF ERRORLEVEL == 255 goto failure
lnk30 -o PMSM.out -i c:\m44\lib\target -i c:\m44 -i c:\c3xtools\lib -q -c -stack 0x200 -heap 0x400 -x .\PMSM.obj -l stdio.lib -l periph.lib -l dsp.lib -l prts40.lib -l rts40.lib c:\m44\generic.cmd
echo COMPILE SUCCESS - PMSM.out created
goto end
:failure
echo COMPILE FAILURE
pause
:end
#include <math.h> // defines trig, epx, and hyperbolic math
// functions
#include <intpt40.h> // interrupts???
#include "dsp.h" // commonly requested C-callable digital
#include "periph.h" // definitions for peripheral devices.
#include <stdio.h> // definitions for console terminal.
#include <stdlib.h>
//--------------------------Define Constants---------------------------
#define F_Delta 20E3 // delta_hyst frequency (max = 20k for stable interrupts?).
#define F_DDS 20E6 // frequency of DDS timer.
#define IO_TIMER 1 // channel of IO timer.
#define IO_XRPT 1 // IO interrupt address.
#define IO_TRIG PIT1 // IO trigger.
#define RESOLUTION 4096 // resolution of sine waves.
#define Max_I 20 // maximum allowed current.
#define pi2 6.2831853071796 // 2.0*pi
#define sqrt2 1.4142135623731 // square root of 2.0
#define offset -25 // rotor position offset (for 90deg electrical) in encoder counts. (zero for testing)
#define off_flag 1 // rotor position offset flag (1=active, 0=inactive)
#define P 4 // machine poles.
//--------------------------Define Variables---------------------------
volatile float Ias_pH; // upper commanded current band.
volatile float Ias_nH; // lower commanded current band.
volatile float Ibs_pH; // upper commanded current band.
volatile float Ibs_nH; // lower commanded current band.
volatile float Ics_pH; // upper commanded current band.
volatile float Ics_nH; // lower commanded current band.
volatile float ADC1; // ADC M0 CH0 input.
volatile float ADC2; // ADC M0 CH1 input.
volatile float ADC5; // ADC M1 CH0 input.
volatile float ADC6; // ADC M1 CH1 input.
volatile float ADC7; // ADC M1 CH2 input.
volatile float Ia; // A phase current input.
volatile float Ib; // B phase current input.
volatile float Ic; // C phase current input.
volatile float I; // commanded current
volatile float Ii; // commanded current
volatile float H; // hystersis band
volatile float Hi; // hystersis band
volatile float speed; // commanded speed counter
volatile float deg90; // ninty electrical degrees
volatile int flag; // delta hysteresis flag.
volatile int count; // counter for sinusoids.
volatile int sp_count; // speed counter.
float cos_as[RESOLUTION]; // a phase cosign vector.
float cos_bs[RESOLUTION]; // b phase cosign vector.
float cos_cs[RESOLUTION]; // c phase cosign vector.
int position = 0; // position read directly from position encoder (12 bit)
float qrm = 0.0; // mechanical rotor position in radians
//--------------------------Define Functions---------------------------
#pragma CODE_SECTION(IO_isr, ".onchip"); // define isr as ext interrupt?
#pragma INTERRUPT(IO_isr); // DAC function.
void IO_isr(void); // IO interrupt service routine.
void initialize(void); // initialization function.
void shutdown(void); // shutdown function.
void display(int i, int pcount); // display function.
//--------------------------MAIN FUNCTION------------------------------
/**********************************************************************
Function: main(void)
Description: This is the main function of the application.
**********************************************************************/
main( void )
{
// Define Variables
int i,col, row, pcount; // index variables
float two_pi = 2.0 * (4.0 * atan(1.0)); // 2*pi
float two_pi_third = two_pi/3.0; // 2*pi/3
float a_res = (P/2)*two_pi/RESOLUTION; // position angle resolution
FILE* inputfile; // this is line 96
// Initialize variables
flag = 0; // delta hystersis flag
count = 0; // sinusoid counter flag
sp_count = 1; // speed count
pcount = 0; // print counter
// Initialize DSP
initialize();
// Generate position vector and sine waves
for (i = 0; i <= RESOLUTION; i++)
{
qrm = i*a_res;
cos_as[i] = cos(qrm);
cos_bs[i] = cos(qrm - two_pi_third);
cos_cs[i] = cos(qrm + two_pi_third);
}
// Set up 90 degree offset
deg90 = RESOLUTION/(2*P);
cursor(OFF);
printf("\n\nDacs: ");
wherexy(&col, &row);
// Enable Interrupt
EnableInterrupt(IO_XRPT); // enable IO update interrupt
// Runtime Loop
while(!kbd_hit())
{
inputfile = NULL;//initialize pointer
inputfile = fopen("datafile.txt","r");//open file here
// if (inputfile != NULL)//check if the file exist
// {
fscanf(inputfile,"%f", &Ii);//scan first data
fscanf(inputfile,"%f", &Hi);//scan second data
fclose(inputfile);//close file to reset the pointer...........