sampler1

Capsim Block Documentation

Short Description

This star simulates a sampler circuit. Triggering is on the positive edge of the clock.

Top
Input Connections
Port Type Name
0 float x
1 float clock
Top
Parameters
Num Description Type Name Default Value
0 Enter phase recording file, none if no recording file phfile_name phfile
1 Enter frame number int frame 8
Top
States
Num Type Name Initial Value Description
0 FILE* fp
1 int count
2 int done
3 int inbufs
4 int outbufs
5 int stdflag 0
Top

Declarations


 

	int phase;
	int no_samples;



Top

Initialization Code



 

        if((inbufs = NO_INPUT_BUFFERS()) != 2
             || (outbufs = NO_OUTPUT_BUFFERS()) != 1) {
          fprintf(stderr,"sampler: i/o buffers connect problem\n");
          return(1);
  	}
        if(frame < 1) {
                fprintf(stderr,"sampler: improper frame number\n");
                return(2);
        }
        if(strncmp(phfile_name,"std",3) == 0) {
                fp = stdout;
                stdflag = 1;
        }
        else if(strncmp(phfile_name,"none",4) == 0) {
                stdflag = -1;
        }
        else if( (fp = fopen(phfile_name, "w")) == NULL ) {
                fprintf(stderr,"sampler: can't open output file\n");
                return(3);
        }




Top

Main Code



 

 
	/* note the minimum number of samples on the input 	*/
	/* buffers and iterate that many times 			*/
	
	for(no_samples=MIN_AVAIL(); no_samples >0; --no_samples) 
	{
		IT_IN(0);	
		IT_IN(1);	
 		
		phase = count % frame;

		if (phase == 0) {
		   done = 0;
		}
		if ((done == 0) && (clock(0) > 0.5)) {
		   done = 1;
		   if(IT_OUT(0)) {
			KrnOverflow("sampler1",0);
			return(99);
		   }
		   OUTF(0,0) = x(0);
		   if (stdflag >= 0) fprintf(fp,"%d\n",phase);
		}
		if ((done == 0) && (phase == (frame - 1))) {
		   if(IT_OUT(0)) {
			KrnOverflow("sampler1",0);
			return(99);
		   }
		   OUTF(0,0) = x(0);
		   if (stdflag >= 0) fprintf(fp,"%d\n",phase);
		}
		count = phase + 1;
	}
	return(0);




Top

Wrapup Code



 

        if(!stdflag && stdflag > 0) fclose(fp);




Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* sampler1.s */
/**************************************************************
			sampler1.s 
****************************************************************
	Inputs:	x, the data stream
		clock, the triggering clock
	Output: y, the sampled version of x
****************************************************************
This star simulates a sampler circuit. 
Triggering is on the positive edge of the clock. 

sampler1


This star simulates a sampler circuit. 
Triggering is on the positive edge of the clock. 
	Inputs:	x, the data stream
		clock, the triggering clock
	Output: y, the sampled version of x


Programmer: Jaejin Lee	
Date:       1/18/1990
Modified:   3/1/1990, add phase recording file

*/