Friday, February 27, 2009

LED Fan Clock

LED Fan Clock - Uses an LED as a light strobe and the persistence of vision technique to show static coloured hands on a RPM countable computer fan like a clock. http://spritesmods.com/?art=ledfanclock&page=1

Tuesday, February 24, 2009

Interesting Maxim Chips

MAX6952 The MAX6952 is an SPI based 5x7 dot matrix LED display driver that can drive up to 4 monochrome displays or 2 dual-colour displays. MAX232 The MAX232 is a very well known chip that converts TTL USART signals (such as the ones on the PIC) to RS232 level signals (on the PC). DS3234 The DS3234 is a precision real time clock with integrated crystal and 256 bytes of SRAM. MAX5402 The MAX5402 is a 256 step digital potentiometer. Maxim IC gives out free samples. Sign up and order.

Build Your Own Clock

Here's a neat project idea to build your own clock using a PIC microcontroller. Parts:
  • A PIC microcontroller (16F886 seems like a good choice; a 12F683 can also be used).
  • A 32.768 kHz crystal for timing (can be used as the primary clock source as well as timer clock source for the PIC).
  • A display. For this purpose, an LED Matrix display or LED 7 segment display can be used. A very low power static LCD can also be used if low power consumption is part of the design goal.
  • Shift registers can be used to drive the LED displays.
  • Optionally, a system to synchronize to local low-frequency radio time signals can be added.
Other ideas:
  • A light level sensor can be used to automatically adjust LED brightness based on ambient light levels. Should be dim during the night and bright during the day. (Possible use for a photoresistor hooked up to the ADC on the PIC?)
  • Include a user-programmable alarm.
  • Include a calendar.

Monday, February 23, 2009

Oscilloscopes

A short article on oscilloscopes - http://www.best-microcontroller-projects.com/handheld-oscilloscope.html

Make a clock using a 32768 Hz crystal and a low end PIC

32768 Hz crystals are extremely common and are used to make clocks as the number 32768 = 2^15 and can therefore be easily divided to obtain a 1 Hz pulse. Further information is provided on the Wikipedia article on quartz clocks. I believe the crystal can be used with a PIC as a secondary clock source for one of the internal timer modules which can generate an interrupt every so often with an exact frequency and therefore be used as a real time clock. Another cool blog discovered here: http://picnote.blogspot.com/ And some interesting articles:

1Hz Clock Generator using PIC12F675 Clock with 32.768KHz Crystal

Sunday, February 22, 2009

Multivibrator

Wikipedia:
A multivibrator is an electronic circuit used to implement a variety of simple two-state systems such as oscillators, timers and flip-flops. It is characterized by two amplifying devices (transistors, electron tubes or other devices) cross-coupled by resistors and capacitors. The most common form is the astable or oscillating type, which generates a square wave—the high level of harmonics in its output is what gives the multivibrator its common name.
http://en.wikipedia.org/wiki/Multivibrator Can be used to build oscillators, touch switches, flip flops and so on.

Friday, February 20, 2009

Displaying custom 5x8 characters on your HD44780 LCD

Creating and displaying your own custom characters on your HD44780 based LCD is very easy. When you send "data" to the LCD (which represents an ascii character to be displayed), the LCD consults its internal ROM and looks up the pattern corresponding to your character. This internal ROM can not be modified by the user and contains a fixed set of characters that can be displayed. However, the LCD also contains some internal RAM that can be used by the user to define his own set of characters. There is enough character RAM for up to 8 custom characters to be defined.
Step 1: Send the Command
To define your own custom characters, you simply write to the character RAM. To do this, simply send the command (0x40 + address). The address can be anywhere from 0 - 63 as there are 64 bytes available for use. To start out, simply set the address to zero. So, send the instruction (0x40). I have my code set up like this:
send_cmd(0x40 + 0);
Step 2: Send the Data
You are now ready to start sending data to the LCD module to define your own characters. Each of the LCD blocks is composed of 5x8 pixels. Each row of pixels, top to bottom, represents one byte. Since each row only has 5 pixels, only the lower 5 bits of each byte you send will be considered by the LCD module. So, to start defining a character like the one shown here, you will need to now send the following data like this:

