caramoan tour package

caramoan tour package

Author Topic: frequency counter using PIC's RTCC  (Read 12025 times)

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
frequency counter using PIC's RTCC
« on: July 08, 2008, 10:32:10 PM »
frequency counter using Real Time Clock Counter (RTCC) / TIMER 0

questions:
1) paano ba ang flow ng code para sa auto-range na frequency counter? ???
  may mga nakita na rin ako sa net gaya nito na gumamit ng 16F84: Frequency Meter Kit,
  kaso assembly language ang ginamit, ang hirap intindihin!  :'(
  simula ng lumipat ako sa C language, nabobo na ako sa assembly..  hehe
2)ano ang pinaka-practical na input circuit para sa frequency counter? ???
  pwede bang gumamit dito ng comparator lang?
  may "napulot" na kasi akong single comparator na 5-pin SOT-23 package..  ::)

     ang balak ko nga palang gamiting pic ay PIC16F73..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

frequency counter using PIC's RTCC
« on: July 08, 2008, 10:32:10 PM »

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10718
  • Pogi/Ganda Points: 629
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: frequency counter using PIC's RTCC
« Reply #1 on: July 08, 2008, 11:00:52 PM »
wala na akong idea sa Timer module ng PIC, pero eto ang normal na ginagawa ko to get frequency (RPM counter ko unang nagamit 'tong method na 'to)

sa AVR merong Capture mode ang Timer. kapag nagkaroon ng EDGE, isusulat niya sa capture register yung present count ng timer. kung auto range, umpisa ka muna sa pinakamahabang period. let's say 1ms ang buong Timer period. 2 EDGE ang kukunin mo (or minsan average ng succeeding EDGEs). Capture 2 - Capture 1 = period nung signal. nung sa 8051 ko 'to ginawa, gumamit ako ng External Interrupt at mano mano ang code ng capture. kung ang nakukuha mo ng sunod-sunod e halimbawa yung minimum period, papalitan mo na yung Timer settings para naman sa smaller periods. Note: kailangan din i-consider dito ang rollover dahil magiging mas malaki na yung Capture 1 sa Capture 2 kapag malapit sa Timer Overflow nangyari ang pag-capture ng EDGEs.

2. ok lang yung comparator. ;D
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #1 on: July 08, 2008, 11:00:52 PM »

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10718
  • Pogi/Ganda Points: 629
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: frequency counter using PIC's RTCC
« Reply #2 on: July 08, 2008, 11:08:05 PM »
mukhang ang method niya is counting external pulses. kung ganito ang method, kailangan mo pa rin ng isa pang reference. sa method rin na 'to kailangan mo ng fixed time in getting the number of pulses.
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #2 on: July 08, 2008, 11:08:05 PM »

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #3 on: July 08, 2008, 11:17:16 PM »
.. kung ganito ang method, kailangan mo pa rin ng isa pang reference. sa method rin na 'to kailangan mo ng fixed time in getting the number of pulses.
isa pang TIMER, aside pa dun sa TIMER0 (RTCC)? ???
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #3 on: July 08, 2008, 11:17:16 PM »

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10718
  • Pogi/Ganda Points: 629
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: frequency counter using PIC's RTCC
« Reply #4 on: July 08, 2008, 11:21:49 PM »
kung isa lang ang available timer, gagamit ka ng based sa delay ng code. like dun sa source code niya, gumamit siya ng timing na based sa execution. hindi another timer.
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #4 on: July 08, 2008, 11:21:49 PM »

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4158
  • Pogi/Ganda Points: 165
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #5 on: July 09, 2008, 07:58:47 AM »
napagaralan ko yung assembly example ng microchip.

bale ang idea is gamit yung TMR0 module ng '84 at input coming from external pulse (T0CKI pin), kagandahan ng scheme na to hindi mo kaylangan ipoll ang input, meaning pwede ka magmeasure ng frequency na many times faster than your MCU clock speed.

Ang ipopoll mo eh ang value ng TMR0 after mo magmeasure. In here defined ang period ng measurement mo, let say 1 sec for example eh magaallow ka ng pulses na pumasok, so pagnakabilang ka ng 60pulses sa duration na yun ibig sabihin may 60Hz ka. Another pin is used para magate yung pulses sa T0CKI pin, kung di ako nagkakamali autoranging dun sa app note na yun eh naguumpisa sa mataas na frequency then may level na ikinucompare, kung below a certain level, next range naman.
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #6 on: July 09, 2008, 08:06:01 AM »
thanks din, sir glutnix_neo!

.meaning pwede ka magmeasure ng frequency na many times faster than your MCU clock speed.
pwedeng mas mataas pa keysa sa maximum clock frequency nya (i.e. 20MHz)?

Quote
..Another pin is used para magate yung pulses sa T0CKI pin..
di ko ma-gets 'to..  :D

Quote
.. naguumpisa sa mataas na frequency then may level na ikinucompare, kung below a certain level, next range naman.
ito rin, di ko pa ma-imagine.. hehe  :D
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4158
  • Pogi/Ganda Points: 165
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #7 on: July 09, 2008, 08:14:30 AM »
BTW, sa app note ng microchip eh may binabanggit na prescaler, so ang resolution ng timer mo eh effectively naging 16bits,
that's "value of TMR0" + "value of prescaler"

