Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microcontrollers, Basics Tips and Tricks with PIC MCUs

Similar presentations


Presentation on theme: "Microcontrollers, Basics Tips and Tricks with PIC MCUs"— Presentation transcript:

1 Microcontrollers, Basics Tips and Tricks with PIC MCUs
20 January 2012 Jonathan A. Titus

2 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...

3 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.

4 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?

5 Several Keys at One Input I
Microchip AN512, Implementing Ohmmeter/Temperature Sensor.

6 Several Keys at One Input II

7 Expanded LED Driving Charlieplexing:

8 Resistive-Sensor Interface

9 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 }

10 Use Internal Pull-Up Resistors

11 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.

12 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."

13 Comparator Detects Low Battery

14 Debounce a Switch Interrupt I
Not Good: Switch bounce could cause a second interrupt.

15 Debounce a Switch Interrupt II
Better: Clear flag after switch bounce ends.

16 Filter PWM Output to Get a Voltage

17 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.

18 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: 6B.pdf.

19 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.


Download ppt "Microcontrollers, Basics Tips and Tricks with PIC MCUs"

Similar presentations


Ads by Google