It is very difficult to reproduce a comparator in programming. Computers live in an ideal world while true comparators live in a physical world. You should allow an error when comparing two voltages. A reasonable algorithm to reproduce the behavior of an ideal op-amp being used as a comparator should be something like:I am taking in 2 varying voltages from 2 separate voltage divider and input into 2 separate AD channel of the uC. In order for it to function like a comparator.
Roughly how should the algorithm be like.
Tks
double Comparator (double v_plus, double v_minus, double v_prail, double v_nrail)
{
constant GAIN = 10000;
double v_out;
v_out = GAIN * (v_plus - v_minus);
return v_out < v_nrail ? v_nrail : vout > v_prail : v_prail : v_out;
}
It is very difficult to reproduce a comparator in programming. Computers live in an ideal world while true comparators live in a physical world. You should allow an error when comparing two voltages. A reasonable algorithm to reproduce the behavior of an ideal op-amp being used as a comparator should be something like:
Being:Rich (BB code):double Comparator (double v_plus, double v_minus, double v_prail, double v_nrail) { constant GAIN = 10000; double v_out; v_out = GAIN * (v_plus - v_minus); return v_out < v_nrail ? v_nrail : vout > v_prail : v_prail : v_out; }
v_prail - Positive rail voltage;
v_nrail - Negative rail voltage;
v_plus - Plus input voltage;
v_minus - Minus input voltage;
v_out - Output voltage.
I am confused - why should the uC function as an op amp? By the way, which uC?