Best Microcontroller Projects


XML RSS
What is this?
Add to My Yahoo!
Add to My MSN
Add to Google

Home
LCD-KEYS OnePort
Digital Downloads
C Course
State Machines
Interrupt Secrets
Schematic Tool
PIC Introduction
PIC Programming
PIC Programmers
PIC Compilers
PIC Projects
Tips & Techniques
Store
My SECRET
Oscilloscopes
Contact Me
About Me
Terms of Use
Search This Site
Freebies
Articles
Problem?-Solution
MicroBlog
Books
Resource Links
Site Map
Your Projects
Video du Jour
Rant/Rave
Privacy Policy

I use and
recommend Firefox
for the best internet
browsing experience. Click below for your
free copy today:

CLICK THE IMAGE:


Note: I find it faster
and easier to use and
it has great plugins.  

It even imports all your current
browser settings!

There's no risk as your existing browser is not affected in any way - you can just choose which one to use.


Find Out How This
Site Works
Like any engineering problem with the right tools it's Easy.
CLICK HERE 

Social Bookmarking
Click & Add:
add to BlinkBlink
add to Del.icio.usDel.icio.us
add to DiggDigg
add to FurlFurl
add to GoogleGoogle
add to SimpySimpy
add to SpurlSpurl
Bookmark at TechnoratiTechnorati
add to YahooY! MyWeb
Find out Why social bookmarking is
Useful For You.

Readers comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."


- Ranish Pottath


"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com

Learn PIC C Now
Wondering how to program your next project using C and need a great start?


"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

Learn Microcontrollers
"Interested in
Microcontrollers?"


Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon





A PIC microcontroller frequency counter using TMR1.

Project Update:

"Measuring Analogue Voltages

Without An ADC"


FREE )

Warning: This project could be Removed at
any time and will NOT be available indefinitely.
To avoid disappointment get it Now.


Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.


To get exclusive access enter your
Name and Primary email Now:


Primary Email
First Name

Don't worry -- your e-mail address is totally secure.
I promise to use it only to send you MicroZine
Note: Look through the back issues for your
No-ADC method).


P.S. The newsletter also has essential information for you as well.

More Resources...

A simple frequency counter measures frequency by counting the number of edges of an input signal over a defined period of time (T).

A more complex method is  reciprocal counting.

Frequency is defined as (Number of events) / (time in seconds) and measured in Hz.

To make calculations trivial using a 1 second gate time (T) gives a direct reading of frequency from the edge counter.

frequency counter algorithm

Making a frequency counter for frequencies up to 65.536kHz is easy as the counters in a PIC chip can count up to 65535 without overflowing.

Up to 65.535kHz all you do is wait for 1 second while the count accumulates, read the value and display it. It will be the frequency in Hertz. Above 65.536kHz you have to monitor the overflow value while at the same time making an accurate delay time (T).

Note: Using a 1 second measurement period results in the frequency counter count value being a direct measurement of frequency requiring no further processing. It also means that the measurement is resolved to 1Hz. (Increasing T to 10s resolves to 0.1Hz while using T=0.1s gives a resolution of 10Hz).

Get a frequency counter now

Here's a selection of frequency counters that you can buy on Ebay (if you don't want to make up your own then you can get a bargain here - and it will have all the front end circuitry made for you).  

Just click on the Counter you want and start bidding.



Click here to see more frequency counters on ebay.

Crystal oscillator

For the following projects the crystal oscillator (of the microcontroller) is used as the timebase. In these projects measurement of T (set at one second) is made by executing a delay that takes a set number of machine cycles.

Using a 4MHz oscillator gives a machine cycle of 1MHz (a period of 1us) which makes calculating and setting time delays fairly easy since most PIC instructions execute in one machine cycle. So executing 1,000,000 of these cycles gives a delay of 1 second.

Frequency counter accuracy

The accuracy of the frequency counter depends on the accuracy of the crystal driving the microcontroller.

ppm calculation

This is specified in ppm or parts per million. Its actually quite simple: taking an example of ±50ppm for a 4Mhz crystal. The error that the crystal could have (assuming that the crystal is loaded with the correct capacitance) will be in the range :

Maximum possible error 4MHz + (4MHz x 50 x 1e-6) = 4.0002e6
Maximum possible error 4MHz - (4MHz x 50 x 1e-6) = 39998e6

So the crystal could oscillate at any frequency between 4000200Hz and 3999800Hz. Note that this frequency can be changed by changing the loading capacitance on the crystal.

The delay time is the important measurement so for the above crystal at fosc/4) for the cycle time of the PIC chip (nominally 1MHz) we have:

Max cycle time : 1/(1.00005e6) or 1/(1MHz + 50ppm)
Min cycle time : 1/(0.99995e6) or 1/(1MHz - 50ppm)

Multiply by 1e6 to give a 1 second period gives the delay time

Min delay time : 1e6/(1.00005e6) 0.99995s or (1s - 1s x 50ppm) seconds.
Max delay time : 1e6/(9.9995e6) 1.00005s or (1s + 1s x 50ppm) seconds.