nakuha ang value ng prescaler by injecting a pulse (yung extra pin na binanggit ko kanina ang nagprovide ng pulse), then counting the number of pulses hanggang magincrement ang TMR0 ng 1(istore mo muna ciempre value ng TMR0 bago mo gawin to,hehe).
then the "value of prescaler" is calculated to be  = 255 - # of pulses

sa extra pin, normally nakaset xa as output-low, then pag gusto mo magsample ng pulses iseset mo xa na input pa maging h-z at makapasok frequency na minemeasure mo. after that output-low na naman, then para makuha prescaler eh alternately is set mo xa as output-high:output-low.

extra pin is directly shorted sa T0CKI, you'll need a resistor to connect T0CKI and the extra pin to the source of the pulse being measured. This will prevent the pulses being measured to interfere with the process of getting the prescaler.
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4158
  • Pogi/Ganda Points: 165
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #8 on: July 09, 2008, 08:18:13 AM »
pwedeng mas mataas pa keysa sa maximum clock frequency nya (i.e. 20MHz)?
yup pwede, tanging limitation mo na lang eh yung slewrate ng hardware ng T0CKI.

isa pa nga pala, yung prescaler na isineset natin sa code(divide by N) eh laging nakaset as divide by 256 para magamit mo ng tama ang prescaler values.
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #9 on: July 09, 2008, 08:45:33 AM »
additional question..

what if im trying to measure the freq. of a sinusoidal signal, instead of square wave signal? ok na ba ang comparator gamitin to convert the sine signal first to square wave?
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline rdpzycho

  • Technical People
  • Solar Power Satellite
  • *****
  • Posts: 10718
  • Pogi/Ganda Points: 629
  • Gender: Male
  • Respect Begets Respect
    • rdpzycho
Re: frequency counter using PIC's RTCC
« Reply #10 on: July 09, 2008, 09:00:41 AM »
yup pwede na.

ang disadvantage nung counting then comparing to a fixed time in measuring frequency e kapag nabubuo at kinukulang yung count. mahirap explain pero graphically makikita. ;D hindi rin gaanong ka-responsive kapag mabilis magbago ang frequency (like sa RPM measurement) kaya mostly, period yung kinukuha. though with limited hardware mahirap din yung period ang kunin (typically requires a Timer/Counter with Capture module).
‎"Divide each difficulty into as many parts as is feasible and necessary to resolve it."
- Rene Descartes

"For every difficult problem there is always a simple answer and most of them are wrong."
- Clayton Paul

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #11 on: July 09, 2008, 09:14:09 AM »

ang disadvantage nung counting then comparing to a fixed time in measuring frequency e kapag nabubuo at kinukulang yung count. mahirap explain pero graphically makikita. ;D hindi rin gaanong ka-responsive kapag mabilis magbago ang frequency (like sa RPM measurement) kaya mostly, period yung kinukuha. though with limited hardware mahirap din yung period ang kunin (typically requires a Timer/Counter with Capture module).

yeah agree if ang timer meron capture/compare mode, madali lang talaga magmeasure ng freq..

medyo tricky if ordinary 8-bit timer/counter tulad TMR0 ng PIC..


@glutnix..

yung slewrate ng T0CKI pin, saan makikita sa datasheet ang value nito?  ???
Mukhang interesting ang makameasure ng freq higher than the PIC clock speed
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4158
  • Pogi/Ganda Points: 165
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #12 on: July 09, 2008, 09:29:28 AM »
@glutnix..

yung slewrate ng T0CKI pin, saan makikita sa datasheet ang value nito?  ???
Mukhang interesting ang makameasure ng freq higher than the PIC clock speed

Hindi po ko alam saan sa datasheet(malamang sa electrical characteristics).

pero dun sa kabilang thread
http://www.electronicslab.ph/forum/index.php?topic=1988.40

andun yung link ng appnote na binabanggit natin
http://www.jimfranklin.info/microchipdatasheets/00592d.pdf

dun din po nakalagay limitation ng T0CKI

dinadownload ko pa ulet appnote kaya di ko pa matingnan,hehehe
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: frequency counter using PIC's RTCC
« Reply #13 on: July 09, 2008, 09:39:24 AM »
RTCC input can reach up to 50MHz.  I had made one using PIC16C54, many many years ago as one of our commercial products.

Even the PIC running at 4MHz, using RTCC can still read up to 50MHz of input.
The technique, in order to be able read 50x its cycle speed is to enable the prescaler and do self-clocking.

As you notice, RTCC is connected to a prescaler and then to Timer0.  
With the two 8bit counters, you will have a 16 bit register/divider.  
Any overflows on Timer0 can just be polled because it is now very slow at approximately 1.3ms for 50MHz.

The only problem is TMR0 value is readable but the prescaler is not.  So self-clocking is applied.
This is done by using an 2 I/Os that controls the gate of the freq counter and the other one to self-clock.
The first I/O is to disable the input.  The other I/O is connected to the RTCC input.  

