drbitboy
Lifetime Supporting Member
- On top of that, an RC analog servo typically works with a duty cycle (ON duration) of between 1% and 2%, or maybe up to 2.5%, of the PWM period.
- The 1400 PWMX.DC (Duty Cycle; cf. here) setting has a range of 0 (0% Duty Cycle i.e. always off) to 1000 (100% Duty Cycle i.e. always on).
- So that 1-2% range will mean the CV output to the PWM.DC control parameter will have a usable range of 10-20 out of 1000, or only 11 discrete values.
If we configure the MicroLogix (ML) PWM for 800Hz, there are 800k PWM "k-counts" per second, or 800 k-counts per ms, and the period is 1.25ms.
If the servo PWM frequency is 20Hz, then its period is 50ms, and (full servo range) of 1-2% of that is 0.5-1.0ms, or 400-800 k-counts, and there will be 40 MicroLogix PWM cycles per servo.
If the servo PWM frequency is 50Hz, then its period is 20ms, and 1-2% of that is 0.2-0.4ms, or 160-320 kcounts, and there will be 16 MicroLogix PWM cycles per servo.
The trick would be turning "off" 39 out of 40 (20Hz servo) or 15 out of 16 (50Hz servo) of the ML PWM cycles.
It could be done in hardware (external breadboard) with a counter triggered on the falling edge of the MicroLogix PWM signal.
Or perhaps it could be done in software with a 1ms STI program task that enables the MicroLogix PWM for only one STI cycle out of 50 or out of 20. The questions are whether the ML PWM starts as soon as its enable bit becomes 1, and whether writing a 1 to that bit in software is only an indication of what the ML PWM should do the next time it is scheduled to run and if so how long that schedule is delayed before executing. The nice part about this approach is that this STI task is also a good place to execute a loop update for the PID, which update will then be in synch with the servo PWM signal.
If one of these approaches could be made to work, it might solve the resolution problem, at least to the point where resolution disappears as an issue compared to backlash in the linkage.