send_data(0b00000);
send_data(0b00100);
send_data(0b00010);
send_data(0b11111);
send_data(0b00010);
send_data(0b00100);
send_data(0b00000);
send_data(0b00000);

The character RAM pointer will auto-incriment so you don't have to keep setting the address. Just send the data. The above 8 bytes define the first character. To define another character, just directly send another 8 bytes representing your second character.
Step 3: Use Your Characters

To use your freshly-created custom characters, all you have to do now is set the display address back to a valid position on the LCD screen and send your character. Every character you define has an ascii value of 0 - 7. For example, to display your first character, send the number 0x00 as data. If you have a second, third or fourth (or so on) character defined, send data 0x01, 0x02, 0x03 (and so on). I have my code configured as follows:
set_cursor(2, 1);
send_data(0x00);

This will display our custom character.
Here's a complete program that puts it all into context:
http://pastebin.com/f3fb04ca
The above program utilizes my HD44780 C18 Driver Code.

Thursday, February 19, 2009

Tiny ARM Embedded Linux Computers

http://gumstix.com/index.html - ~$140 Gumstix, inc. makes the world's smallest full function, open source computers. These computers and related products are marketed to companies, product designers and hobbyist in more than forty countries worldwide. http://beagleboard.org/hardware - $149 The USB-powered Beagle Board is a low-cost, fan-less single board computer that unleashes laptop-like performance and expandability without the bulk, expense, or noise of typical desktop machines.

Great Electronics Books

As recommended by the PICLIST members: The Art of Electronics - by Paul Horowitz, Winfield Hill Practical Electronics for Inventors - by Paul Scherz

Wednesday, February 18, 2009

Two more radio transceivers from Futurlec

Radio Data Transceiver - 433MHz - Priced at $7.90 and $8.90. SPI interface - easy interface with microcontrollers. http://www.futurlec.com/Radio.shtml - The 10th and 11th products on that page.

Tuesday, February 17, 2009

Popular Shift Register with Enable Pins

Two cool high-speed shift registers:
  • 74HC595 - 8-Bit Shift Registers with Output Latches - Datasheet at Futurlec - $0.50 each.
  • UCN5832 (a bigger version of the 595)
Thanks Colin! (PICLIST) These chips can also be chained to even further increase output lines: http://homepages.which.net/~paul.hills/Software/ShiftRegister/ShiftRegister.html

Great Electronics Stores to Buy Parts

http://www.futurlec.com/ My all time favorite store to buy electronics parts. Very low priced for small and large quantities, great for hobby use. Really cool value packs, prototyping boards, components and so on. First stop when you need something. No minimum order, low prices, slow shipping. http://www.sparkfun.com/ Second stop. Lots of cool parts, good prices. They also make PCBs at the best hobbyist prices. http://www.allelectronics.com/ Haven't used. http://www.mouser.com/ Haven't used. http://www.jameco.com/ Haven't used. http://digikey.com/ Haven't used. http://www.microchipdirect.com/ First place to go to when PIC microcontrollers are needed. They also allow samples to be taken every month for only $7.50.

Sunday, February 15, 2009

Turbocharge Your PIC with PLL

The PIC18 series have a maximum internal oscillator frequency of 8 MHz, which translates to 2 MIPS. However, the PIC can run at much higher speeds (especially when using an external clock source). Using the PIC's PLL, one is able to multiply the clock source by up to 4 times. This is even software-controllable if using the internal clock source. Using the maximum speed of the internal oscillator, the PIC can run at up to 32 MHZ with PLL enabled. This yields blazing fast performance of 8 MIPS. Best of all, you can turn this feature on or off as you please to control power consumption. Using the PLL is very easy.

We must first ensure that we are using the internal oscillator. So, in C18, declare a configuration option like this:

#pragma config OSC = INTIO67

Next, we must either configure the internal oscillator to run at 4 or 8 MHz. The PLL will not be enabled on any other configuration. Since we're opting for speed here, let's set it at 8 MHz. Put the following as the first line in your main() function:

OSCCON = 0b01110000;

Note that the last two bits of OSCCON must be 00. And finally, to enable the PLL, add the next line right after:

OSCTUNE = 0b01011111;

