PDA

View Full Version : Frequency



MICOCALI
- 10th August 2004, 08:26
If possible read one frequency at 100hz with pbp and in wich mode

MICOCALI
- 10th August 2004, 08:27
the frequency is 1000 hz +/-

Melanie
- 10th August 2004, 12:16
Yes you an do 1kHz very easily.

As with all frequency measurements you have two choices...

1. Meausre the Length of a Pulse

Here you measure the lenth (in time) of the input signal... so for example you can use PulseIn, measure the Positive Going part of your cycle, then measure the Negative going part and add the two together. Another way would be to start a timer at the beginning of your first cycle, then stop the timer at the start of the next cycle. The timer will then tell you the length of the cycle.

2. Measure the number of Pulses in a Set Time

Using either an internal or external timer, you simply count the number of pulses received in one set time period. Here you can also use the Capture Compare feature of the CCP Module if your PIC has one (the PIC's Datasheet has all the setup details).

I posted an Olympic Timer last week in the Code Examples section... it should take all of about ten minutes to trash that code and convert it to a simple direct-reading Frequency Counter as a starting point.

Melanie

NavMicroSystems
- 10th August 2004, 12:20
For a frequency of 1000Hz */- Count would be the easiest way:

F VAR WORD

Loop:
COUNT PORTB.1,1000,F
LCDOUT "Freq. = ", DEC5 F," Hz"
goto loop

See PBP Manual Section 5.10

MICOCALI
- 10th August 2004, 13:16
WHEN THE FREQUENCY IS 1000HZ THEN SET PORT TO HIGH
VERIFY IF THE COMMAND IS GOOD

F VAR WORD

LOOP:
COUNT PORTB.1,1000,F
IF F=1000 THEN,OK
GOTO LOOP
OK:HIGH PORTB.0
PAUSE 1000
LOW PORTB.0
GOTO LOOP


IS OK ?
THE SIGNAL WICH AMPLITUDE 200 mvolt IS GOOD OR POOR SIGNAL?

Melanie
- 10th August 2004, 13:38
200mV is inadquate for direct connection to a PIC - UNLESS you have built-in Comparators. Set your VRef to trip say at 100mV, use the option to feedback the Comparator Output to the pin you will be taking the measurements with Count. Refer to your PIC's Datasheet on how to do this.

You have an error in your code... remove the comma from the line...

IF F=1000 THEN,OK

If you are using a PIC as a 1kHz detector... it's probably cheaper to use an NE567.

MICOCALI
- 10th August 2004, 13:46
I KNOW NE567 BUT I DONT HAVE SPACE FOR THIS COMPONENT
IF I AMPLITUDE THE SIGNAL WITH TRANSISTOR NPN ?

Melanie
- 10th August 2004, 14:04
Yes, you can use your NPN transistor. What PIC are you using?

MICOCALI
- 10th August 2004, 14:18
PIC 16F628
ONE QUESTION FOR THIS COMMAND I INSERT ANY DEFINE?

Melanie
- 11th August 2004, 02:40
The COUNT Command has no defines itself, but relies on the correct DEFINE OSC statement that most of the other PICBasic time critical commands rely on.