interrupts and putdata()

for our autonomous program, we are planning on using interrupts to control the motor speeds at specific intervals… i was just wondering if it was safe to call Putdata() more often than we call Getdata(). for example, if in the interrupt handler which executes say every 30-40 ms, we would modify the value of the pwms from a lookup table we have, and then we call putdata() to put those values on the actual pwms… is this going to cause problems anywhere? or can the pwm outputs only be changed every 26.2 ms no matter what?

From my testing, it looks like the only thing that causes the processor to choke is if you don’t call PutData often enough. You can call GetData whenever you want, and you can call PutData as often as you want as long as it’s more often than the cutoff time (not sure what that is).

I’m not sure if the master updates the pwms every time PutData is called, or just every 26.2 ms.

I just finished testing exactly this code on the EDU controller. It works fine as long as there are no conflicts with the values that your fast and slow code sections output. I wrote the code for the fast section, and forgot that the slow section would output 127 every 26 msec :slight_smile: The edu motor sounded really weird as a result. As soon as I figured this out though everything worked.

I am not sure if updating the values that quickly will actually do any good, however. Even if the speed controller can respond this quickly to the change in PWM, the motors and the drivetrain certainly won’t. Inertia in the drivetrain will erase all difference between fast and slow updates, I think. If I’m wrong please correct me on this.

It’s fine to call putdata more often than needed, but it would probably be a bad idea to call putdata from an interrupt handler because of timing issues. The interrupt pin would be disabled for as long as putdata would take to execute. I’d just set your PWM values and call putdata as you normally do.

You may want to just use the Generate PWM function which will update PWMs 13,14,15,16 without needing to call putdata.