For the past couple of years the logic in my 26.2 ms loop area has looked like this:
set all pwms to neutral and set all relays (fwd and rev) to 0
execute logic that sets pwms and relays
By setting all pwms and relays to neutral, I know that nothing will move if I don’t set it and outputs from the previous pass won’t interfere with the current pass. Also, if I need to put relay1 forward, all I have to do is write relay1_fwd = 1 and not worry about relay1_rev because I know it is set to zero at the beginning.
This year I realized that PutData handles the pwms(and a few other things) but not the relays. In fact, I have no idea how or how quickly the master processor sets the relays after it is set in code. This makes me think that my habit of resetting all relays at the start of each loop may not be such a good idea if enough time elapses between the time I set the relays to off at the start and I set the relays to what I want them to be to adversely effect the robot.
I’ve had no problems doing this so far but, in order to sleep soundly, I need to know how quickly the master processor processes what I set the relays to and if I will ever get burned by zeroing the relays before each pass.
The master processor has no control at all over the relays. If you’ll look in ifi_aliases.h, you’ll see that the relays are all aliased off pins on the user processor. So the relays get updated literally the instant* you set them to something in your code. So if relay1_fwd is 1 before your loop, and you set it to 0, and then set it back to 1 again, you’ll actually be getting a veeeery short pulse from 0 to 1 on the output pin. This is almost certainly negligible and won’t affect anything, but it will be there. Plus you’re wasting valuable processor cycles clearing variables. Why, back in my day our user processor was a monkey with a calculator and…
*actually an instant plus a few nanoseconds of propagation delay.
In that case, it might be possible to create a “poor man’s speed controller” by using a high resolution timer to set or zero relays based on how fast you want the motor to run. Could be useful if you have too many servos taking up PWM outputs.
You’d have a fun time wiring it. The red and white pins are both signal on the relay ports, so you’d have to make sure you’re pulsing the right one. You’d never use them as servo outputs because the red wire is signal, so you wouldn’t get the 7.2V to power the servo. And to top it off, you’d have the same interrupt problem that the Generate_PWMs() has for PWM13-16. But yes, it could be done in theory.