Thread: the main code
View Single Post
  #2   Spotlight this post!  
Unread 10-01-2008, 10:44
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: the main code

The main while(1){} in the default code without any user changes is executed about 830,000 times a second. Once you start adding your own code then it will get slower.[1]

The inner loop via the new spi data check is executed at most ~38 times per second (new data from the operator interface is available every 26.2ms).

The best thing to do would be to read some of the documentation at the ifirobotics site on the structure of the main loop.

And while it is true you can get the red light of death if you make your program execution path too long -- there is an easy way to avoid this ala EasyC/WPILIB. Namely you move the getdata/putdata into an event routine that is run during the system clock interrupt. Then it doesn't matter how long your program execution path is unless you really do something nasty to hang the processor so it won't service interrupts.

[1] the default code path is roughly 12 instruction cycles long but this doesn't account for the background global interrupt routine that is handling the SPI bus transfers of data between the master and user processors, nor the Process_Data_From_Master_uP routine that is executed 38 times per second, so maybe it has an average code path length of 20 instruction cycles in the default code and it only runs 500,000 times per second.