Timers

Is there anyway to hook into the high priority interrupts? maybe steal back whatever timer you’re using and run a whole mess of servos off of the a/d ports – oops, found the bit about getting timer0 back in the readme, but am not sure what functionality i lose. presumably all of the motors.

**The SPI interrupt is the only High priority interrupt and all the other interrupts are defined as Low priority. These settings can not be changed. When the Timer 0 flag is set, it tells you that the SPI data transfer between the Master and the User processors is about to take place.

Use the vex_library for Timer 0 to work this way. Use the alltimers_library to have access to all Timers. The only functionality you lose by doing this is that the User processor (your code) simply will not know when the SPI data transfer is about to take place. **

Seems like if I could sync up timer0 to statusflag.NEW_SPI_DATA there must be a 6 to 12 ms window during which the master controller is decoding the ppm from the r/c when i could snag 2 ms to generate my own pwm without worrying about interruptions from the spi. might this be feasible?

Timer0 is to be used for those needing to know when the Master will interrupt the Slave. The timer gets reset at the end of the SPI transfer. INTCONbits.TMR0IF will be set after 14ms. High priority interrupts will not occur during the 14ms period. One could look at TMR0H and TMR0L (considering it gets preloaded to 0x7747 and the control register uses a divide by 4 prescale value) to determine if there is time before the SPI transfer takes place. The best way to synchronize with timer0 is to wait for the first time INTCONbits.TMR0IF gets set then synchronize when the flag is zero.

I am assuming that since you are using timer0 only to sync pwm generation to avoid conflicts with SPI interrupts, that you are using timing loops to generate the pwm outputs. Does this mean that for 1-2ms out of every 18 the controller is busy doing nothing but counting cycles and switching motor outputs? I would like to attempt to put together a self-balancing robot. It seems to me that I might not be able to do this if I can’t sample the sensors while waiting for pwm generation. I’ll probably need to run hardware pwm at a much higher frequency than 50Hz through an h-bridge and either get a couple of gear motors or gut a couple of yours. Are your motors not essentially hobby servos with the stops removed and the positioning feedback disconnected? If I wanted a plain vanilla gear motor that would mount to the kit, could I buy a spare and remove whatever electronics might be inside? Maybe tuck a little board with an l293d or similar into it?

**All PWMs get generated in one call to generate_pwms which takes 2ms. This is done every 18ms. If you can handle a 55Hz rate then allow the master to generate them for you and you will have plenty of time to sample sensors. A fellow from Deka has already built a balancing robot using the Vex controller so we know that it is possible.

As for the motors, they are basically a servo motor that has been modified. They work from a standard R/C PWM signal. That signal is decoded by a micro-controller. You must be able to decode that same signal and then control the motor.**