import Comparator, Resistor, ElectricPower, Electrical

comparator = new Comparator
comparator.common_mode_rejection_ratio = 80dB +/- 10%
comparator.input_bias_current = 1nA +/- 50%
comparator.input_hysteresis_voltage = 5mV +/- 20%
comparator.input_offset_voltage = 1mV +/- 30%
comparator.propagation_delay = 100ns +/- 20%
comparator.output_type = Comparator.OutputType.PushPull
comparator.package = "SOIC-8"

# Power supply connections (dual supply)
power_pos = new ElectricPower
power_neg = new ElectricPower
assert power_pos.voltage within 5V +/- 5%
assert power_neg.voltage within -5V +/- 5%
comparator.power.hv ~ power_pos.hv
comparator.power.lv ~ power_neg.lv

# Create voltage reference with resistor divider
ref_resistor_high = new Resistor
ref_resistor_low = new Resistor
ref_resistor_high.resistance = 10kohm +/- 1%
ref_resistor_low.resistance = 10kohm +/- 1%

# Reference voltage = Vcc/2
power_pos.hv ~> ref_resistor_high ~> comparator.non_inverting_input
comparator.non_inverting_input ~> ref_resistor_low ~> power_neg.lv

# Connect input signal to inverting input
input_signal ~ comparator.inverting_input
output_signal ~ comparator.output

# Output will be HIGH when input_signal > reference_voltage

Parameters

common_mode_rejection_ratio
decibel
input_bias_current
ampere
input_hysteresis_voltage
volt
input_offset_voltage
volt
output_type
dimensionless
propagation_delay
second

Interfaces

inverting_input
Electrical
non_inverting_input
Electrical
output
Electrical
power
ElectricPower

Global Attributes

These attributes are available to all modules and interfaces in a design.
lcsc_id
str
Assign the LCSC ID of the module.If set, this will tell the picker to select that part from LCSC for this block.
manufacturer
str
This module’s manufacturer name, as a string.Only exact matches on the manufacturer’s name will be found by the picker. It’s recommended to fill this information based on what ato create component provides.
mpn
str
This module’s manufacturer part number, as a string.For the picker to select the correct part from the manufacturer, this must be set.
package
str
The package of the module.This drives which components can be selected, and what footprint is used.Must exactly match a known package name.
exclude_from_bom
bool
override_net_name
str
When set on an interface, this will override the net name of the interface.This is useful for renaming nets which are automatically generated.
required
bool
Only for ModuleInterfaces. If set to True, require that interface is connected to something outside of the module it’s defined in.
import Comparator, Resistor, ElectricPower, Electrical

comparator = new Comparator
comparator.common_mode_rejection_ratio = 80dB +/- 10%
comparator.input_bias_current = 1nA +/- 50%
comparator.input_hysteresis_voltage = 5mV +/- 20%
comparator.input_offset_voltage = 1mV +/- 30%
comparator.propagation_delay = 100ns +/- 20%
comparator.output_type = Comparator.OutputType.PushPull
comparator.package = "SOIC-8"

# Power supply connections (dual supply)
power_pos = new ElectricPower
power_neg = new ElectricPower
assert power_pos.voltage within 5V +/- 5%
assert power_neg.voltage within -5V +/- 5%
comparator.power.hv ~ power_pos.hv
comparator.power.lv ~ power_neg.lv

# Create voltage reference with resistor divider
ref_resistor_high = new Resistor
ref_resistor_low = new Resistor
ref_resistor_high.resistance = 10kohm +/- 1%
ref_resistor_low.resistance = 10kohm +/- 1%

# Reference voltage = Vcc/2
power_pos.hv ~> ref_resistor_high ~> comparator.non_inverting_input
comparator.non_inverting_input ~> ref_resistor_low ~> power_neg.lv

# Connect input signal to inverting input
input_signal ~ comparator.inverting_input
output_signal ~ comparator.output

# Output will be HIGH when input_signal > reference_voltage