Peter Nachtwey
Member
I see PWM memtioned a lot when it comes to converting an analog output to a digital output. PWM takes timers and is resource hungry. Consider this:
AnalogMax is the maxiumum output plus one in output units which are usually counts. A 12 bit analog card would have a max value of 4096. This can be implented in just one rung on most PLCs and requires only one register for AnalogSum. Why not keep things simple?
Code:
AnalogOut = PID(error) The PID calculates an analog control output value.
AnalogSum = AnalogSum + AnalogOut
if ( AnalogSum >= AnalogMax )
AnalogSum = AnalogSum - AnalogMax
DigitalOut = On
else
DigitalOut = Off
AnalogMax is the maxiumum output plus one in output units which are usually counts. A 12 bit analog card would have a max value of 4096. This can be implented in just one rung on most PLCs and requires only one register for AnalogSum. Why not keep things simple?