generate and read a frequency signal

Hello

is there any way to generate a frequency signal (high-low-hight-low...) in an output pin of Arduino and then read it from another pin and calculates its frequency?

First question, yes.

Second question, depends on the frequency range (and desired resolution) we're talking about.

What are you planning to do with it?

is there any way to generate a frequency signal (high-low-hight-low...) in an output pin of Arduino and then read it from another pin and calculates its frequency?

If you are generating the signal, why do you need to read and calculate what you are generating? Surely you know what you are generating.

What are you actually trying to do?

is there any way to generate a frequency signal

Use the tone() function.

septillion:
First question, yes.

Second question, depends on the frequency range (and desired resolution) we're talking about.

What are you planning to do with it?

cattledog:
If you are generating the signal, why do you need to read and calculate what you are generating? Surely you know what you are generating.

What are you actually trying to do?

I had a problem in counting a frequency (and i found some differences between the interrupt method and calculating the frequency with if statement testing digital pin if HIGH or LOW) so I'm trying to read something i know it's result to be sure.

jremington:
Use the tone() function.

I'll test it.

Thank you.

ardv:
. . .
I had a problem in counting a frequency (and i found some differences between the interrupt method and calculating the frequency with if statement testing digital pin if HIGH or LOW) so I'm trying to read something i know it's result to be sure.
. . .

Frequency measurement is simply counting pulses or edges in unit time. If the the waveform is not clean, however, you may get some false results which can be minimised by filtering/smoothing.
You may also have to consider that if you are generating a signal and measuring it on the same device, the signal measurement may interfere with the signal generation, say if you are doing a lot of signal processing activity in an interrupt service routine.

I had a problem in counting a frequency (and i found some differences between the interrupt method and calculating the frequency with if statement testing digital pin if HIGH or LOW) so I'm trying to read something i know it's result to be sure.

Not sure I understand. Are you trying to measure the frequency on the same Arduino that is creating it? I don't see how that will tell you anything useful.

The QandD way of generating a pulse train on any pin is to set that pin as output and then loop a write HIGH to that pin's PIN.

PINx is the input register for port x. If the pin is configured as output, writing a one to the bit position n in PINx will cause the output to toggle. You can set the timing to create almost any freq you want.

If you want it to happen in the background. commandeer a time (not timer0) and set it to CTC mode (WGM = 4), set the compare output mode to 2 (which toggles OCxA and OCxB) and OCRxA or OCRxB will determine the freq. OCRxA will set the TOP and the overflow. OCRxB will need to be incremented. Your generated freq will then be available on the corresponding OCxA or OCxB pins (refer to pinout diagram).

You guys read the posts, why not spend a wee bit of time and read the datasheet?

Loopback testing is a common way of working, surely?

MarkT:
Loopback testing is a common way of working, surely?

You could wire the output to T1 (pin5) and then have timer1 count the pulses until they hit OCR1A and measure the time.