cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
176 Views
Registered: ‎08-22-2019

Fir with spi protocol

Hi, I am trying to make a Fir filter but with data acquisition through SPI protocol, my problem is when I want to save the new acquired data and move the past samples. My ap_int<16> array of size 20 only saves the current element because when I finish the program 1 time it restarts putting my array in 0s. How can I make my samples to be saved and shifted as I acquire new ones without restarting?

 

void fir(ap_int<16> TX, bool *MISO, bool *MOSI, volatile bool &SCK, volatile bool &CS,
		ap_int<16>  &XIN){
	const int D = 500e3; const int F = 100e6; const int NF = 168e3;
	int DT; volatile bool new_clock = 0; const char n = 16;

	DT = tick_calculator(F, D);
	int NFT = tick_calculator(F, NF);
	ap_int<16> Xidx = 0b0;
	ap_int<16> Xk;
	//printf("%i", (int)TX[14]);
	char M = 20;

	ap_int<16> As[20];
	ap_int<16> Xs[20];// = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	ap_int<16> Y;
	S0:for(int i = 0; i <DT; i++){
		CS = 0;
	}
	S1:for(int i = 0; i <2*NFT; i++){
		CS = 1;
	}
	S2: for(int i = 0; i <2*DT; i++){
		CS = 0;
	}
	S3: for(int i = n-1; i >= 0; i--){
		TICKS: for(int j = 0; j<NFT; j++){
			if(j == NFT/2){
				new_clock=!new_clock;
				SCK = new_clock;
				*MISO = TX[i];
				Xidx[i] = *MISO;
			}
		}
		XIN = Xidx;
		new_clock = !new_clock;
		SCK = new_clock;
//		printf("MISO: %i\n",MISO);
//		for(int i = 0; i < n;i++){
//			printf();
//		}
//		printfA(Xidx, n);
		//printf("%i",(int)Xidx[i]);
		//printf("%i\n",SCK);
	}
	S4: for(int i = 1; i <=M; i++){ // here is where i have trouble. only X[0] is a value different of 0 the rest are 0. 
		if(i == M) Xs[0] = Xidx;
		else	   Xs[i] = Xs[i-1];
	}
	//Y = filtro(As, Xs, M);

	//printf("\n");
//	S4:for(int i = 0; i <DT; i++){
//		CS = 0;
//		//*SCK = 0;
//	}
}

 

 

this is my test bench:

void fir(ap_int<16> TX, bool *MISO, bool *MOSI, volatile bool &SCK, volatile bool &CS,
		ap_int<16>  &XIN);
int main(){
	bool MISO; bool MOSI; bool SCK; bool CS; char M = 20;
	ap_int<16> TX[M], XIN;
	TX[0] = 0b1;
	for(int i = 1; i <M; i++){
		TX[i] = TX[i-1]<<1;
	}
	for(int i = 0; i <M; i++){
		fir(TX[i],&MISO, &MOSI, SCK, CS, XIN);
	}
	return 0;
}

Also, Xidx reset to 0 every time the fir is call 

Captura.JPG

 

 

 

0 Kudos
0 Replies