View Single Post
  #17   Spotlight this post!  
Unread 28-03-2006, 15:12
Mike Bortfeldt Mike Bortfeldt is offline
Registered User
FRC #1126 (& 1511)
Team Role: Mentor
 
Join Date: Oct 2004
Rookie Year: 2004
Location: Rochester, NY
Posts: 119
Mike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud ofMike Bortfeldt has much to be proud of
Re: ADC code effecting motor outs???

Gary,

Actually I wrote the code that way more for efficiency and to keep the footprint as small as possible. The first line, as Joel says, performs a multiplication that when used with the timer and CCP module determines the duration of the pulse. It is written in that particular manner to ensure that the compiler uses the 8x8 hardware multiplier (chapter 9 of the PIC18F8722 data sheet) rather than one of the math library routines to perform the operation. The result of the 8 bit multiply is automatically placed in the PROD register pair (this is a 1 instruction clock cycle operation). While I could have assigned a variable to receive the result of this multiplication (and cast the variables as ints), it was an unnecessary step as the next line can just as easily use the result from the PROD registers (10,000 = 1 millisecond). If you want, you can look in the generated .lst file to see how these statements are converted into assembly code. The relevant operation is the MULWF instruction and additional information on that can be found in chapter 26 (Instruction Set Summary) of the data sheet. (If you have some free time, take a look at what the C18 "WREG tracking" optimization does to the assembly code and how that would change the pulse width slightly)

Mike