Page 1 of 1

Capture frequency

Posted: Tue Sep 01, 2015 8:09 pm
by 407charles
Hi my friend how are you? I hope your are doing well. I got a problem trying to make a program to capture frequency. I'm using the atmel 328p but I'm not sure if I set the registers correctly. Can you take a look at it? You may be able to guide me in the right direction. Thanks a lot for your help. Right know I'm using a comparator to eliminate transmission noise. The program is not working it just gave me an 8 count after start up but it does not count the signal in the ICP1 pin. I appreciate all your help.

Re: Capture frequency

Posted: Tue Sep 01, 2015 10:05 pm
by kersing
I have moved your question to the English forum and created a new topic for it. Posting unrelated questions in an existing topic (hijacking a topic) is not done, please keep topics on subject in especially when writing English in the non English language forums.

Re: Capture frequency

Posted: Wed Sep 02, 2015 11:00 am
by Benj
Hello,

I noticed this.

Code: Select all

//while (TIFR1.5 == 0);
while (TIFR1 & 0x10 == 0);
bit 5 equates to hex 0x20 so I think your code should be like this.

Code: Select all

//while (TIFR1.5 == 0);
while (TIFR1 & 0x20 == 0);
Same goes for this.

Code: Select all

//TIFR1.5 = 0;
TIFR1 &= 0xEF;
Probably should be like this.

Code: Select all

//TIFR1.5 = 0;
TIFR1 &= 0xDF;

Re: Capture frequency

Posted: Wed Sep 02, 2015 5:35 pm
by 407charles
Thanks a lot for your quick response. I did the changes you suggest to the program. It does display values without input. I had the comparator switch off and I got values without any input but when I switch the comparator on (ACSR bit 7 = 0) it does not work. Looks like the code is more complex than I thought. I got no idea if all the registers needed for this task are set correctly. First, I got the comparator register ACRS bit 6 enable (logic 1) to get a reference voltage to the positive pin ( according with datasheet) but I switched to 0 and still not capturing data. I will appreciate all the help. Thanks a lot.

Re: Capture frequency

Posted: Thu Sep 03, 2015 9:25 am
by cubitus54
Hello,

I'm not sure, but there is no external counter input for the 328.

This entry exists on the Mega 2560 on the timer 5 (see p161 TCCR5B : CSn2, CSn1, CSn0 => 111 = External clock source on Tn pin. Clock on rising edge)

Re: Capture frequency

Posted: Thu Sep 03, 2015 12:55 pm
by 407charles
Hello my friend, I checked the Arduino website and I found the datasheet for atmega 328p which is the processor of the arduino 1 and nano. Datasheet Chapter 16 is about the 16 bit timer/counter 1 and it can be configured into capture mode at pin 12 which is the ICP1 pin. I believe that I just missing something. The way the program is displays a value without any input. I missing something or I got a register set up wrong. I still reading some more trying to find the mistake. Thanks a lot for your interest. I'm trying to develop this program because in the industrial environment there are two dynamic measurements for machine control: temperature and speed. By being able to capture frequency I can converted to time and then find the speed using a tachometer, encoder or a photo switch. Thanks a lot for your time and concern.