Microcontrollers, Basics Tips and Tricks with PIC MCUs 20 January 2012 Jonathan A. Titus
General Tips & Tricks I Keep your lab notebook up to date so you know what worked and what didn’t. Always insert your name, time, date, version in your code listings. In large projects, use version-control programs. Do not obfuscate code; keep it clear and readable. Adopt a coding style and use it. Use comments liberally--they take NO code space. If you run into problems, before you do anything else...
General Tips & Tricks II 3 General Tips & Tricks II Check your power supply. Put a ‘scope on the output. Does the supply voltage match the MCU specs? Is the supply current-limit improperly set? Do you have a short circuit? Have you connected the power supply? Don’t use built-in meters, use a calibrated DVM.
General Tips & Tricks III Check jumpers and connectors. Do all boards have a common ground? Do all boards have power? Have you used the latest version of the code and the software tools? Run a simple test program to ensure communication through the debug pod or dev-kit board. Have you selected the proper MCU for the IDE software? Is there a power conflict between your power supply and the debug pod?
Several Keys at One Input I Microchip AN512, Implementing Ohmmeter/Temperature Sensor.
Several Keys at One Input II
Expanded LED Driving Charlieplexing: http://en.wikipedia.org/wiki/Charlieplexing
Resistive-Sensor Interface
Don’t Waste Power in Loops Replace loops that wait for a flag with code that puts the CPU in a low-power mode, then awaken CPU when an event occurs. Don’t do this: while(!ADCInterruptFlag); Do this: while(!ADCInterruptFlag) { Idle(); //wake on ADC interrupt }
Use Internal Pull-Up Resistors
LEDs 1. Use a PWM output to drive an LED and vary brightness. 11 LEDs 1. Use a PWM output to drive an LED and vary brightness. 2. Use a high-brightness LED at low power--you’ll still get good brightness at lower power. 3. If you have an LED to use for diagnostics, connect to an I/O pin with a jumper to free the pin for other uses.
Terminate or Set I/O Pins 1. To reduce power, leave unused I/O pins unconnected, but drive them to a logic 1 or 0. 2. If you have an unused input, connect it to either V+ or ground through a 10K resistor. You lower power use, but add a component. For more power-saving tips, read: Microchip Application Note AN1416, "Low-Power Design Guide."
Comparator Detects Low Battery
Debounce a Switch Interrupt I Not Good: Switch bounce could cause a second interrupt.
Debounce a Switch Interrupt II Better: Clear flag after switch bounce ends.
Filter PWM Output to Get a Voltage
Miscellaneous Tips I Use an internal R-C clock instead of external R-C components. Depends on frequency accuracy you need. Use different clock sources to reduce power. Operate at low clock frequencies Switch to higher-frequency clocks for critical tasks Turn off unused peripherals, if possible. Disable watch-dog timer, if not needed. Look for fast wake-up times, which minimize power use. Include an LED for each power source.
Miscellaneous Tips II Check MCU vendor Web sites and forums for more tips and tricks. Find additional tips, tricks, and sample code on independent sites and discussion groups. For more "Tips and Tricks," visit: http://ww1.microchip.com/downloads/en/DeviceDoc/0114 6B.pdf.
Purchase from Reputable Vendors Ebay looks like it has some “bargains” in development hardware, but don’t trust your career to unknown suppliers. Problems with Chinese AVR JTAG-ICE “knock offs.” Software might not update cloned hardware. Difficult to spot cloned equipment.