Sie sind auf Seite 1von 4

IIR main:

/*
* main.c
*
* Author: GSI
*/

#include <usbstk5515.h>
#include <AIC_func.h>
#include <stdio.h>
#include <Dsplib.h>

#define NUM_SEC 4
#define BIQ_COEFF 6

//useful for timing routine!


#define TCR0 *((ioport volatile Uint16 *)0x1810)
#define TIMCNT1_0 *((ioport volatile Uint16 *)0x1814)
#define TIME_START 0x8001
#define TIME_STOP 0x8000

Uint16 start_time, end_time, delta_time;

Int16 biq[NUM_SEC * BIQ_COEFF];

Int16 delay_DF1_buff [NUM_SEC * 4];

Int32 biq_32[NUM_SEC * BIQ_COEFF] = {


6533, -6592, 0, 32768, -15268, 0,
32768, -65905, 33139, 32768, -31738, 8723,
32768, -65003, 32237, 32768, -35815, 14008,
32768, -65406, 32641, 32768, -43896, 24562};

Int16 IIR_DF1(Int16 input, Int16 *biq, Int16 *delay_buff, Uint16 Num_Sec);

void main(void) {
Uint16 i;
Int16 input, notUsed, output;
USBSTK5515_init();

//TODO: Convert each of the filter coeff. from 32-bit Q15 to 16-bit Q14.
for(i=0; i<NUM_SEC; i++)
{
biq[(i*BIQ_COEFF) ] = biq_32[(i*BIQ_COEFF) ] >>15; //b0
biq[(i*BIQ_COEFF)+1] = biq_32[(i*BIQ_COEFF)+1] >>15; //b1
biq[(i*BIQ_COEFF)+2] = biq_32[(i*BIQ_COEFF)+2] >>15; //b2

biq[(i*BIQ_COEFF)+3] = biq_32[(i*BIQ_COEFF)+3] >>15; //a0 -- this


one is actually ignored.
biq[(i*BIQ_COEFF)+4] = biq_32[(i*BIQ_COEFF)+4] >>15; //a1
biq[(i*BIQ_COEFF)+5] = biq_32[(i*BIQ_COEFF)+5] >>15; //a2
}
for(i=0; i<NUM_SEC*4; i++)
delay_DF1_buff[i] = 0; //Initialize the registers to zero

AIC_init();
while(1) {
AIC_read2(&input, &notUsed);
output = IIR_DF1(input, biq, delay_DF1_buff, NUM_SEC);
AIC_write2(output, notUsed);
}
}
Int16 IIR_DF1(Int16 input, Int16 *biq, Int16 *delay_buff, Uint16 Num_Sec) {
Uint16 j;
Int16 x;
Int32 Acc;
Int32 un;

// Each stage will have "x" as its input. For the first stage x is the
// actual input, for each stage after that it is the output of the last stage.
x = input;

// Now go through each stage.


for(j=0; j<NUM_SEC; j++) {
un = input - (biq[(j*BIQ_COEFF)+4]*delay_buff[(j*NUM_SEC) ]) -
(biq[(j*BIQ_COEFF)+5]*delay_buff[(j*NUM_SEC)+1]);
Acc = (biq[(j*BIQ_COEFF) ]*un) +
(biq[(j*BIQ_COEFF)+1]*delay_buff[(j*NUM_SEC) ]) +
(biq[(j*BIQ_COEFF)+2]*delay_buff[(j*NUM_SEC)+1]);
// TODO: This will take the 16-bit Q15 values from the
input
// and Z-1 blocks and multiply them by the 16-bit Q14
coeffs
// to get a 32-bit Q29.

Acc = Acc>>15; // TODO Convert to a 16-bit Q15 with rounding and


saturation.

//TODO update the various delay blocks. BE VERY CAREFUL OF THE ORDER!
delay_buff[(j*NUM_SEC)+1] = delay_buff[(j*NUM_SEC) ];
delay_buff[(j*NUM_SEC) ] = un;
// The other two delay blocks go here.

x = (Int16)Acc;
}
return x;
}
INTERUPT:
/*
* Interrupt_test.c
*
* Created on: Jun 28, 2011
* Author: GSI
*/

#include <usbstk5515.h>
#include <usbstk5515_interrupts.h>
#include <stdio.h>
#define LED_OUT1 *((ioport volatile Uint16*)0x1c0a)
#define LED_OUT2 *((ioport volatile Uint16*)0x1c0b)
#define LED_DIR1 *((ioport volatile Uint16*)0x1c06)
#define LED_DIR2 *((ioport volatile Uint16*)0x1c07)

#define TINT 0x20


#define TINT_BIT 4

#define TIME_START 0x8001


#define TIME_STOP 0x8000
#define TIME_START_AUTOLOAD 0x8003

Uint32 program_counter = 0; // This counter is used for your own application

void Reset();

void My_LED_init()
{
LED_DIR1 |= 0xC000;
LED_DIR2 |= 0x0003;

LED_OUT1 |= 0xC000; //Set LEDs 0, 1 to off


LED_OUT2 |= 0x0003; //Set LEDs 2, 3 to off
}

interrupt void Timer_Handler()


{
program_counter++;
TIAFR = 0x0001;

Uint16 time_set;
Uint32 reset_loc = (Uint32)Reset;

void Timer_setup()
{
//Set up Interrupt Vector Pointer Table
IVPD = reset_loc >> 8;
IVPH = reset_loc >> 8;
*((Uint32*)((reset_loc + TINT)>>1)) = (Uint32)Timer_Handler; //Table points to
our handler

IER0 |= (1 << TINT_BIT);//enable interrupt


IFR0 &= (1 << TINT_BIT);//clear the flag

TCR0 = TIME_STOP;
TPR0_1 = 199;
//Set the other period reg and both counters to 0
TPR0_2 = TCR0_1 = TCR0_2 = 0;

TIAFR = 0x0007; // Set the flag

TCR0 |= TIME_START_AUTOLOAD;
}

void main1(void)
{
// Uint16 change = 0xFFFF;
USBSTK5515_init();
My_LED_init();
Timer_setup();
_enable_interrupts();

if(IER0 == 0)
{
printf("erb?, no enabled interrupts\n");
goto TERMINATE;
}

while(1)
{
if(program_counter >= (Uint32)50000)
{
program_counter = 0;
LED_OUT1 ^= 0xC000;
LED_OUT2 ^= 0x0003;

}
}
TERMINATE:
printf("TERMINATING\n");