"Vectorizing" a custom skill function

Discussion in 'Cadence' started by Stephen Greenwood, Jan 18, 2011.

  1. I'm writing a SKILL function to count the number of crossings in a
    waveform object. After some poking around in the SKILL ADE Reference,
    I managed to write the following:

    procedure( crossCount( inWave crosspt edgeType )
    crossWave = cross(inWave crosspt 0 edgeType t "time")
    numberOfCrossings = drVectorLength(drGetWaveformYVec(crossWave))
    )

    where the arguments are as follows:

    inWave (waveform)
    crosspt (float)
    edgeType (string ["rising" | "falling" | "either"] )

    The idea is to use the cross function to capture all crossings of a
    user-defined threshold "crosspt", then get the length of one of the
    vectors returned from that cross() function. (In this case I chose the
    YVec.) So numberOfCrossings returns an integer, and it works fine when
    "inWave" is a single waveform.

    However, when "inWave" is a family of waveforms, the function does not
    do what I want it to. It returns a single integer, whereas I want it
    to return a vector of integers. Can anyone suggest a way to accomplish
    this? I'm not so concerned about the type of the data returned
    (integer or float), as long as I can get the information somehow.

    Thanks for any help you can provide,
    Stephen Greenwood
     
    Stephen Greenwood, Jan 18, 2011
    #1
  2. Bump.

    Anyone? Thank you.
     
    Stephen Greenwood, Jan 26, 2011
    #2
  3. Stephen Greenwood wrote, on 01/26/11 18:12:
    Stephen,

    The way this is normally done is something like this (i.e. have a cond which
    checks the type, and then use famMap if it's a family):

    procedure(ABEyeHisto(waveform start stop period threshold bins @optional
    (edgeType "either"))
    cond(
    ;---------------------------------------------------------------------
    ; Handle ordinary waveform
    ;---------------------------------------------------------------------
    (drIsWaveform(waveform)
    let((xVec len clipped crosses cycleNum edgePos binArray binWidth bin
    outXVec outYVec)
    xVec=drGetWaveformXVec(waveform)
    len=drVectorLength(xVec)
    binArray=makeVector(bins+1 0)
    binWidth=period/bins
    ;---------------------------------------------------------------
    ; if no start given (start less or equal to 0), use first time point
    ;---------------------------------------------------------------
    when(start<=0
    start=drGetElem(xVec 0))
    ;---------------------------------------------------------------
    ; if no stop given (stop less or equal to 0), use last time point
    ;---------------------------------------------------------------
    when(stop<=0
    stop=drGetElem(xVec len-1))
    ;---------------------------------------------------------------
    ; cast everything to floats, just to make sure
    ;---------------------------------------------------------------
    start=float(start)
    stop=float(stop)
    period=float(period)
    ;---------------------------------------------------------------
    ; clip the waveform
    ;---------------------------------------------------------------
    clipped=clip(waveform start stop)
    ;---------------------------------------------------------------
    ; And find the crossing points, and then bin them
    ;---------------------------------------------------------------
    crosses=cross(clipped threshold 0 edgeType)
    foreach(cross crosses
    cross=cross-start
    cycleNum=floor(cross/period)
    edgePos=cross-cycleNum*period
    bin=floor(edgePos/binWidth)
    binArray[bin]=binArray[bin]+1
    )
    ;---------------------------------------------------------------
    ; Build the waveform
    ;---------------------------------------------------------------
    outXVec=drCreateVec('double bins)
    outYVec=drCreateVec('intlong bins)
    for(binNum 0 bins-1
    drSetElem(outXVec binNum binWidth*(binNum+0.5))
    drSetElem(outYVec binNum binArray[binNum])
    )
    drCreateWaveform(outXVec outYVec)
    ))
    ;---------------------------------------------------------------------
    ; Handle family
    ;---------------------------------------------------------------------
    (famIsFamily(waveform)
    famMap('ABEyeHisto waveform start stop period threshold bins edgeType)
    ) ; family
    (t
    error("ABEyeHisto - can't handle %L\n" waveform)
    )
    ) ; cond
    ) ; procedure

    Regards,

    Andrew.
     
    Andrew Beckett, Feb 22, 2011
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.