drbitboy
Lifetime Supporting Member
Correct scaling factor is 2PI/60 = 0.0147198; SIN SINE COS COSINE MicroLogix 1100
Below are two plots
The ladder code is available here; the sine function subroutine is limited to an input argument range of [0:2PI], but that could be easily expanded; adding a cosine subroutine is also straightforward. The sine function accuracy is around 1E-7, which is good enough for the single-precision IEEE-754 floats used by MicroLogix. The code also uses CTU instructions instead of the RTC seconds field, because the RTC on MicroLogix does not work normally; other than a phase shift, the results will be identical numerically to what is generated by a real RTC.
Below are two plots
- [2PI/59=0.1064947] scaling with glitches,
- [2PI/60=0.0147198] scaling with no glitches.
The ladder code is available here; the sine function subroutine is limited to an input argument range of [0:2PI], but that could be easily expanded; adding a cosine subroutine is also straightforward. The sine function accuracy is around 1E-7, which is good enough for the single-precision IEEE-754 floats used by MicroLogix. The code also uses CTU instructions instead of the RTC seconds field, because the RTC on MicroLogix does not work normally; other than a phase shift, the results will be identical numerically to what is generated by a real RTC.