Do you use on-chip peripherals?

The Question is… Do you use any on-chip peripherals? Which ones? None? Interrupts? Do you understand em? How do you implement them? Experiences? Thoughts?

Choices: UART(serial), (E)CCPs, ADCs, External Interrupts(PORTB), Timers, None, Other

1024 uses every one in the book… and hasnt been disappointed.


So far, we’ve only used the Timers and External Interrupts on the actual robot. We plan to use all of the first five on the next one, though.

We are gradually getting more sophisticated.

Serial Ports: We have always used the serial ports indirectly (through Kevin’s code and the Camera code). No custom modification.

Timers: We have always used the timers to give us a higher resolution clock and provide activity scheduling.

Interrupts: We have always used interrupts 1,2 for drive odometry. We have on occasion used the other 4 interrupts for various purposes.

eeprom: This year we are using the eeprom to store arm position values. This is our first year using the eeprom.

ADC: In previous years, we have made better use of the ADC via Kevin’s code. We used it to experiment with the gyro among other things.

IIc: we investigated this to prove that it couldn’t possibly by used due to the RC architecture. This year we simulated it using digital I/O.

ccps: - we looked at using them last year to help in determining rotation direction (for the gear tooth sensor on the drive motor), and for determining rotation speed of our ball shooter’s impeller wheels. Ultimately we did not use them (didn’t care about direction, used a custom circuit to determine shooter speed)

What other on-chip periperal do you use?

Just the ones listed above…

We used an interesting combination of hardware this year on our traction motors… used TMR3 to feed CCP1,2, and 3. CCP1 provided a 100Hz cycle to clock our PWM/PID for the traction motor victors. In this 100Hz routine we sample both the analog encoders and do a state decode on them to figure which way they are going, and handle 5 to 0 and 0 to 5 volt transitions, as well as handling the PID… worked out great, got the timebase as well as the duty cycle time for both victors out of just TMR3… which we never stop, set, or in any way touch… it just freeruns… now THAT gets my blood going! :yikes:


Our software is much more sophisticated this year; last year we had a loop-based dead reckoning auton mode. This year, I have serial and eeprom as the main attractions to my code. We are using encoders, so I guess that would fall under interrupts.

Sorry if I’m a little short on details…I wouldn’t want to give it all away! :wink:


This year, we’re light on sensors. Only 2 pots, a limit switch, 2 banners, and the camera.

I would, however, like to add a real-time clock to the mix, at least for autonomous. A handy thing to have.

Thanks to the help from Qbranch I was able to get a hardware timer working to make our arm move for a specific time. I was also using gear tooth sensors (2 interrupts) for use on our transmissions but later figured out I didn’t need them.

Has anyone made a list of what peripherals are available on the RC?

A list of all the functions summarized from the PIC data sheet would be an amazing asset to have, especially to newer programmers.

We used eeprom and serial port to tune our arm PID.

Due to popular demand… I made up this list of all the on chip peripherals available for use as the chip is implemented in the '07 rc, and listed the page numbers where you can find info in the User’s Manual available here:

> 2 UARTS - Hardware Serial Ports - One is brought out to the Program port, the other is connected to the TTL port. (page 249)

> 2 CCPs and 3 ECCPs - (Enhanced)Capture/Compare/PWM modules - Four of the CCPs are brought out to pwms 13-16. Because of this, the ‘Capture’ mode for the (e)ccps cannot be used since the procesor’s pins sit behind a signal driver on the PWM pins. Programmers can still use these pins for output and generate their own pwm signals, either using the hardware setup for pwm (the rate is too high to drive a victor, so be careful) or can be used in conjunction with another CCP serving as a timebase to generate a razor-sharp high accuracy SIXTEEN BIT pwm signal… being sixteen times the resolution of a standard pwm. The ‘Compare’ mode of the PWM serves as a kind of hardware equality test for a timer, interrupting on a given value for a timer. Keep in mind TMR3CON holds the bits that direct which CCPs can view which timer’s values, also remember that the best way to use a ccp is to never reset, stop, or set the timer’s value, just let it freerun. If you want to know more on that, ask me, or read up on unsigned binary addition and subtraction. (page 181 for CCPs, page 189 for ECCPs)