This enables the PLL and runs the PIC at the maximum possible frequency using only the internal oscillator - 8 MIPS @ 32 MHz. To toggle the PLL on or off, simply set OSCTUNEbits.PLLEN to either 1 or 0, respectively. Refer to the datasheet for information on how to fine-tune the PLL.

Friday, February 13, 2009

PICFLOAT

Midrange PIC floating point library written in MPASM. IEEE 32bit single and 40bit format (8bit signed exponent,32bit mantissa, 1bit sign - calculations are done in 40bit format including trig, log, etc). http://picfloat.sourceforge.net/ Would be nice to have a 64 bit float in C with high precision math functions for use with all PICs, but 40 bit with 32 bit mantissa is still better than single precision.

An Introduction to Analog Filters

http://www.sensorsmag.com/articles/0701/24/main.shtml

Serial to Parallel Shift Register

To expand the I/O of a microcontroller, one can use a serial-in-parallel-out shift register to convert serial signals to a parallel output. Useful to control HD44780 type parallel LCD modules using only 3 wires (one for enable one, one for the shift register data, one for the shift register clock). The shift register would control the LCD in 4 bit mode with another bit for RS). http://www.allaboutcircuits.com/vol_4/chpt_12/4.html http://www.play-hookey.com/digital/shift-in_register.html

XBee

http://www.sparkfun.com/commerce/product_info.php?products_id=8664 Another way to interface microcontrollers wirelessly.

DIY Electrocardiograph

http://www.eng.utah.edu/~jnguyen/ecg/ecg_index.html http://www.diyhappy.com/homemade-ekg/ I was thinking about hooking one up to the ADC on a PIC microcontroller and use a high capacity SD card to log heart beat throughout the day as a fun experiment. Update - more links: http://www.cisl.columbia.edu/kinget_group/student_projects/ECG%20Report/E6001%20ECG%20final%20report.htm http://forum.allaboutcircuits.com/showthread.php?t=6356 http://www.esnips.com/doc/07625f96-c19d-421b-bf0a-1c12efec2abb/ECG-circuit-guide http://www1.hut.edu.vn/vlir/STATIC/list/PhamYen7.pdf And more: http://engnet.anu.edu.au/DEpeople/Salman.Durrani/_teaching/TA1.pdf http://blog.ednchina.com/Upload/Blog/2007/8/23/ef1b052e-b8dd-466f-a7bc-b9ab542a11d8.pdf

Thursday, February 12, 2009

Cheap Microcontroller USB to Serial Interface

http://www.sparkfun.com/commerce/product_info.php?products_id=718 Basic breakout board for FTDI's popular USB to UART IC. Now with internal oscillator and EEPROM, the FT232RL is an impressive IC!

Seems like an easy way to add wireless to any project...

Transmitter - http://www.sparkfun.com/commerce/product_info.php?products_id=8946 Receiver - http://www.sparkfun.com/commerce/product_info.php?products_id=8950 Very cheap RF modules for easy wireless data communication.

Thursday, February 5, 2009

PIC18 HD44780 LCD Driver Interface Code

Update 2013-03-25:

I've updated this example code to work with the latest Microchip XC8 compiler. The code is working perfectly with a PIC18F14K50, but can be very easily modified for use with any PIC.

Download: https://github.com/veegee/pic18-lcd


Wednesday, February 4, 2009

Delays

