// Copyright 2012 Accellera Systems Initiative
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0

// Voltage triangle waveform generator 

`include "disciplines.vams"

module V_triangle_generator(out);
    output out;
    voltage out;

    parameter real period = 10n from [0:inf);
    parameter real ampl = 1;

    integer slope;
    real offset;

    analog begin
        @(timer(0,period)) begin
            slope = +1;
            offset = $abstime;
            $discontinuity(1);
        end

        @(timer(period/2,period)) begin
            slope = -1;
            offset = $abstime;
            $discontinuity(1);
        end

        V(out) <+ ampl * slope * (4*($abstime-offset)/period - 1);
    end

endmodule