During capture, this I/O is set to high-impedance.  
After the gate-time elapsed, the first I/O disables the input then the 2nd I/O is set to output.
Then clock pulses are generated and counted. On each pulse, TMR0 is checked for any changes.
When TMR0 changed its value, the clocking stopped and the previous prescaler value = (256-count) is now determined.  
This idea behind self-clocking is that it the prescaler is clocked until overflow occurs thus the clock pulse count is the lacking pulses until overflow.

Sorry it difficult to explain.  :)
Any further clarification on this technique just ask.
The Cebuano Geek

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: frequency counter using PIC's RTCC
« Reply #14 on: July 09, 2008, 09:39:24 AM »
Hindi po ko alam saan sa datasheet(malamang sa electrical characteristics).

pero dun sa kabilang thread
http://www.electronicslab.ph/forum/index.php?topic=1988.40

andun yung link ng appnote na binabanggit natin
http://www.jimfranklin.info/microchipdatasheets/00592d.pdf

dun din po nakalagay limitation ng T0CKI

dinadownload ko pa ulet appnote kaya di ko pa matingnan,hehehe

oki thanx. Basa muna ako  ;)
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4158
  • Pogi/Ganda Points: 165
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #15 on: July 09, 2008, 09:42:07 AM »
10nS minimum, upto 50Mhz kaya nya sukatin
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #16 on: July 09, 2008, 10:05:36 AM »
.. So self-clocking is applied.
This is done by using an 2 I/Os that controls the gate of the freq counter and the other one to self-clock.
The first I/O is to disable the input.  The other I/O is connected to the RTCC input. 

During capture, this I/O is set to high-impedance. 
After the gate-time elapsed, the first I/O disables the input then the 2nd I/O is set to output.
Then clock pulses are generated and counted. On each pulse, TMR0 is checked for any changes.
When TMR0 changed its value, the clocking stopped and the previous prescaler value = (256-count) is now determined. 
This idea behind self-clocking is that it the prescaler is clocked until overflow occurs thus the clock pulse count is the lacking pulses until overflow.
thanks, sir zer0w1ng dito sa idea.. di sya 100% clear sa'kin, pero i'll try to make a code para dito..

opss.. edit dun sa first post ko.. di pala 16F84 ang ginamit dun sa link na nakita ko, kundi 16C54..
natataka lang ako sa schematic nya, wala syang ibang pins na ginamit para sa input aside dun sa RTCC, ???
isa pang pin na gaya ng sabi ni glutnix_neo na naka-tie sa RTCC for gating..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline glutnix_neo

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4158
  • Pogi/Ganda Points: 165
  • Gender: Female
  • A journey to a thousand lines begins w/ LED Blink
    • Underground Workbench
Re: frequency counter using PIC's RTCC
« Reply #17 on: July 09, 2008, 10:09:32 AM »
good enough master zerowing, nahirapan din ako magexplain di ko kasi alam tawag dun eh,hehehe,

self clocking pala yun.
If we hear,we forget;if we see, we remember;if we do,we understand.
Let's support the use of free and open source softwares...
http://UndergroundWorkbench.wordpress.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: frequency counter using PIC's RTCC
« Reply #18 on: July 09, 2008, 10:50:47 AM »
thanks, sir zer0w1ng dito sa idea.. di sya 100% clear sa'kin, pero i'll try to make a code para dito..
...natataka lang ako sa schematic nya, wala syang ibang pins na ginamit para sa input aside dun sa RTCC, ???
isa pang pin na gaya ng sabi ni glutnix_neo na naka-tie sa RTCC for gating..

You're welcome.  :)

On the app note, there is only one I/O used for gating and self-clocking.  A resistor is added in series to prevent contention from the input during the self-clocking.
On the one I made, I use gates because it is an autoranging freq meter with a 1GHz prescaler added to divide by 16 if over the range. Thus I use 2 independent I/Os for gating and self-clocking plus one for autorange-select.

good enough master zerowing, nahirapan din ako magexplain di ko kasi alam tawag dun eh,hehehe,

self clocking pala yun.
Yes. it is self-clocking.  I don't know also if this same technique can be applied to other processors.

I had a difficult time doing this project before,  it has an 8 digit 7segment display and I have to do the LED scanning, maintain a very-accurate 1second timebase, poll the overflows plus there is no interrupts in a PIC16C54.  I have to count each instruction and optimize the cycles.  Had to do it also in pure assembly.

Having an LCD display with this application will be easier.  Only 0.1 or 1 second accurate time-base is needed.
The Cebuano Geek

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: frequency counter using PIC's RTCC
« Reply #19 on: July 09, 2008, 01:43:51 PM »
kaya pala wala ng ibang ginamit na extra I/O pin dun Frequency Meter Kit
kasi yung instructions mismo ang ginamit na time base..
Quote
This means we must use some other method for measuring time - specifically, by manually counting the number of instructions that are executed.
mukhang mahirap gawin ito kung C language ang gagamitin..
ok na ko dun sa may extra pin(s) for gating..
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Philippine Electronics Forum

Re: frequency counter using PIC's RTCC
« Reply #19 on: July 09, 2008, 01:43:51 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com