Delays are used in code to pause for a specific amount of time, usually to allow humans to read output. But they are also important when interfacing peripherals. For example, when interfacing a microcontroller to an HD44780 LCD, enough time must be given for the LCD module to complete its operation. For this purpose, delays are used to waste time. There are numerous ways to implement delay functions. For example, one may chose to use the built in delay functions in C18, impliment their own using inline assembler for greater timing precision or use the timer module. The easiest way to use delays are to use the built in delay functions in C18. All you have to do is #include to use the delay functions. However, the delay functions are not a function of time - that is, they do not accept units of time as arguments. Instead, they delay for multiples of instructions. Therefore, to create times delays (1 second, 500 milliseconds, 45 microsecodns), it is important to calculate the number of instructions based on your clock speed. In the previous post, we configured the internal clock source to its highest setting for the PIC18F2620 - 8 MHz. PIC18 chips take 4 clock cycles for each instruction. So the frequency of executed instructions is 8 MHz / 4 = 2 MHz. The instructions execute at a frequency of 2 MHz. Taking the inverse of this value, we get the period (the time each instruction takes to execute). The value is 1/2000000 s per instruction. This is equal to 0.5 microseconds per instruction. We now know that each instruction takes 0.5 microseconds (a millionth of a second). We can now easily create our delay functions. By including delays.h, you now have access to the following built-in delay functions: Nop(); //Delay one instruction cycle Delay10TCYx(unsigned char N); // Delay in multiples of 10 instruction cycles. Delay100TCYx(unsigned char N); // Delay in multiples of 100 instruction cycles. Delay1KTCYx(unsigned char N); // Delay in multiples of 1000 instruction cycles. Delay10KTCYx(unsigned char N); // Delay in multiples of 10000 instruction cycles. The above functions delay in multiples of instruction cycles. If you want to create a function to delay 1 second (1 million microseconds), you need to delay 2 million instruction cycles (since each instruction cycle takes half a microsecond at our specified clock frequency). Here's a function that delays one second: void delay1s() { Delay10KTCYx(200); //Delay 2 million instruction cycles } As you can see, it is trivial to create your own custom delay functions using the delays.h funcions provided.

Basic Port I/O

In this post, we will examine basic IO port control for the PIC18. In C18, it is very straightforward to control I/O pins of your chip.

To set the data direction, use the TRISX register like you normally would. For example, if I want to make my PORTC all output, I would use:

TRISC = 0x00; In hexadecimal notation

or

TRISC = 0b00000000; In binary notation.

Once the tristate registers have been set, you can begin to send data through the I/O pins. You can do this directly by writing to the PORTX register or control the individual bits with PORTXbits.RXn.

For example, to make pin 6 of PORTC a logic "1", you would do:

PORTCbits.RC6 = 1;

Reading the data from the ports follows the same pattern. Remember to set the TRISX variable to the right value in order to read data.

Setting Configuration Bits and Configuring Clock Speed

Pragmas are preprocessor direrectives which are used in C18 to set configuration options for your chip. They are usually set at the top of the main source file, just under the includes.

They are declared like this:

#pragma [option] = [value]

For example, my usual options are:

#pragma config OSC = INTIO67
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = ON
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config PBADEN = OFF
#pragma config LVP = OFF

Declare them just under your #includes.

Another essential thing to do when developing with your chip is to define a clock source and set the frequency of oscillation. In the above configuration settings, the OSC has been declared to use the internal clock source. This is advantageous because no external circuitry is required.

The OSCCON register controls the clock frequency of the inter clock source. The following code will set it to the maximum frequency of the PIC18F2620 - 8 MHz.

OSCCON = 0b01110010;

The above code should be the first line in your main() function - more on this later.

Tuesday, February 3, 2009

PIC 18 Microcontroller Programming in C- Introduction

Introduction

I believe that the PIC18 series is the best family when diving into the world of microcontrollers. Myself, I have a PIC18F2620. It's a solid, all round, feature-rich chip with lots of flash and ram (64K, 3K). It's really easy to work with, very reliable, comes in a 28 pin DIP package and is compatible with the Microchip C18 compiler.

Assumptions

This tutorial assumes that you know basic electronics and how to wire up a breadboard or solder your components prototyping board. It is also assumed that the reader knows basic C programming and is able to understand and modify basic C code to his/her requirements.

Requirements

To get started, you'll need a PIC18 series microcontroller (such as the PIC18F2620). To program the chip, you'll need an ICSP programmer. I recommend the PICKIT2 as it is Microchip's own development programmer, is compatible with a wide range of chips, can do very easy UART communication between the PIC and PC and can even act as a mini logic analyzer. You'll also need a small development board (a breadboard or prototyping board, doesn't matter). And of course, you'll need a computer to use as a development machine. Your operating system doesn't matter, as long as you know your way around it well enough.

Setting Up The Circuit

To begin, wire up your circuit as follows:

(to do)

Then connect the PICKIT2 and load the "PICKIT2 Operating System" onto the chip.

Writing Your First Program

Will be in the next post...