So you don't have to calculate all the intermediate steps just use the ppm value directly.

Note: If you have a reference oscillator that is more accurate than the crystal used in the frequency counter project then you can calibrate the project crystal. You can do this by adjusting a variable capacitor on one side of the crystal oscillator circuit while reading the output frequency displayed. If you don't have a reference then just use a fixed capacitor to give the correct parallel load capacitance for the crystal you use.

Common crystals

Commonly available crystals have a ppm specification of ±30ppm to ±50ppm (part per million error) but you can buy crystals with a ppm of ±20ppm. The smaller the ppm value (the smaller the error) the more accurately you can measure frequency.

Project Update:

"Measuring Analogue Voltages

Without An ADC"


FREE )

Warning: This project could be Removed at
any time and will NOT be available indefinitely.
To avoid disappointment get it Now.


Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.


To get exclusive access enter your
Name and Primary email Now:


Primary Email
First Name

Don't worry -- your e-mail address is totally secure.
I promise to use it only to send you MicroZine
Note: Look through the back issues for your
No-ADC method).


P.S. The newsletter also has essential information for you as well.

More Resources...

Watch crystal

Note: The temperature coefficient is about ±50ppm unless you use a watch crystal which has a temperature coefficient of 0.034 ±0.006ppm/ºC but if the temperature does not change much then this will not matter as much e.g. where the temperature is fairly stable.

Timer 1 algorithm

TMR1 (timer one) is ideal for frequency measurement (counting edges) as it functions as a 16 bit counter taking its input directly from a port pin. This the easiest way of measuring frequency using a PIC micro - you can use Timer 0 but more software is required to make it work as a 16 bit counter.

The maximum count for Timer one is 65535 with one more count setting the overflow flag (the timer then reads zero again). Counting the number of overflows gives the count in multiples of 65536 and reading the value of TMR1 at the end will give the total edge count over the period of measurement - T.

The trick to making the frequency counter algorithm work is that the overflow flag must be polled within the delay routine but it must be polled ensuring that the polling routine takes a constant time (So that the delay period can be calculated exactly).

In fact the delay time period mentioned earlier does take 1,000,000 cycles (xtal 4MHz) but it must also include the constant time polling routine. This makes the code slightly more complex.

For the frequency counter interrupts are not used at all in either measurement of the input signal edges or measurement of the time period T. This is because using an interrupt as part of the measurement process would interrupt the time measurement part of the code. The number of interrupts would be dependent on the input signal frequency and so the time measurement would be inaccurate. If the time period (T) measurement was made using a different method e.g. Using a 1s externally generated time period T then interrupts could safely be used.

LCD frequency counter display

The 1st project uses an LCD to display the measurement result. This is a fairly easy way to display the result as high level languages usually include drivers for the LCD. Using the LCD does not require any special techniques and it can be updated quickly.

You can find the lcd frequency counter project here.

Seven segment frequency counter display

The 2nd project uses several Seven segment displays providing an 8 digit output which is far more complex to drive but it is so much more satisfying than the LCD display.

You can find the seven segment led frequency counter project here.

To display numbers on multiple 7 segment displays you rely on persistence of vision (a way of describing how your eye perceives light).

With a single 7 segment display you can wire all its connections directly to the microcontroller and you need a total of 8 connections, with 2 segments you need 16 connections and with 8 segments you need 64 connections.

Obviously most microcontrollers don't have 64 pins so you need a different method.

The answer is to use multiplexing which is a way of recycling pins. All the seven segment displays are connected to the same 8 bit port. Then the displays are multiplexed i.e. each display is turned on for a short period of time and then off. You usually switch the seven segment display on by turning on a transistor connected to the common cathode (ground) of the display. When the transistor is on all the LEDs are enabled - the corresponding LED lights up when a bit in the 8 bit port is high.

The following example shows four multiplexed seven segment displays using only 12 pins (without multiplexing you would need 32 pins).

To make the illusion that the LEDs are on all the time the LEDs must be refreshed faster than your eye notices. You need to refresh the display at about 50Hz relying on persistence of vision i.e. the image you see does not need to be constant as long as it is repeated quickly enough. 

The trick with driving the multiplexed display for the frequency counter application is that the multiplex routine must work in a constant time. The delay period T can then incorporate refreshing the seven segment display. The constant time is needed in the same way that it is needed for polling the overflow flag of timer 1 (see earlier).


Jump to
Best Microcontroller Projects Home Page.


Don't forget to Sign Up for your

Microcontroller Newsletter

With "Essential tips and techniques",

..."New Site Info" and more...

Including a free project :

How to drive an LCD and 12key keypad using "Only One 8 Bit Port" with no interface logic!...

(Works for any microcontroller)

This costs you : Nothing...
Just fill out the form below and you'll get full C source code and project schematic and description.



Email

Name

Then

Don't worry -- your e-mail address is totally secure.
I promise to use it only to send you MicroZine.
Google
 
  Best Microcontroller projects.