This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
I am using the C2000 launchpad (InstSPIN board) with CCS5.4, the ADC channel reading codes are used and in ISR tried to use sin and cosin function the output is in error
code attached
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File #include <stdio.h> #include <math.h> #include <cmath> #define pi 3.14159265358979323846 // Prototype statements for functions found within this file. interrupt void adc_isr(void); void Adc_Config(void); // Global variables used in this example: Uint16 LoopCount; Uint16 ConversionCount; Uint16 Voltage1[10]; Uint16 Voltage2[10]; int i=0,j=0,l=0,m=0,b=0,d=0; float num=0,rmsv1=0,rmsv2=0,V1[25]={0},V2[25]={0},sumv1=0,sumv2=0,V1s[25]={0},V1c[25]={0},V2s[25]={0},V2c[25]={0},sumv1s=0,sumv1c=0,sumv2s=0,sumv2c=0,v1ph=0,v2ph=0,k=0,a=0, b1=0, o=1.57,p=0; main() { InitSysCtrl(); DINT; InitPieCtrl(); // Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000; InitPieVectTable(); EALLOW; // This is needed to write to EALLOW protected register PieVectTable.ADCINT1 = &adc_isr; EDIS; // This is needed to disable write to EALLOW protected registers InitAdc(); // For this example, init the ADC PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable INT 1.1 in the PIE IER |= M_INT1; // Enable CPU Interrupt 1 EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM LoopCount = 0; ConversionCount = 0; // Configure ADC EALLOW; AdcRegs.ADCCTL2.bit.ADCNONOVERLAP = 1; // Enable non-overlap mode AdcRegs.INTSEL1N2.bit.INT1E = 1; //Enabled ADCINT1 AdcRegs.INTSEL1N2.bit.INT1CONT = 0; //Disable ADCINT1 Continuous mode AdcRegs.INTSEL1N2.bit.INT1SEL = 1; //setup EOC1 to trigger ADCINT1 to fire AdcRegs.ADCSOC0CTL.bit.CHSEL = 0; //set SOC0 channel select to ADCINA0 AdcRegs.ADCSOC1CTL.bit.CHSEL = 1; //set SOC1 channel select to ADCINA1 AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 5; //set SOC0 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 AdcRegs.ADCSOC1CTL.bit.TRIGSEL = 5; //set SOC1 start trigger on EPWM1A, due to round-robin SOC0 converts first then SOC1 AdcRegs.ADCSOC0CTL.bit.ACQPS = 6; AdcRegs.ADCSOC1CTL.bit.ACQPS = 6; //set SOC0 S/H Window to 7 ADC Clock Cycles, (6 ACQPS plus 1) GpioCtrlRegs.GPACTRL.all = 0x00000000; GpioCtrlRegs.GPAQSEL1.all = 0x55555555; GpioCtrlRegs.GPAMUX1.all = 0x00000000; // All GPIO GpioCtrlRegs.GPADIR.all = 0xFFFFFFFF; // All outputs GpioCtrlRegs.GPAPUD.all = 0x00000000; // Enable pull-up on GPIO2 EDIS; // Assumes ePWM1 clock is already enabled in InitSysCtrl(); EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOC on A group EPwm1Regs.ETSEL.bit.SOCBEN = 1; EPwm1Regs.ETSEL.bit.SOCASEL = 4; // Select SOC from CMPA on upcount EPwm1Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event EPwm1Regs.CMPA.half.CMPA = 0x0080; // Set compare A value EPwm1Regs.TBPRD = 0x7530; // Set period for ePWM1 EPwm1Regs.TBCTL.bit.CTRMODE = 0; // count up and start // Wait for ADC interrupt for(;;) { LoopCount++; } } interrupt void adc_isr(void) { b++; GpioDataRegs.GPADAT.all = 0x0000000C; //output pulse GPIO2 and GPIO3 high for (i = 0; i < 30 ; i++) {} GpioDataRegs.GPATOGGLE.all = 0x0000000F; //Toggle output bits o=1.78; p= sqrt(129); b1 = sin(pi/2); k = cos(pi/2); a =k*k+(b1*b1); AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //Clear ADCINT1 flag reinitialize for next SOC PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE return; }
Can you give me more details? Are you saying that the values of b1 and k are incorrect when you view them in the Expressions window in CCS? Are you consistently getting the same incorrect values or are they different?
Is it using the default rts2800_fpu32.lib versions of sin/cos (like do you see sinf in s_sinf.c when you step into the function or look at the map file) or some other implementation?
Whitney
Thanks for reply
Yes, if you see the code, its b1=sin (pi/2) and k=cos (pi/2), actually values should have been b1=1 and k=0, when viewed in Expression window in CCS.
The values shown in the Expression window for b1= -0.2902847 and k= 0.9569404 are consistently same, incorrect values.
Possibly it must be using run time support library default rts2800_fpu32.lib or <Automatic>, although the selection is not specifically made.
Now I have tried with both the above things (rts2800_fpu32.lib or <Automatic>), as a run time library and the results are same incorrect values.
If we step into the function, it uses the path given below; $C:/ti/controlSUITE/libs/math/FPUfastRTS/V100/source/sin_f32.asm:62:96$, for sine and $C:/ti/controlSUITE/libs/math/FPUfastRTS/V100/source/cos_f32.asm:62:96$ for cosine values computation
request your inputs
Okay, so you're using the FPUfastRTS library. The FPUfastRTS does sacrifice accuracy in favor of speed. I'm not sure what degree of error is expected but that could be an explanation. (edit: looking at the numbers you're getting that doesn't really make sense as an explanation--I'll look into this further...)
rts2800_fpu32.lib which is typically part of the compiler package has functions called sinf and cosf that can get you more accuracy at the cost of cycle time. What version of the compiler are you using?
Whitney
It just occurred to me that the math tables are in a different location for the F28069M than they are for the F28069. Can you make sure your linker command file is the correct one for the F28069M?
Whitney
Could not locate 28069M_RAM_lnk.cmd file, on any of the cmd folders/directories available in CCS5.4, also could not get the same on net
Presently using 28069_RAM_lnk.cmd , could not resolve the issue
Can you look for the following?
C:\ti\controlSUITE\device_support\f2806x\v151\F2806x_common\cmd\f28069M_ram_lnk.cmd
Whitney
Could locate the file, it compiles the program.
When you run the code, it indicates "No source available for "0x3ff4fa" and in assembly it shows at 3fff4fa 7625 ESTOP0, pl refer the text below
3ff4f6: FE84 SUBB SP, #4
3ff4f7: 0006 LRETR
3ff4f8: 767FF74F LCR 0x3ff74f
3ff4fa: 7625 ESTOP0
3ff4fb: 6FFF SB -1, UNC
When you load the code does it successfully go to main()? If so, when you step through the code, how far do you get before this occurs?
0x3ff4fa is the WaitBoot section of the boot ROM. You can find the boot ROM symbols and source code in the following folder:
C:\ti\controlSUITE\libs\utilities\boot_rom\2806x
Whitney