In order to get more precision for the control of hydraulic valves, I implemented a 10 bit PWM on the arduino for Cytron. This basically gives 1024 steps for the PWM duty cycle instead of only 256, i.e. the gain resolution is four times higher.

The .ino works directly with the v2 PCB, you only need to switch Cytron to take the PWM from “PWM2” which is hooked to pin D9. Also no modifications needed in AOG side, the min/max PWM values are simply multiplied by a factor of four in the arduino to match the 1024 steps. Gain values are four times higher, i.e. replace 4 with 16 etc. Added a third option to the main ino, it’s also possible to adjust the frequency in the related if clause, default is 125 Hz now.

Hi @nut,
It may be a silly question, but is there an advantage to multiplying the PWM resolution by 4 if at the same time the value you use in the .ino is always a multiple of 4 ? To me, it looks like there should be physically no increase in resolution at the input of the Cytron. Did you actually see an improvement with your multimeter when using AOG ?

Only the limits are multiplied in the ino to keep compatibility with AOG. The PWM is working with a value of 0-1023, so you need to use 4 times higher gain to have the same gain as with 0-255 value.

So if you had gain of four, you get from 1 degree error gain*error = 4 → 4/256 PWM duty cycle. Now, with 10-bit you set 16 so you get 16/1024 = 4/256 duty cycle. The advantage is that now the next step down is 15 in gain, so you get 15/1024 = 3.75/256 PWM duty cycle. With 8 bit resolution, the next option down is 3, so 3/265.