MSP430 xbox controller mod

You can use a 32KHz crystal instead of the clock to get a more accurate timing. The CPU is affected more by temperature. Since you're using it indoors, this probably isn't a big issue.

I skipped the external clock source due to space. The internal oscillator has been sufficient. (I've played halo and l4d locally with good results. Don't have any other FPSes)

As for improvements, without spending more time understanding everything... in GPIO.C, avoid checking else if conditions if you can safely assuming it is a binary case. This will save a few cycles and probably more importantly ROM space.

This is excellent advice. I'll make those adjustments.

In PWM.c, you use division. Not that there is anything inherently wrong with division, just keep in mind the MSP430 lacks hardware for it, and has to emulate it. You can sometimes get the same code clarity by using #defines and having the preprocessor do the work for you. Or you can use look up tables if the range is short.

I removed division in main.c in favor of bit shift. I didn't do the same in PWM because I wasn't sure how to achieve it without division. A lookup table may be the way. Or PWMStart() could just get the raw value for CCR0 and I can always set it in a define.

You have some __delay_cycles() in your interrupt. Now if you only have a single source of interrupt this is fine, but if you needed to handle multiple interrupts I wouldn't advise doing that. But avoiding that issue adds a whole extra level of complexity.

I understand that hanging in an interrupt isn't the best, but I couldn't think of any cases where I'd need to get out of an interrupt during an interrupt. Also, unless I'm very mistaken, it seems like the peripherals keep running during delay cycles. So I wasn't too bothered about it. Is there any other reason to avoid using __delay_cycles()? Is there a better choice for software debouncing?

I don't really understand the need for separate tens and ones.

Imagine you want speed 99. Either pull the trigger 99 times, or 18 times. 9 for tens 9 for ones.

/r/MSP430 Thread