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





Using Fixed point maths in microcontrollers.

Fixed point maths lets you calculate results that need to have a fractional multiplier and they let you calculate results that would normally need floating point variables.  This saves a huge amount of memory.

For example if you want to calculate an ADC result that uses a 19.6mV step size then you need to multiply the ADC result by 0.0196.  Normal maths using a floating point variable would result in the following:

ADC reading Floating point calculation Floating point result
0 0 * 0.0196 0.0
127 127 * 0.0196 2.489
255 255 * 0.0196 4.998

Fixed point lets you do this quickly and efficiently using only integer type variables.

Note: Floating point variables use up huge amounts of resources in a microcontroller as microcontrollers are only really good at integer type variables.  To do floating point complex library functions are call up.  This is similar to the old 386 processor (it too was no good at floating point operations being far too slow) so a separate floating point processor was used.

An example problem

Here is the problem to solve:

Using the minimum memory resources use an 8 bit ADC with 5V reference to transmit using a PIC micro serial data to a PC via the serial port the ADC reading every second.

The most important decision is not to use floating point - this saves lots of memory resource - all the rest; sending data to the serial port and timing will not take up much memory (the soft serial port (TX) that you can find here takes about 90 memory words).

So how to do it : First of all the step size of each ADC bit is:

5V/255 = 0.0196 (19.6mV)

Next work out the type of the variable that is big enough to hold the maximum expected value but is also the minimum size variable you can get away with. Factors such as the number of ADC bits and required calculation accuracy affect the variable size.

To convert, using fixed point, multiply the ADC reading by an integer scale factor but make sure the maximum value fits within the variable e.g If you choose a scale factor of 196 check the maximum value:

Maximum value : 255 * 196 = 49980

Here you can use a 16 bit variable (or unsigned int) as the maximum value is smaller than the maximum value that the 16 bit variable can hold.

Max value that unsigned int can store is 216-1 = 65535.

Since 49980 < 65535 the scheme is ok.

This has calculated the result using fixed point shown in the table below:

ADC reading Fixed point calculation Fixed point result
0 0 * 196 0.0
127 127 * 196 24892
255 255 * 196 49980

The decimal point is fixed four to the left - i.e. fixed point.


This has use the internal compiler routine '16 bit multiply' which is much simpler than a floating point multiply so you save loads of memory resource.


Jump from Microcontroller Fixed Point Maths 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.