Capsim Block Documentation
This star simulates a sample and hold circuit.
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | x | |
| 1 | float | clock |
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | y |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | int | holdTime | 1 |
| Num | Type | Name | Initial Value | Description |
|---|---|---|---|---|
| 0 | float | hold_sample | ||
| 1 | int | count |
int this_clock,last_clock,get_sample; int no_samples; |
|---|
hold_sample = 0.0; count = 0; |
|---|
/* 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)
{
if (clock(0) > 0.5)
last_clock = 1;
else
last_clock = 0;
IT_IN(0);
IT_IN(1);
if (clock(0) > 0.5)
this_clock = 1;
else
this_clock = 0;
get_sample = 0;
if (this_clock && !last_clock)
get_sample = 1;
if (get_sample)
{
hold_sample = x(0);
count = 0;
}
if(IT_OUT(0)) {
KrnOverflow("hold",0);
return(99);
}
if (count < holdTime)
y(0) = hold_sample;
else
y(0) = 0.0;
count++;
}
return(0);
|
|---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
Copyright (C) 1989-2002 XCAD 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://capsimtmk.sourceforge.net
XCAD Corporation
Raleigh, North Carolina */
|
|---|
/* hold.s */ /************************************************************** hold.s **************************************************************** Inputs: x, the data stream Outputs: y, the chosen samples of x Parameters: Number of samples to hold **************************************************************** This star simulates a sample and hold circuit. The lone parameter specifies the number of samples to hold the value. Triggering is on the positive edge of the clock. |
|---|