You are on page 1of 2

#include <plib.

h>
// Configuration Bit settings
// SYSCLK = 72 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV)
// PBCLK = 36 MHz
// Primary Osc w/PLL (XT+,HS+,EC+PLL)
// WDT OFF
// Other options are don't care
//
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OF
F
#pragma config POSCMOD = HS,FNOSC = PRIPLL,FPBDIV = DIV_2
//Let compile time pre-processor calculate the PR1 (period)
#define FOSC 80E6
#define SYS_FREQ (80000000L)
#define PB_DIV 8
#define PRESCALE 8
#define T1_TICK 0x30D4 // for 10ms
#define FALSE 0
#define TRUE 1
#define FALLING 0
#undef TIMERMODULE
int Dftmain(void);
void WaitTicks(unsigned int Ticks){
while(--Ticks);
}
extern void dft(int *inSignal, int size, unsigned char order, float *mag, float
*phase);
extern float Magnitude, Phase;
extern int Signal[2000];
main(void)
{
unsigned int temp,pbClk;
char HarmonicsOrder;
// SYSTEMConfigPerformance(FOSC);
pbClk = SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
// pbClk = SYSTEMConfig(SYS_FREQ,SYS_CFG_PCACHE);

/* enable cacheability for KSEG0 */


CheKseg0CacheOn();
/* configure the cache for prefetch and 2 wait-state operation */
mCheConfigure(CHE_CONF_WS2 |CHE_CONF_PF_C);
// mCheConfigure(CHE_CONF_PF_C);
#ifdef TIMERMODULE
// Override PBDIV to 1:8 for this timer example
mOSCSetPBDIV(OSC_PB_DIV_8);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 2. configure Timer 1 using internal clock, 1:256 prescale
OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_8, T1_TICK);
// set up the timer interrupt with a priority of 2
ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);
// enable multi-vector interrupts
INTEnableSystemMultiVectoredInt();
#endif
Dftmain();
mPORTESetPinsDigitalOut(BIT_3); //LED
while(1){
mPORTESetBits(BIT_3);
for(HarmonicsOrder=1;HarmonicsOrder<=40;HarmonicsOrder++){
dft(Signal, 160,1, &Magnitude, &Phase);
}
mPORTEClearBits(BIT_3);
mPORTDSetBits(BIT_1);
for(HarmonicsOrder=1;HarmonicsOrder<=40;HarmonicsOrder++){
dft(Signal, 160,1, &Magnitude, &Phase);
}
}
}
#ifdef TIMERMODULE
void __ISR(_TIMER_1_VECTOR, ipl2) Timer1Handler(void)
{
// clear the interrupt flag
mT1ClearIntFlag();
// .. things to do
// .. in this case, toggle the LED
mPORTDToggleBits(BIT_1);
}
#endif

You might also like