> 2 I2C(inter integrated circuit)/SPI(serial peripheral interface) - Already implemented as a communication bus between the user and master processors. (page 207)

> 1 ADC with a 16 line multiplexer - 1 Analog to Digital converter that can read voltages, a driver is provided by IFI so you don’t have to handle the actual hardware. The processor has an internal input mux that allows the single ADC module to read any one of 16 inputs, one at a time. These are often used with a Potentiometer to read in position feedback data or other data input. (page 273)

> PORTB special features

  • 4 Unique external interrupts with programmable edge trigger direction - the first four pins on port b (the last two of which (RB2 and RB3) are avalable as Digital I/O 1 and 2) which have an individual interrupt flag for each pin and can be programmed to edge trigger on a low-to-high or high-to-low transition. very useful with encoders, ultrasonic sensors, any one of a plethora of sensing situations. especially useful for pulse timing when an input capture is not available. (pages 140, 123-125)
    • 4 Grouped external interrupt on change pins - the last four pins of PORTB (RB4,5,6,7 or Digital I/O 3,4,5,6) have one interrupt flag if any number of the pins have a high to low OR low to high transition… it is not programmable. also, once in the interrupt, you’ll have to figure out which pin changed programmatically since theres only one flag for all four pins if your using more than one. If you use these external interrupts, above all, remember this: if you don’t read portb, you’ll be in whats called a “Mismatch Condition” in the silicon of the chip, causing the port to continually interrupt over and over and over. To solve this, just make sure you read or write portb in your interrupt service routine. (pages 140, 123-125)

> 2 Analog Comparators - Used for seeing which of two voltages is greater without actually getting the values of them, a much faster process than full analog to digital conversion. (page 283)

> 2 8bit and 3 16bit Timers - These all have varying characteristics, but for the most part, they incorporate a prescaler which divides down off of a 10MHz clock for the rate at which the timer’s 8 or 16 bit counter increments. The 16 bit timers have the neat option of doing a 16 bit read… when one reads the low byte of the timer (TMRxL) the high byte is instantly copied, in hardware, to a register which is then read as the high byte of the timer (TMRxH). TMR3CON, the control register for timer three, has the extra responsibility for directing the data from the timers to CCP modules, the programmer can change where they go to. Remember, timer 0 is the most flexible timer available since it is the original. (pages 163-180)

> 1024bytes of EEPROM - Electrically Eraseable/Programmable Memory - A few control registers control reading and writing to this static memory which doesnt erase when the processor is shut off, good for storing data from during a match or keeping configuration values, autonomous programs, etc. Remember: this memory is slow. (page 113)

> 8x8 Hardware Multiply - This allows a byte to be multiplied by another in hardware, a function controlled by the compiler but if an extreme speed multiply is needed using this in assembly results in a single-cycle multiply. A VERY nifty feature. (page 119)

> General I/O notes - The chip has 70 I/O pins that can be configured individually as an Input (1) or Output (0) by setting their Tristate (TRISx) value. The IFI board on which the processor is installed pulls up all the Digital I/O lines so they float at about 3v, and have a normal state of 1, so watch that in your logic, remember when a signal line is connected to ground it is zero, when it isnt its one. When configured as an output, each individual pin can drive 25mA… a defining feature of microchip microprocessors.

Again, here’s the link to the user’s manual for the chip.

Well I think that about sums up what i have in my head. If you need any additional help just give me a yell on this thread or otherwise, a positive rep never hurts if you found this useful, and I’ll see you all in atlanta… just give me a yell there and ask anyone on 1024 for “Q”, they’ll point you in the right direction.