Quote:
Originally Posted by sumadin
Interesting. You're suggesting I run another timer at 100hz, and use one to time the calls on PWM() and the other one for timing the calculations, right?
I think I might have a simpler solution. I have the ISR that calls on PWM() to set another flag high (not the interrupt flag), and check that flag in the _Spin() functions. As a result, assuming the calculation runs fast enough, I'll be one cycle behind, which would probably be the case either way. Does that sounds like it could work?
Thanks.
|
My thought was to not even have an ISR and just keep an eye on your 100Hz timer interrupt flag with code located in teleop_spin() and/or autonomous_spin(). Just setup and start a timer, but don't set the interrupt enable bit to one, which will prevent the processor from calling the low priority ISR. Then with code like this in *_spin():
if(INTCONbits.TMR0IF)
{
// Get encoder counts
// Calculate position/velocity
// Do PID calculations
// Update PWM values
//reset interrupt flag
INTCONbits.TMR0IF = 0;
}
...you can implement your 100Hz contol algorithm.
-Kevin