www.micro-examples.com
Microcontroller circuits and source code examples
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 

The P16F84A simple frequency meter is ready !
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.micro-examples.com Forum Index -> Discussion About the Examples
View previous topic :: View next topic  
Author Message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Mon Dec 12, 2005 12:19 am    Post subject: The P16F84A simple frequency meter is ready ! Reply with quote

The P16F84A simple frequency meter is ready !

It will be discussed here.
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
hugo
Guest





PostPosted: Wed Mar 08, 2006 4:26 am    Post subject: overflow Reply with quote

Hi,

For a 16 MHz crystal we have:

while(ovrflw < 15626) ; //15625 = 16 000 000 / 4 * 256

what will be the right value for a 20MHz crystal:

while(ovrflw < 19532) ; //19531.25 = 20 000 000 /4*256

Thanks
Back to top
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Wed Mar 08, 2006 9:51 am    Post subject: Reply with quote

Hi Hugo,

I would better use 19531 which is closer to computed value 19531.25.

By the way, the accuracy should not differ that much between the two values !

Thanks,
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
yylee



Joined: 30 May 2006
Posts: 15
Location: Miri

PostPosted: Sun Jul 09, 2006 1:28 pm    Post subject: Reply with quote

Why the 256 have to multiply by 4? Where does the '4' come from? Thank.
_________________
Look ever forward
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Mon Jul 10, 2006 1:28 am    Post subject: Reply with quote

yylee wrote:
Why the 256 have to multiply by 4? Where does the '4' come from? Thank.


In a pic, the frequency of the oscillator is divided by 4, so with a 16 Mhz cristal, 16 000 000 / 4 = 4 000 000 instructions par second are done, and the timer is incremented 4 000 000 times per second.
the interrupt is called on each timer overflow,when the timer counter overflows from 255 to 0.
That's why the interrupt is called 16 000 000 / 4 / 256 = 15 625 times per second.
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
yylee



Joined: 30 May 2006
Posts: 15
Location: Miri

PostPosted: Mon Jul 10, 2006 6:25 am    Post subject: Reply with quote

Thanks! Any suggestion where I can find more info about the theory behind the microcontroller? Thank.
_________________
Look ever forward
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Wed Jul 19, 2006 8:21 am    Post subject: Reply with quote

Hi,

I suggest you to read the very good book of Nebojsa Matic "PIC Microcontrollers" :

http://www.mikroe.com/en/books/picbook/picbook.htm

It is on-line, and it is free !
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
Ford



Joined: 15 Nov 2006
Posts: 6

PostPosted: Wed Nov 15, 2006 3:12 am    Post subject: Nebojsa Reply with quote

Hehe, I'm sorry but i must write punchline Very Happy
Literal translation of the name "Nebojsa" is "dreadnought", meaning someone, who is not afraid (anything, anywhere, against nothing).
Back to top
View user's profile Send private message Send e-mail
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Wed Nov 15, 2006 9:48 am    Post subject: Reply with quote

Idea So "Nebojsa Matic" is the one who is not afraid of autoMatic process ?

If he can read this, maybe he will give the answer Wink
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
Clonus



Joined: 15 Jun 2007
Posts: 3

PostPosted: Fri Jun 15, 2007 3:33 am    Post subject: Reply with quote

This example is just what I've been looking for, however, I am having a helluva time getting the output to be correct.

I am using a 16f84a at 20mhz, with the minor mod listed above.

I get nothing but garbage from the serial output.

Is there a modification for this?

It would be nice to have a working piece of code.

thanks!
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Fri Jun 15, 2007 8:30 am    Post subject: Reply with quote

Hello,

I tried to build the project with the source code from the web page example, and I noticed that the soft UART init function prototype has changed since last mikroC revision, please use now :

Code:
Soft_Uart_Init(PORTB, 1, 2, 38400, 0) ;


and it will work fine.
The change has been reported to the web page, thank you for your report.

Arrow If you still get garbage on your terminal, please try a slower baud rate.

hallelujah Wink !
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
Clonus



Joined: 15 Jun 2007
Posts: 3

PostPosted: Fri Jun 15, 2007 10:23 pm    Post subject: Reply with quote

oh yes, sorry, soft_uart_init did change as well. glad you noticed.

besides this, I still get garbage at both higher and lower baud rates. If I compile even a simple "hello world" application I still get garbage.

I tried with MikroC < never works

PicBasic < works just fine.

Also, after all my troubles I noticed that PicBasic has a "Count" command to test frequency on a port. Have you ever tried comparing the results?

Just trying to save myself a hundred bucks by building something simple.

thanks
clonus
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Sat Jun 16, 2007 11:23 am    Post subject: Reply with quote

You still get garbage ?
It should workd at first try with a 1200-8-N-1 serial communication line Exclamation

I tested my PIC16F84A serial output frequency meter with a function generator and it is ok for the range I mention, but I don't know what you can expect from the picbasic count routine
you can try to wake up this thread :
http://www.micro-examples.com/forums/viewtopic.php?t=106
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
Clonus



Joined: 15 Jun 2007
Posts: 3

PostPosted: Mon Jun 18, 2007 2:34 am    Post subject: Reply with quote

1200 is too low a baud rate at 20mhz, so i tried 2400, still no luck Sad[/img]
Back to top
View user's profile Send private message
BrunoG
Site Admin


Joined: 22 Nov 2005
Posts: 636

PostPosted: Mon Jun 18, 2007 8:28 am    Post subject: Reply with quote

Can you please send me you full mikroC folder of this project by email ?
I will check on my hardware
_________________
BrunoG, Administrator
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    www.micro-examples.com Forum Index -> Discussion About the Examples All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group