PDA

View Full Version : PULSIN for frequency meter?



PICante
- 9th November 2008, 19:01
Hi guys,

I am thinking about how to add a frequency display to my function generator project. The required range is 1 Hz to 100 kHz and if possible with a 1 Hz resolution. The source is square wave TTL level 50% duty.
And now the question; is this achievable using a 16FXXX device and the PBP PULSIN command?

Thanks!

Acetronics2
- 9th November 2008, 19:48
Hi,

BPB calculates with 16 Bits ... Ok ???

100 000 Hz @ 1 bit resolution need ???


That's it ...

Alain

GioppY
- 9th November 2008, 20:41
why do not use the timer ?
For low frequency is more accurate measure the period.
Regards

dhouston
- 10th November 2008, 00:32
If using the PIC as the frequency generator, wouldn't it be simpler to calculate the frequency rather than measure it?

PICante
- 10th November 2008, 17:10
Alain> I don’t follow your discussion, sorry.

GioppY> Could you give more detail please?

Dave> I guess I was unclear about the use of the PIC, the PIC is not involved in the generator part.

Thanks!

mister_e
- 10th November 2008, 17:20
Check you PIC datasheet, some have built-in counter. This allow you to use them to count the incoming pulses for a x sampling time.

A while back i've made this one
http://www.picbasic.co.uk/forum/showthread.php?t=1044

Maybe this could be handy for you. It use TIMER0

PICante
- 10th November 2008, 17:44
So, what you mean is that the PULSIN command is not the way to go then?

Thanks.

Acetronics2
- 10th November 2008, 17:45
And now the question; is this achievable using a 16FXXX device and the PBP PULSIN command?


a 16F device running @ 20 Mhz max... so PULSIN will give you 2µs per count.

PBP 16F compiler uses 16 bits ... so, 65535 counts at a maximum


Pulsin will give you a valid result from 1 to 65535 unit +/- 1 count.

@ 50% duty cycle your period can be ... 4 to 131070 µs +/- 4µs


a 16F device running @ 4Mhz ... so PULSIN will give you 10µs per count.

PBP 16F compiler uses 16 bits ... so, 65535 counts at a maximum


Pulsin will give you a valid result from 1 to 65535 unit +/- 1 count.

@ 50% duty cycle your period can be ... 20 to 655350 µs +/- 20µs



from that you can understand what precision and resolution you can get with the PULSIN command.

That's quite simple ...

Alain

PS: Gioppy gave you ... half of the answer !!! LOL

GioppY
- 10th November 2008, 21:48
Have a look here:
http://www.picbasic.co.uk/forum/showpost.php?p=44869&postcount=4
You can use this code to measure the frequency with timer1. This open the timer1 gate for exactly 1 sec. (@4MHz); so you can get a resolution of +- 1Hz. The result return in 2 words Hicntr and Locntr. Obviously you need a routine that convert the 32 bit to decimal.
With a bit less accuracy can be done in pbp.
http://www.picbasic.co.uk/forum/showthread.php?t=7828
Not very easy, but works fine.

Regards
Gianni

PICante
- 11th November 2008, 13:07
Thanks Guys, I think I have enough to read up on for now! I’ll let you know how it develops.

All the best!