// ELN - Diode
// (c) Wolfgang Scherr
// w.scherr <at> cuas.at

#include "diode.h"

diode::diode( sc_core::sc_module_name mn, const params& par ) :
	anode("anode"),
	cathode("cathode"),
    E1("E1")
{
	// this is our PWL diode model...
	//
	//                               Vfwd+1
	//                                    |
	//                               Vfwd    __ 1.0/Rs_on
	//  Vref-1                          | /
	//  |                                /
	//     ,----------------------------´    -- Vref/Rs_off  and Vfwd/Rs_off
	//    /
	//   / |                                 __ -1.0/Rs_on
	//     Vref
    E1.np(anode);
    E1.nn(cathode);
    E1.ncp(anode);
    E1.ncn(cathode);
    E1.value = 1.0;
    E1.pwl_value = {{p.Vrev-1.0,-1.0/p.Rs_on+p.Vrev/p.Rs_off},{p.Vrev,p.Vrev/p.Rs_off},{0.0,0.0},{p.Vfwd,p.Vfwd/p.Rs_off},{p.Vfwd+1.0,1.0/p.Rs_on+p.Vfwd/p.Rs_off}};
}
