Other Parts Discussed in Thread: TIDA-01606, TIDA-010210, CONTROLSUITE, C2000WARE
Hi,
I want to create a sin graph of RampGen so I used the lib file inside of TI. (/cfs-file/__key/communityserver-discussions-components-files/171/SolarLib.pdf Page 157). I tried to use CpuTimer0 as an interrupt and with every interrupt it should have created a ramp. After that, I took the sin of the function. However, I can not get the correct graph. Also, I am not sure If I create the Ramp graph right. I researched the TI sources and I could not solve it. I put my code down and hope you can show me the parts that should be corrected. Also, for these values what should I enter into graph properties? If you want, I can add the full file as a zip file and put the graph results.
MAIN FILE:
#include "Lab.h" // Main include file
#include "Solar_IQ.h"
//--- Global Variables
// I used a buffer to get the correct result. I named that AdcBuf1IQ but it is not about ADC it is just a name. I did not change too much from previous examples.
Uint16 AdcBuf1[ADC_BUF_LEN]; // ADC data buffer allocation
_iq AdcBuf1IQ[ADC_BUF_LEN]; // ADC data buffer allocation - IQ
long GlobalQ = GLOBAL_Q; // IQmath debug support
RAMPGEN_IQ Ramp;
/**********************************************************************
* Function: main()
*
* Description: Main function for C28x
**********************************************************************/
void main(void)
{
//--- CPU Initialization
InitSysCtrl(); // Initialize the CPU (FILE: SysCtrl.c)
InitGpio(); // Initialize the shared GPIO pins (FILE: Gpio.c)
InitPieCtrl(); // Initialize and enable the PIE (FILE: PieCtrl.c)
InitWatchdog(); // Initialize the Watchdog Timer (FILE: WatchDog.c)
//--- Peripheral Initialization
InitAdc(); // Initialize the ADC (FILE: Adc.c)
InitEPwm(); // Initialize the EPwm (FILE: EPwm.c)
InitECap(); // Initialize the ECap (FILE: ECap.c)
//RAMPGEN Variables
RAMPGEN_IQ_init(&Ramp);
Ramp.Freq = _IQ24(90);
Ramp.StepAngleMax = _IQ24(1.0/1000);
CpuTimer0.InterruptCount = 0;
//LEDcount=0;
DINT; // Disable CPU Interrupts
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &TINT0_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
//CPU Configuration//
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 90,1000000); //90 MHz, 500 000 uSecond
// Use write-only instruction to set TSS bit = 0
CpuTimer0Regs.TCR.all = 0x4000;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; /
IER |= M_INT1;
EINT;
ERTM;
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &TINT0_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
//--- Main Loop
while(1) // endless loop - wait for an interrupt
{
asm(" NOP");
}
} //end of main()
/*** end of file *****************************************************/
ISR file;
interrupt void TINT0_ISR(void) // PIE1.7 @ 0x000D4C TINT0 (CPU TIMER 0)
{
CpuTimer0.InterruptCount++;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Must acknowledge the PIE group
static _iq *AdcBuf1IQPtr = AdcBuf1IQ; // Pointer to ADC data buffer
extern RAMPGEN_IQ Ramp;
RAMPGEN_IQ_MACRO(Ramp);
//--- Manage the ADC registers
AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear ADCINT1 flag
*AdcBuf1IQPtr++ = Ramp.Out; // When I want to see sin graph of it, I change that line to ' AdcBuf1IQPtr++ = _IQsinPU(Ramp.Out) '.
}